DevAcademia
C++C#CPythonJava
  • Java Basics

  • Java Introduction
  • Java Get Started
  • Java Syntax
  • Java Output
  • Java Comments
  • Java Variables
  • Java Data Types
  • Java Type Casting
  • Java Operators
  • Java Strings
  • Java If...Else
  • Java Switch Statement
  • Java Loops
  • Java Math
  • Java Arrays
  • Java Date
  • Java OOP

  • Java Classes/Objects
  • Java Class Attributes
  • Java Class Methods
  • Java Constructors
  • Java Destructors
  • Java this Keyword
  • Java Modifiers
  • Java Non Modifiers
  • Java Encapsulation
  • Java Packages & API
  • Java Inheritance
  • Java Polymorphism
  • Java Super Keyword
  • Java Inner Classes
  • Java Exception Handling
  • Java Abstraction
  • Java Interfaces
  • Java Enums
  • Java User Input
  • Java Quiz

  • Java Fundamentals Quiz
  • Java Basics

  • Java Introduction
  • Java Get Started
  • Java Syntax
  • Java Output
  • Java Comments
  • Java Variables
  • Java Data Types
  • Java Type Casting
  • Java Operators
  • Java Strings
  • Java If...Else
  • Java Switch Statement
  • Java Loops
  • Java Math
  • Java Arrays
  • Java Date
  • Java OOP

  • Java Classes/Objects
  • Java Class Attributes
  • Java Class Methods
  • Java Constructors
  • Java Destructors
  • Java this Keyword
  • Java Modifiers
  • Java Non Modifiers
  • Java Encapsulation
  • Java Packages & API
  • Java Inheritance
  • Java Polymorphism
  • Java Super Keyword
  • Java Inner Classes
  • Java Exception Handling
  • Java Abstraction
  • Java Interfaces
  • Java Enums
  • Java User Input
  • Java Quiz

  • Java Fundamentals Quiz

Loading Java tutorial…

Loading content
Java BasicsTopic 2 of 59
←PreviousPrevNextNext→

Download and Install Java

To begin programming in Java, install the Java Development Kit (JDK): 1. Visit the official Oracle website: https://www.oracle.com/java/technologies/downloads/ 2. Download the latest JDK version for your operating system (Windows, macOS, or Linux) 3. Run the installer and follow the instructions 4. Set the JAVA_HOME environment variable to point to the JDK installation directory

Verify Installation

Open a command prompt or terminal and type: `java -version` This displays the installed Java version. Also check the compiler: `javac -version`

Example
// Check Java runtime version
java -version

// Check Java compiler version
javac -version
Output
java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)

Your First Java Program

Create and run a simple 'Hello World' program: 1. Create a file named `HelloWorld.java` 2. Add the code below 3. Compile with `javac HelloWorld.java` 4. Run with `java HelloWorld`

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

Understanding the Structure

• `public class HelloWorld`: Defines a public class; filename must match the class name • `public static void main(String[] args)`: The main method, entry point of Java programs • `System.out.println()`: Prints text to the console • Curly braces `{}`: Group code blocks • Semicolon `;`: Ends a statement

Choosing an IDE

You can write Java in any text editor, but IDEs simplify development: - IntelliJ IDEA: Popular and powerful Java IDE - Eclipse: Free, widely used open-source IDE - NetBeans: Free IDE supported by Apache - VS Code: Lightweight editor with Java extensions

Expected Output

Hello, World!
✅ Great job! You've set up your Java environment and run your first program. Next, we'll explore variables, data types, and control structures to build more advanced applications.
Java BasicsTopic 2 of 59
←PreviousPrevNextNext→