Back to Curriculum

Java Introduction

📚 Lesson 1 of 16 ⏱️ 25 min

Java Introduction

25 min

Java is a high-level, class-based, object-oriented programming language designed to have as few implementation dependencies as possible. Created by James Gosling at Sun Microsystems (now Oracle) in 1995, Java has become one of the most widely used programming languages. It's used for enterprise applications, Android development, web applications, and large-scale systems. Java's design emphasizes portability, security, and simplicity.

Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of the underlying computer architecture. This 'compile once, run anywhere' approach means you write code once and it runs on Windows, Linux, macOS, and other platforms. The JVM interprets bytecode and can optimize it at runtime through Just-In-Time (JIT) compilation, providing performance comparable to native code.

The main method is the entry point of any Java application: `public static void main(String[] args)`. The `public` modifier makes it accessible, `static` means it belongs to the class (not an instance), `void` means it returns nothing, and `String[] args` receives command-line arguments. Understanding the main method signature is fundamental to Java programming.

Java's 'Write Once, Run Anywhere' philosophy makes it ideal for cross-platform development. This portability, combined with Java's robust standard library, makes it popular for enterprise applications. Java's strong typing, automatic memory management (garbage collection), and exception handling make it suitable for large-scale, mission-critical applications. Understanding Java's strengths helps you choose it for appropriate projects.

Modern Java (Java 8+) includes features like lambda expressions, streams, and modules that make it more expressive and powerful. Java's ecosystem includes extensive libraries and frameworks (Spring, Hibernate, etc.) that simplify enterprise development. The language continues to evolve with regular releases adding new features while maintaining backward compatibility. Understanding Java's evolution helps you use modern features effectively.

Java's object-oriented nature means everything is organized into classes and objects. Classes define blueprints for objects, encapsulating data (fields) and behavior (methods). Java supports inheritance, polymorphism, and encapsulation—core OOP principles. Understanding these concepts is essential for writing effective Java code. Java also supports interfaces, abstract classes, and other advanced OOP features.

Key Concepts

  • Java is an object-oriented, platform-independent programming language.
  • Java code compiles to bytecode that runs on the JVM.
  • The main method is the entry point of Java applications.
  • Java's 'Write Once, Run Anywhere' enables cross-platform development.
  • Java has automatic memory management through garbage collection.

Learning Objectives

Master

  • Setting up Java development environment (JDK, IDE)
  • Writing and compiling basic Java programs
  • Understanding the main method and program structure
  • Running Java applications

Develop

  • Understanding Java's design philosophy
  • Appreciating Java's platform independence
  • Setting up efficient development workflows

Tips

  • Install JDK (Java Development Kit), not just JRE (Java Runtime Environment).
  • Use an IDE like IntelliJ IDEA or Eclipse for better development experience.
  • Follow Java naming conventions: classes start with uppercase, methods with lowercase.
  • Compile with javac and run with java command.

Common Pitfalls

  • Confusing JDK with JRE—you need JDK to compile code.
  • Not setting JAVA_HOME environment variable correctly.
  • Using wrong Java version for your project.
  • Not understanding the difference between .java (source) and .class (bytecode) files.

Summary

  • Java is a platform-independent, object-oriented language.
  • Java compiles to bytecode that runs on the JVM.
  • The main method is the entry point of Java applications.
  • Java's portability and robustness make it ideal for enterprise development.

Exercise

Create a simple Java program that prints 'Hello, World!' to the console.

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

Exercise Tips

  • Compile with: javac HelloWorld.java (creates HelloWorld.class).
  • Run with: java HelloWorld (no .class extension).
  • Add command-line arguments: java HelloWorld arg1 arg2 (accessed via args array).
  • Use System.out.printf() for formatted output: System.out.printf("Hello, %s!", name);

Code Editor

Output