Introduction to Java
What is java?
Java is a object oriented programming language , platform independent
language.
It is invented by James gosling in 1995.
Why java?
WORA(write once run anywhere)
Platform Independence.
Object-Oriented.
Wide range of pre-build functionality.
Community Support.
Enterprise Use.
These are three applications to
complete the java project.
Java development kit(JDK).
Java virtual machine(JVM).
Java runtime environment(JRE).
Compiler Execution
High level Binary
language Byte code language (0 or
1)
JVM
JRE
JDK
Basic program in Java syntax
Class class_name
{
public static void main (strings[]args)
{
statement 1;
statement 2;
statement n;
}
}
Data types:
Primitive data types.
Non-Primitive data types.
Primitive data types:
Int.
Short.
Long.
Byte.
Char.
Float.
Double.
Boolean.
Non-primitive data types
Arrays.
Strings.
Collections.
Operator and Operand
Operator is a symbol which is used to perform the operator
operation(ex: +,-,*,/,%).
Operand is a data or value which is used to perform the
operators operation(ex: a+b).
Types of Operator
[Link] operator : Which is used to accept only single operand
to perform the operation. (ex: a++,b--)
[Link] operator : Which is used to accept two operands to
perform the operation. (ex: a + b)
[Link] operator : Which is used to accept three or more
operands to perform the operation. (ex: a + b + c, a : a ? b)
List of operators
• Arithmetic Operator.[+,-,/,*,%]
• Increment/Decrement Operator.[++,--]
• Relational Operator.[<,>,<=,>=,==,!=]
• Bitwise Operator.[&,|,!,XOR,>>,<<]
• Logical Operator.[&&,||,!]
• Conditional Operator.[?,:]
• Assignment Operator.[==,+=,-=,*=,/=,%=]
Control Flow Statement:
It executes the block of statements.
We have two types of Control Flow Statements.
[Link] making statements.
[Link] statements.
Decision Making Statements:
[Link]
[Link]-else
[Link]-else ladder
[Link] if
[Link] case
if if-else
Syn: if(condition) Syn: if(condition)
{ {
statements; statements;
} }
else
{
statements;
}
If else ladder
Syn: if(condition)
{
statements;
}
else if(condition)
{
statements;
}
else if(condition)
{
statements;
}
else
{
statements;
}
Nested if
If (condition)
{
if (condition)
{
if (condition)
{
statements;
}
else
{
statements;
}
else
{
statements;
}
else
{
statements;
Switch case
Syn: switch (variable_name)
{
case value 1:
statement;
case value 2:
statement;
case value 3:
statement;
case value n:
statement;
default :
statement;
}