How Java Works?
1.We write command in Java
2.The program is converted into bytecode using
software called compiler that is not readable by
humans anymore.
3.Then the computer reads the bytecode using
software called interpreter.
4.The computer reads the translated code and the
requested task.
The statement to print a text is
System.out.print(“enter text”)
How computer makes decisions?
1.There is a statement called conditional statement,
which helps serve this purpose.
2.The conditional statement is known as if…else
statement.
3.Based on this statement the program divides into
two branches.
1.if block- do tasks when conditions are true.
This one example of if statement-
if(condition){
System.out.print(“The condition is true”);
}
2. else block- do tasks when condition is false.
The code for else block is
else {
System.out.print ("The condition is false")
}
When you want the computer to repeat a task
we use a loop.
There are the types of loop –
1.While loop
When we don’t know when to stop our loop but
know the condition to stop at so we use while loop
in such situations.
The code for while loop is-
while(condition_to_stop){
Instructions…
}
2.Do while loop
When you want a task to repeat once.
The code for Do while loop is-
do{
instructions...
} while(condition_to_stop);
3.For loop
When you know how many times you want to
repeat a task you use For loop.
The code for 'For loop' is-
for(start_value;condition_stop;pro
ceed_code){
instructions to repeat in the
loop
}