Uploaded by oshinnuga

JAVA BASICS

advertisement
Java
The Basics of Java
Java is a high level computer
programming language. It is
simple, concurrent, class-based
and graphics oriented. Java is a
programming language created
by James Gosling from Sun
Microsystems (sun) in 1991. Sun
Microsystems was acquired by
Oracle Corporation in 2010.
Oracle now has the ownership of
Java.
Java is an Object Oriented
Programming . Object Oriented
Programming is a programming
environment where an
application system is considered
as a collection of objects.
Java Development Kit(JDK): It is
a programming environment for
developing java programs and
applications.
Java Runtime Environment
(JRE): It consists of all the
programs and files required to
run applications in the java
programming language
Class is a template which has
certain properties and
behaviours and objects
customise these properties and
behaviours.
Object is an instance of a class.
Symbols used in Java
{ }: Curly braces: They are used
to specify the block of code.
( ): Parenthesis: They are used
to identify a method.
[ ]: Square Brackets: They are
used to identify an array.
Program execution begins from
the main( ) method.
Public: which specifies if the
method can be used by other
members of the program.
Static: It does not create any
instance of the class.
Void: There’s no return value.
Main: This is the beginning point
of execution of the program.
String args: Argument to this
method must be an array of
Strings, and the array is called
args.
System: It is an inbuilt class.
Out: It is the object of the class,
System
Println: Tells the compiler to
print the message on the screen
in a new line.
Text in quotes: A message which
needs to be printed
Formula to calculate Simple Interest and
Amount
Mathematics
SI = P X R X T
100
Java
si = (p * r * t) / 100
amt = si + p
AMT = SI + P
Variable
A variable is a named storage location in memory that can store any
value.
To calculate simple interest in java , you require the following
values from the user; Principal, Rate of Interest and Time.
For declaring a variable, the computer memory needs to know the
name of the variable and the type of data or information the
variable will store.
Data Type
A data type specifies the type and size of data that can be stored in
a variable.
Examples of Data Types
1. Int : This data type is used to store Integer values. Examples are:
1,2, 3, 4 …. Etc.
2. Float: This data type is used to store floating point numbers, they
can take decimal values. Examples are: 13.45, 8.79 …. Etc.
3. Double: This data type is used to store Big floating numbers,
Examples are, 85342.4433.
4. Char: This data type stores single character value, Example are,
a, b, C, D
5. Boolean: This data type is used to store either true or false.
Operator
An Operator is a symbol that tells the compiler to perform the
specific logical or mathematical operations. Using operators, you
can perform operations on variables.
Arithmetic Operators perform mathematical calculations.
Relational Operators compare two or more expressions. They give
the result as either true or false.
Assignment Operator (=) assigns a value to a variable. It is used to
modify the current value of the variable.
Operator
Description
Operator
+
Addition
Subtraction
Multiplication
Division
Modulo
==
!=
<
>
<=
>=
*
/
%
Arithmetic Operators
Equal To
Not Equal To
Less Than
Greater Than
Less Than or Equal To
Greater Than or Equal to
Relational Operators
Logical Operator
The logical operator, && and ||, are used when comparing two
expressions to obtain a single relational result. The logical operator
‘!’corresponds to NOT, which is used to inverse the resultant value.
1. && = AND; yields true if both statement are true.
2. || = OR; yields true if any of the expression is true.
3. ! = NOT; returns true if the expression to the right evaluates to
false. Returns false if the expression to the right is true.
Download