Introduction to Java (Hindi) | What is Java? Explain with Syntax and Example

Education


Introduction to Java (Hindi) | What is Java? Explain with Syntax and Example

Hi friends,

In today's article, we will cover the following:

  1. Introduction to Java: What is Java?
  2. Writing Java statements.
  3. Creating a simple Java program and explaining it.
  4. Historical context of Java development and its first version.

What is Java?

Java is a class-based, high-level, object-oriented programming language developed by James Gosling and his friends at Sun Microsystems in 1991. Java allows us to write a program once and run it anywhere and anytime. This capability makes Java a platform-independent language.

History of Java

The first version of Java, JDK 1.0, was released by Sun Microsystems on January 23, 1996.

Writing Java Syntax

Java requires you to create a class even for the simplest program. Here is how you can write a basic Java program:

class Amit (
    [public static void main](https://www.topview.ai/blog/detail/why-public-static-void-main-string-args-in-java-full-explanation-learn-coding)(String[] args) {
        System.out.println("Welcome to Java");
    )
}
  • class Amit: We begin with creating a class named Amit.
  • public static void main(String[] args): This is the main method. public makes it accessible from anywhere. static allows it to run without creating an object of the class. void signifies that it does not return any value. The main method is the entry point of any Java program.
  • System.out.println("Welcome to Java");: This statement prints the message Welcome to Java on the screen. System is a predefined class, and out is the output stream. The println method prints the message.

Executing a Java Program

  1. Save the file with the class name, for example, Amit.java.
  2. Compile the program using the command:
    javac Amit.java
    
  3. Run the compiled Java program using:
    java Amit
    

Compilation and Execution Example

To demonstrate, let’s use the Sublime Text Editor to create and run our first Java program.

  1. Creating the Class and Main Method

    class Amit (
        public static void main(String[] args) {
            System.out.println("Welcome to Java");
        )
    }
    
  2. Saving the File

    Save it with the name Amit.java.

  3. Compiling the Program

    Open the command prompt and navigate to the location where the file is saved:

    cd desktop
    javac Amit.java
    
  4. Running the Program

    java Amit
    

    The output will display Welcome to Java.

Conclusion

Java is a versatile and powerful programming language with a rich history and significant utility. Mastering its basics, including syntax and class creation, is essential for any aspiring developer.

If you enjoyed this article, please like, share, and subscribe to our channel for more content like this.


Keywords

  • Java
  • High-level Programming Language
  • Object-oriented
  • Platform-independent
  • JDK 1.0
  • Compilation
  • Execution
  • Syntax
  • Class

FAQ

Q1: Who developed Java and when was its first version released?
A1: Java was developed by James Gosling and his colleagues at Sun Microsystems. The first version, JDK 1.0, was released on January 23, 1996.

Q2: What is the importance of the main method in Java?
A2: The main method is the entry point of any Java application. It is where the program execution begins.

Q3: Why is Java considered platform-independent?
A3: Java is considered platform-independent because its compiled code (bytecode) can run on any platform that has a Java Virtual Machine (JVM).

Q4: How do you compile and run a simple Java program?
A4: First, save your program with a .java extension. To compile, use javac YourClassName.java, and to run, use java YourClassName.

Q5: What is the significance of the System.out.println statement?
A5: The System.out.println statement is used to print messages to the console. It is a predefined method in the System class for outputting text.