Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




Java - Basic

Java
  1. Java is an object oriented programming language initially developed by Sun Microsystems.

  2. Java is a platform independent language. i.e. Java can run on any operating system with the help of Interpreter.

  3. Java is used to built Web Application, Enterprise Application, Desktop Application and even a Mobile Application.


First Java Application

Let us write our first Application which just prints 'Hello World' on the screen.


public class FirstApplication {

  public static void main(String[] args) {

    System.out.println("Hello World");
  }
}

Output :


   Hello World


1. In the above code we are printing 'Hello World' using the below statement :


System.out.println("Hello World");

We do not have to dig much into individual component in the output statement for now. We can just remember, System.out.println() is the statement used to print something on the screen

2. Since, java is said to be a complete object oriented programming language(Except primitives). All java programmes should be written inside a class. 'FirstApplication' is the name of the class inside which we have to write our code :


public class FirstApplication {

   ...
}

3. Inside the class 'FirstApplication', we have the main() method. The main() method is the entry point of a standalone java application. So, java executes the code written inside the main() method :


public static void main(String[] args) {

   System.out.println("Hello World");
}

Since, System.out.println("Hello World") is inside the main() method, it got printed.


Moral of the Story

We have to write all our codes inside the main method. And the main method should be inside a class.


public class FirstApplication {
   public static void main(String[] args) {

    //OUR CODE SHOULD BE WRITTEN HERE.
   }
}