Video Lecture- https://youtu.be/StCjnwfS0NQ
Basic structure of a Java program
public class xyz
{
public static void main(String args[])
{
//Code
//Code
//Code
//Code
//Code
}}
public- access specifier/modifiers which makes the particular entity accessible throughout the program i.e., it can be accessed by other classes also.
static- a keyword by which we don't have to create an object of that particular entity.
void- return type keyword by which the function becomes non-returning type.
main- name of the function
String args[]- argument for main function
Print Statement
Syntax: System.out.println();
Three types of Iteration statements are:
for loop
Example:
for(int i=0; i<=5;i++)
{
//Code
//Code
//Code
//Code
//Code
}
The body of the above for loop will be executed 6 times.
while loop( entry control loop)
Syntax:
while (condition)
{
//Code
//Code
//Code
//Code
//Code
}
The body of the above while loop will be executed continuously as long as the condition of the while is true.In this loop the condition is checked before the execution of the loop's body.
do-while loop (exit- control loop)
Syntax:
do
{
//Code
//Code
//Code
//Code
//Code
}
while(condition);
The body of the above do-while loop will execute at least once, even if the condition of the loop is false because the condition is checked after the body's execution. After the first execution, similar to that of while loop the body of do-while will be continuously executed as long as the condition is true.
All the loops given below have three statements. Initial statement, conditional statement and an update statement.