0% found this document useful (0 votes)
32 views4 pages

Java Programming Basics Explained

The document explains how Java programs are executed, starting from writing code to converting it into bytecode using a compiler, which is then interpreted by the computer. It also discusses decision-making in programming through conditional statements like if...else, and introduces loops such as while, do while, and for loops for repeating tasks. Each concept is illustrated with example code snippets for clarity.

Uploaded by

skwajahatahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views4 pages

Java Programming Basics Explained

The document explains how Java programs are executed, starting from writing code to converting it into bytecode using a compiler, which is then interpreted by the computer. It also discusses decision-making in programming through conditional statements like if...else, and introduces loops such as while, do while, and for loops for repeating tasks. Each concept is illustrated with example code snippets for clarity.

Uploaded by

skwajahatahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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
}

You might also like