Page 241 - PowerPoint Presentation
P. 241
CAVITE STATE UNIVERSITY
TRECE MARTIRES CITY CAMPUS
Department of Information Technology DCIT 111 - Advanced Programming
Parameters used in First Java Program
Let’s see what is the meaning of class, public, static, void, main, String[],
System.out.print, ln.
- 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.
- 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.
- System.out.print is used to print statement
- ln is used for new line.
To write the simple program, you need to open notepad by start menu -> search for
Notepad and write a simple program as displayed below.
class HelloWorld {
public static void main(String[] args) {
System.out.println( “Hello World!”);
}
}
As displayed in the above diagram, write the simple program of java in notepad and saved it
as HelloWorld.java. To compile and run this program, you need to open the command
prompt by start menu -> search for Command Prompt or simply cmd.
To compile and run the program, go to your current directory first, my current directory is
C:\Users\Chan\Desktop\JAVA. Write here:
To Compile: javac HelloWorld.java
To Execute: java HelloWorld
Internal Details of Hello World Program
Here, we are going to learn what happens while compiling and running the java
program. Moreover, we will see some question based on the first program.
1. What happens at compile time?
At compile time, java file is compiled by Java Compiler and converts the java code
into byte code.
17