The document provides an explanation of a simple Java program that prints "hello java" and describes the key components. It explains that the main method is the program entry point, is static so no object is needed, and returns void. It also describes how System.out.println prints to the console and that the main method can accept command line arguments. The document then outlines the steps to write and run a simple Java program from the command line.
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
23 views
Simple Program-Java
The document provides an explanation of a simple Java program that prints "hello java" and describes the key components. It explains that the main method is the program entry point, is static so no object is needed, and returns void. It also describes how System.out.println prints to the console and that the main method can accept command line arguments. The document then outlines the steps to write and run a simple Java program from the command line.
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8
Simple program-java
• Class Simple { public static void main(String args[]) { System.out.println(“hello java”); } } Explanation of program
• class keyword is used to declare a class in java.
• public keyword is an access modifier which represents visibility. It means it is visible to all. • static is a keyword. If we declare any method as static, it is known as the static method. The core advantage of the static method is that there is no need to create an object to invoke the static method. The main method is executed by the JVM, so it doesn't require to create an object to invoke the main method. So it saves memory. • void is the return type of the method. It means it doesn't return any value. • main represents the starting point of the program. • String[] args is used for command line argument. We will learn it later. • System.out.println() is used to print statement. Here, System is a class, out is the object of PrintStream class, println() is the method of PrintStream class. We will learn about the internal working of System.out.println statement later. Steps to do: Step 1:To write the simple program, you need to open notepad by start menu -> All Programs -> Accessories -> notepad and write a simple program as displayed below: write the simple program of java in notepad and saved it as Simple.java. To compile and run this program, you need to open the command prompt by start menu -> All Programs -> Accessories -> command prompt. How many ways can we write a Java program
1. By changing the sequence of the modifiers, method
prototype is not changed in Java.
static public void main(String args[])
2. The subscript notation in Java array can be used after type,
before the variable or after the variable.
public static void main(String[] args)
public static void main(String []args) public static void main(String args[]) Invalid java main method signature
× public void main(String[] args)
× static void main(String[] args) × public void static main(String[] args) × abstract public static void main(String[] args)