Advertisement
Google Ad Slot: content-top
Java Install
Here’s a step-by-step guide to install Java, create a Java file, compile it, and run it:
Install Java:
Download the JDK (Java Development Kit):
- Go to the Oracle JDK Download Page or use OpenJDK.
- Download the appropriate version for your operating system (Windows, macOS, or Linux).
Install the JDK:
- Follow the installation instructions for your OS.
- Make sure to note the installation path (e.g.,
C:\Program Files\Java\jdk-XX).
Set Environment Variables (Windows):
- Add the
binfolder of your JDK to the system PATH: - Go to
System Properties > Advanced > Environment Variables. - Add
C:\Program Files\Java\jdk-XX\binto thePathvariable. - Verify installation by opening Command Prompt and typing:
java -version.
Create a Java File:
- Open a text editor (Notepad, VS Code, or IntelliJ IDEA).
- Write a simple Java program
- Save the file as
Main.javain a directory of your choice.
Example
// Main.java
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Compile the Java File:
- Open a terminal or Command Prompt.
- Navigate to the directory where your
Main.javafile is located:cd path\to\Your\file - Compile the Java file using the
javaccompiler:javac Main.java - This will generate a
Main.classfile in the same directory.
Run the Java Program:
- Run the compiled Java program using the
javacommand:java Main - Output:
Hello world