Java Program

First create file.

Let's write below code into file. Class name should be filename.


public class simpledemo {
    public static void main(String[] args) {
      System.out.println("welcome to java tutorials!");

Compile above code using below command.


Execute code using below command.

java simpledemo

It generates below output.


welcome to java tutorials!

When we compile Java program using javac tool, the Java compiler converts the source code ( into byte code ( simpledemo.class).

public keyword in Java Program

public keyword is an access modifier. we can access public properties aneywhere java program. A class contains main method should be public.

class in Java Program

class keyword is used to declare a class in Java.

main method in Java Program

main represents the entry point for executing a Java program.

static in Java Program

if method is static, then we don't need to create object to access static method. The main() method is executed by the JVM, so it doesn't require creating an object to invoke the main() method. So, it saves memory.

void in Java Program

void is the return type of the method. It means it doesn't return any value.

String[] args or String args[] in Java Program

String[] args or String args[] is used for command line argument. We can pass array string argument in main method using command promt.

System.out.println() in Java Program

System.out.println() is used to print statement. System is a class, out is an object of the PrintStream class, println() is a method of the PrintStream class.


Leave a Reply

Your email address will not be published. Required fields are marked *