Introduction to Java

Introduction to Java

Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1995. It is widely used for building robust, secure, and portable applications.

Key Features of Java

  1. Simple:

    • Java is designed to be easy to learn and use, especially if you already know some basic programming concepts.
  2. Object-Oriented:

    • Everything in Java is an object, which helps organize code into reusable sections.
  3. Platform-Independent:

    • Java code is compiled into bytecode, which can run on any device with a Java Virtual Machine (JVM), making it platform-independent (Write Once, Run Anywhere).
  4. Secure:

    • Java provides a secure environment by restricting access to critical system resources and ensuring safe execution of code through the JVM.
  5. Robust:

    • Java is designed to handle errors effectively, with strong memory management and automatic garbage collection.
  6. Multithreaded:

    • Java supports multithreading, allowing multiple tasks to run simultaneously, making it efficient for performing concurrent operations.

Java Development Kit (JDK)

To write and run Java programs, you need the Java Development Kit (JDK), which includes:

  • Compiler (javac): Converts your Java source code into bytecode.

  • Java Runtime Environment (JRE): Provides the libraries, JVM, and other components to run Java applications.

  • Java Virtual Machine (JVM): Executes the compiled bytecode.

Basic Structure of a Java Program

Here is a simple Java program to print "Hello, World!" to the console:

  • Class Definition: java public class HelloWorld {

    • public class HelloWorld: Declares a public class named HelloWorld.
  • Main Method: java public static void main(String[] args) {

    • public static void main(String[] args): The entry point of any Java program. It's the method that is executed when you run the program.
  • Print Statement: java System.out.println("Hello, World!");

    • System.out.println: A method to print text to the console. System is a class, out is a static member of the System class, and println is a method of the out object.

Summary

  • Java is a popular, high-level, object-oriented programming language.

  • It offers platform independence, making your programs portable across different systems.

  • JDK is essential for developing Java applications, and it includes tools like the compiler and JVM.

  • A typical Java program consists of class definitions and a main method, serving as the entry point.

  • Java emphasizes simplicity, security, and robustness, making it suitable for a wide range of applications.