In this java tutorial, we will learn how to write java program. In this program, we will simply print hello world in java. As we know java is purely object oriented programming language so we have to write a java program inside class.
We will discuss about class in detail when we will start oops concept. We create class using class keyword. Public is access specifier.
public class FirstHelloapplication{
}
Before creating the class, we need to add this class into a package. A group of related classes and interfaces is called package. A package is a kind of directory that contains group of related classes and interfaces. We have both built in and user defined package. In this example, we create user-defined package. We use using keyword to add package
package firsthelloapplication;
We declare main() as a static because static method calls without creating object. JVM compiler calls main() method with it class name internally.
JVM always looks for main() method with string array type as parameter.
public static void main(String[] args) {
}
To print on screen in java we use print method, which belongs to PrintStream class. However, we directly cannot create the object of PrintStream class. Therefore, System.out give the PrintStream class object.
package firsthelloapplication;
public class FirstHelloapplication {
public static void main(String[] args) {
System.out.print("Hello world");
}
}