Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

Java Get Started

Java Install

Certain PCs may come pre-installed with Java.

To determine if Java is installed on your Windows PC, you can either search for “Java” in the start bar or enter the following command in Command Prompt (cmd.exe):

C:\Users\Your Name>java -version

Upon successful installation of Java, you’ll encounter a message similar to the following (content may vary based on the version):

java version "11.0.1"
2018-10-16 LTS

Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS,
mixed mode)

In the event that Java is not installed on your computer, you can obtain it at no cost by visiting oracle.com.

Please note: In this tutorial, we’ll be writing Java code using a text editor. Nonetheless, you can also utilize Integrated Development Environments like IntelliJ IDEA, NetBeans, or Eclipse, especially beneficial for handling larger sets of Java files.

Setup for Windows

For installing Java on Windows:

  • Access “System Properties” by navigating through Control Panel > System and Security > System > Advanced System Settings.
  • Under the “Advanced” tab, click the “Environment variables” button.
  • Next, choose the “Path” variable within the System variables section, and then click the “Edit” button.
  • Afterwards, click on the “New” button and input the directory where Java is installed, followed by \bin. Typically, Java resides in C:\Program Files\Java\jdk-11.0.1 by default (if no other location was specified during installation). In this scenario, add a new path such as C:\Program Files\Java\jdk-11.0.1\bin. Subsequently, click “OK” to confirm the changes and save the settings.
  • Finally, open Command Prompt (cmd.exe) and enter java -version to verify if Java is operational on your system.

Java Quickstart

In Java, each application initiates with a class name that must correspond to the filename.

Let’s initiate our inaugural Java file, named Main.java, which can be accomplished using any text editor, such as Notepad.

The file should feature a “Hello World” message, scripted with the following code:

Main.java

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

If the code above seems complex, don’t fret – we’ll delve into it thoroughly in subsequent chapters. For now, concentrate on mastering how to execute the provided code.

Save the provided code in Notepad as “Main.java”. Next, launch Command Prompt (cmd.exe), navigate to the directory where you saved your file, and execute the command “javac Main.java”:

C:\Users\Your Name>javac Main.java

Compiling your code with this command will prompt the Command Prompt to proceed to the next line if there are no errors detected. Afterward, input “java Main” to execute the file.

C:\Users\Your Name>java Main

Upon successful execution, the output should display:

Hello World

Congrats! You’ve successfully written and executed your inaugural Java program.