Requirements for java Program
- Install the JDK any version if you don’t have installed it.
- Set path of the jdk/bin directory.
- Create the java program.
- Compile and run the java program.
Refer this link to Download & Install JAVA: Java | Download Install and Setup.
Simple Java Program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // Package Declaration package package_Java; // Class Declaration public class First_Java_Program { // Main Method execute First public static void main(String[] args) { System.out.println("Hello Selenium"); }// End of main }// End of First_Java_Program Class |
Output:
1 | Hello Selenium |
Understanding first java program
Meaning of package, class, public, static, void, main, String[], System.out.println():
- package Using package statement defines a namespace in which number of classes are stored. The package is used to organize the classes based on functionality and workflow. It must be the primary line of your program is package name.
- class keyword is used to declare a class with class name in java.
- Comments (//) Single line starts with two forward slashes (//) and continues to the end of the current line. Line comments do not require an ending symbol.
- public keyword is an access modifier which represents visibility, it means it is visible to all. Depends on Datatype, Method, Class Visibility.
- static keyword, if we declare any method as static, it is known as static method. The core advantage of static method is that there is no need to create object to invoke the static method. The main method is executed by the JVM, so it doesn’t require to create object to invoke the main method. So it saves memory. Using static keyword directly use functionality without object creation.
- void is the return type of the method, it means it doesn’t return any value. Does not return any Data type.
- main represents startup of the program. Main Execution method of Program.
- String[] args is used for command line argument. Give command to Console.
- System.out.println() is used print statement with / without message.