Professional Documents
Culture Documents
platform.
5)Multithreading
A thread is like a separate program,
executing concurrently. We can write Java
programs that deal with many tasks at once
by defining multiple threads. The main
advantage of multi-threading is that it
doesn't occupy memory for each thread. It
shares a common memory area.
6) Distributed
RMI and EJB are used for creating distributed
applications. In distributed application
multiple client system depends on multiple
server systems so that even problem occurred
in one server will never be reflected on any
client system.
7) Networked
It is mainly designed for web based
applications, J2EE is used for developing
network based applications.
8) Robust
◦ It is robust or strong Programming Language
because of its capability to handle Run-time Error,
automatic garbage collection, the lack of pointer
concept, Exception Handling.
◦ Java uses strong memory management.
9) Dynamic
The process of allocating the memory space
to the input of the program at a run-time is
known as dynamic memory allocation, To
programming to allocate memory space by
dynamically we use an operator called 'new'
'new' operator is known as dynamic memory
allocation operator.
10) Secure
In this language, all code is covered in byte
code after compilation which is not readable
by human.
11) High Performance
Use Bytecode which is faster than ordinary
pointer code.
Garbage collector, collect the unused memory
Class
Inheritance
Polymorphism
Abstraction
Encapsulation
Phases Of Java Program
How to Java Source Code execute
Source Code(.java file) Native Code(.exe file)
value.
main represents startup of the program.
String args[] is used for command line argument. We will learn it
later.
System.out.println() is used print statement. We will learn about the
Operators in Java
Operator is a special symbol that tells the compiler to perform specific mathematical or
logical Operation. Java supports following lists of operators.
Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
Ternary or Conditional Operators
Control Statement
1) Selection Control Statement
a) If-else
b) Switch
2) Iteration Control Statement
a) while Loop
b) do-while Loop
c) For-Loop
If else(Selection Control)
The Java if statement is used to test the
condition. It checks boolean
condition: true or false. There are various
types of if statement in java.
Syantax
if(condition){
//code if condition is true
}else{
//code if condition is false
}
Java IF-else-if ladder Statement
The if-else-if ladder statement executes one condition from multiple statements.
Syntax:
if(condition1){
//code to be executed if condition1 is true
}else if(condition2){
//code to be executed if condition2 is true
}
else if(condition3){
//code to be executed if condition3 is true
}
...
else{
//code to be executed if all the conditions are false
}
Nested If-else
It is always legal to nest if-else statements
which means you can use one if or else if
statement inside another if or else if
statement.
Syntax:-
The syntax for a nested if...else is as follows −
if(Boolean_expression 1) { // Executes when
the Boolean expression 1 is true
if(Boolean_expression 2) { // Executes when
the Boolean expression 2 is true } }
Switch Statement
Multiple decision making statement is called
switch statement.
The value of expression determines which
case is selected.
expression must evaluate to byte, short, char,
with break;
Switch Statement
Syntax:-
switch ( expression )
{
case label1: statementList1
break;
case label2: statementList2
break;
case label3: statementList3
break; . . .
default: defaultStatementList
}
While Loop(Iteration Control)
In while loop first check the condition if
condition is true then control goes inside the
loop body otherwise goes outside of the
body. while loop will be repeats in clock wise
direction.
Syntax:-
while(condition){
//code to be executed
}
do-while loop
The Java do-while loop is used to iterate a part of
the program several times. If the number of
iteration is not fixed and you must have to
execute the loop at least once, it is recommended
to use do-while loop.
The Java do-while loop is executed at least once
variable.
Syntax:
for(Type var:array){
//code to be executed
}
Example:
public class ForEachExample {
public static void main(String[] args) {
int arr[]={12,23,44,56,78};
for(int i:arr){
System.out.println(i);
}
}
}
Java Labeled For Loop
We can have name of each for loop. To do so, we use label before the for loop. It is useful if we have nested
for loop so that we can break/continue specific for loop.
Normally, break and continue keywords breaks/continues the inner most for loop only.
Syntax:
labelname:
for(initialization;condition;incr/decr){
//code to be executed
}
Example:
public class LabeledForExample {
public static void main(String[] args) {
aa:
for(int i=1;i<=3;i++){
bb:
for(int j=1;j<=3;j++){
if(i==2&&j==2){
break aa;
}
System.out.println(i+" "+j);
}
}
}
}
Array in java
Array is a collection of similar type of data. It is
fixed in size means that you can't increase the
size of array at run time. It is a collection of
homogeneous data elements. It stores the value
on the basis of the index value.
Types of Array
There are two types of array in Java.
Single Dimensional Array
Multidimensional Array
Syntax:-
Datatype variablename =new datatype[size];