Structure of Java
Structure of Java
Filename: Class_Name.java
Note: Every class in java must have a name it is known as class
name.
Every class has a block, it is known as classblock.
Members of class
• In class block we can create
Variables
Methods
Initializers variable
• These are called as members of class.
1. Variables: Variable is the container which is used to store
data.
2. Methods: It is a block of instructions which is used to
perform task.
3. Initializers: Used to execute the start up instructions.
• Note: A class in java can be executed only if main method is
created as follows:
Syntax to create main method
public static void main(String[] args)
{
//Statements;
}
• Note: We can create a class without main method. It is compile
time successful and class file is generated but we can’t execute
that class file.
Difference between print and println
Statements
• System.out.println(data)
Println statement is used to print data as well as
create a new line.
We can use the println statement without passing
any data, it is just used for printing new line.
Example:
System.out.println(“hi”);// hi _
System.out.println(“hello”);//hello_
System.out.println();//_
Contd…..
• System.out.print()
Print statement is used only to print the data.
We can’t use the statement without passing any data,
if we use then will get a compile time errors.
Example:
• System.out.print(“hi”);
• System.out.print(“hello”);
• System.out.print();// CTE
Example:
class Program
{
public static void main(String[] args)
{
System.out.println(“hello world”);
}
}
Output
hello world