java

Java Introduction


What is Java?

Java is a class based, high-level object oriented programming language developed by James Gosling and his friends in the year 1995. The first version of java(JDK 1.0) was released on the year 1996, January 23rd by Sun Microsystem (Now a subsidiary of Oracle Corporation).

 

Syntax

 

class class_name {
    public static void main(String[] args) {
       // code;
    }
}

 

 

Why main() method is public static void in java?

 

  • public is an access modifier. It means that the main method can be called by JVM from outside the class.
  • static is a keyword indicating that the method belongs to the class itself, not to instances of the class.
  • void is the return type of the main method. It means that the main method does not return any value.
  • main() is a method, you will it in every java program because it is starting and ending point of java program. Without the main method the program will not be execute.
     

Note:- You can change the return type of method according to your requirements.

 

What are these String args[] in the main method?

 

  • String args[] is an array of strings that represent the command-line arguments passed to the program. 
  • The args parameter is optional.
  • You can use any name in place of args.
  • String itself is a class in Java which is available on java. lang package.

 

Java First Program

 

class class_name {
    public static void main(String[] args) {
    System.out.print("Hello World");
    }
}

 

Java System.out.println()

 

  • System-

    1. It is a predefined or final class which is available in java.lang package. 
    2. It provides access to system.
     
  • out-

    1. It is a public and static member of the System class representing the standard output stream.
    2. Available in java.lang.System package.
     
  • println()-

    1. println() means "print line". It is a method which prints the text on your screen.
    2. To access it, System.out keyword is used.
    3. Available in java.io.PrintStream package.

    Note:- Where does System.out.println() happen in Java?

    👉 It is placed under the curly brackets of the block. 
    👉 The sentence written under it becomes visible to you on your console, when you run the program.