- Java Introduction
- Java Getting Started
- Java Syntax
- Java Comments
- Java Variables
- Java Data Types
- Java Type Casting
- Java Operators
- Java Strings
- Java Math
- Java Booleans
- Java If ... Else
- Java Switch
- Java While Loop
- Java For Loop
- Java Break And Continue
- Java Arrays
- Java Methods
- Java Method Parameters
- Java Method Overloading
- Java Scope
- Java Recursion
- Java OOP
- Java Classes And Objects
- Java Class Attributes
- Java Class Methods
- Java Constructors
- Java Modifiers
- Java Encapsulation
- Java Packages
- Java Inheritance
- Java Polymorphism
- Java Inner Classes
- Java Abstraction
- Java Interface
- Java Enums
- Java User Input (Scanner)
- Java Date And Time
- Java ArrayList
- Java LinkedList
- Java HashMap
- Java HashSet
- Java Iterator
- Java Wrapper Classes
- Java Exceptions - Try...Catch
- Java Regular Expressions
- Java Threads
- Java Lambda Expressions
- Java Files
- Java Create And Write To Files
- Java Read Files
- Java Delete Files
Java Getting Started
Java Install
Some PCs might have Java already installed.
To check if you have Java installed on a Windows PC, search in the start bar for Java or type the following in Command Prompt (cmd.exe):
If Java is installed, you will see something like this (depending on version):
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)
If you do not have Java installed on your computer, you can download it for free at oracle.com.
Note: In this tutorial, we will write Java code in a text editor. However, it is possible to write Java in an Integrated Development Environment, such as IntelliJ IDEA, Netbeans or Eclipse, which are particularly useful when managing larger collections of Java files.
Practice Excercise Practice now
Setup For Windows
To install Java on Windows:
- Go to "System Properties" (Can be found on Control Panel > System and Security > System > Advanced System Settings)
- Click on the "Environment variables" button under the "Advanced" tab
- Then, select the "Path" variable in System variables and click on the "Edit" button
- Click on the "New" button and add the path where Java is installed, followed by \bin. By default, Java is installed in C:\Program Files\Java\jdk-11.0.1 (If nothing else was specified when you installed it). In that case, You will have to add a new path with: C:\Program Files\Java\jdk-11.0.1\bin
Then, click "OK", and save the settings - At last, open Command Prompt (cmd.exe) and type java -version to see if Java is running on your machine
Practice Excercise Practice now
Java Quickstart
-
Writing the Java Code:
- You begin by creating a Java file named
Main.java
. In Java, every application starts with a class definition, and the class name must match the filename. - Inside
Main.java
, you define a class namedMain
with amain
method. Themain
method is the entry point for Java applications and serves as the starting point for execution. - Within the
main
method, you use theSystem.out.println()
method to print the "Hello World" message to the console.
- You begin by creating a Java file named
-
Compiling the Java Code:
- After saving
Main.java
, you open the Command Prompt and navigate to the directory where the file is saved. - You use the
javac
command to compile the Java source code. In this case, you runjavac Main.java
. If there are no errors in the code, the compiler will generate a bytecode file namedMain.class
.
- After saving
-
Running the Java Program:
- Once the code is successfully compiled, you use the
java
command to execute the program. You typejava Main
in the Command Prompt. - The Java Virtual Machine (JVM) loads the bytecode from
Main.class
and starts executing themain
method. - As a result, the "Hello World" message is printed to the console, indicating that the program has run successfully.
- Once the code is successfully compiled, you use the
Main.java
public class Main { public static void main(String[] args) { System.out.println("Hello World"); } }
Don't worry if you don't understand the code above - we will discuss it in detail in later chapters. For now, focus on how to run the code above.
Save the code in Notepad as "Main.java". Open Command Prompt (cmd.exe), navigate to the directory where you saved your file, and type "javac Main.java":
This will compile your code. If there are no errors in the code, the command prompt will take you to the next line. Now, type "java Main" to run the file:
The output should read:
Congratulations! You have written and executed your first Java program.
Practice Excercise Practice now
Products
Partner
Copyright © RVR Innovations LLP 2024 | All rights reserved - Mytat.co is the venture of RVR Innovations LLP