Requirement for Java Hello World Program:
- Install the JDK if you don’t have installed it, download the JDK and install it.
- Set path of the jdk/bin directory.Setting CLASSPATH in Java
- Create the Java program
- Compile and run the Java program
Hello World Example:
class Hello{
public static void main(String args[]){
System.out.println("Hello World! Coderzpy");
}
}
Save the above file as Hello.java.
In the terminal:
To compile: | javac Hello.java |
To execute: | java Hello |
Output:
Hello World! Coderzpy
Parameters used:
Let’s look at what class, public, static, void, main, String[], and System.out.println mean ().
- In Java, the class keyword is used to declare a class.
- The visibility is represented by the public keyword, which is an access modifier. It means that it is visible to everyone.
- static is a keyword. Any method that is declared as static is referred to as a static method. The main advantage of the static method is that it does not require the creation of an object to use. Because the main() method is executed by the JVM, there is no need to create an object to call it. As a result, it conserves memory.
- The method’s return type is void. It indicates that it does not return any information.
- The program’s starting point is represented by main.
- The command line argument is String[] args or String args[]. We’ll go over it in the next section.
- To print a statement, use System.out.println(). System is a class, out is a PrintStream class object, and println() is a PrintStream class method. In the following section, we’ll look at how the System.out.println() statement works internally.
Compilation Flow:
The Java compiler converts source code into byte code when we compile a Java program with the javac tool.
Note: We can also use other editors like the eclipse(https://www.eclipse.org/downloads/), also read about the JDK vs JRE vs JVM
Follow Me
If you like my post please follow me to read my latest post on programming and technology.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Leave a Comment