
Learn to Program in Java 25: Your First Hello World
Introduction to Java 25
Java is one of the most popular programming languages in the world, widely used for developing applications across various platforms. With the arrival of Java 25, new features and improvements have been introduced, but the essence of the language remains the same. In this article, we will explore how to create a simple 'Hello World' program in Java 25, ideal for beginners who want to take their first steps in programming.
What is a 'Hello World' Program?
A 'Hello World' program is traditionally the first program developers write when learning a new programming language. It serves to illustrate the basic syntax of the language and how the execution of a program works. In the case of Java, the 'Hello World' displays the phrase "Hello, World!" on the screen.
Setting Up the Development Environment
Before we start programming, we need to set up our development environment. Here are the necessary steps:
1. Install the JDK (Java Development Kit)
The JDK is a set of tools needed to develop Java applications. You can download it from the official Oracle website. After downloading, follow the installation instructions for your operating system.
2. Configure the Environment Variable
After installing the JDK, it is important to configure the JAVA_HOME environment variable. This ensures that the system can locate the JDK. On Windows, you can do this as follows:
1. Right-click on 'This PC' and select 'Properties'.
2. Go to 'Advanced system settings'.
3. In the 'Advanced' tab, click on 'Environment Variables'.
4. In 'System variables', click 'New' and add:
- Variable name: JAVA_HOME
- Variable value: C:\path\to\your\jdk
3. Choose a Code Editor
You can use any text editor to write your Java code, but an integrated development environment (IDE) like Eclipse or Visual Studio Code can greatly simplify the process. These editors provide features such as syntax highlighting, autocompletion, and debugging.
Writing the 'Hello World' Program
Now that we have our environment set up, let’s write our first program in Java 25.
1. Creating the Java File
Open your code editor and create a new file named HelloWorld.java. The .java extension is crucial as it indicates that this is a Java source code file.
2. Basic Code Structure
The basic structure of a Java program consists of a class and a main method. Here’s an example of how your code should look:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
3. Explaining the Syntax
Let's break down each part of the code:
public class HelloWorld: Declares a public class namedHelloWorld. In Java, all code must be within a class.public static void main(String[] args): This is the main method, the entry point of the program. Java starts executing the program from this method.System.out.println("Hello, World!"): This line prints the message "Hello, World!" to the console.System.outis an object that represents the standard output, andprintlnis a method that displays the message followed by a new line.
Compiling and Running the Program
Now that we have our code ready, let's compile and run the program.
1. Compiling the Code
Open the terminal or command prompt and navigate to the directory where you saved the HelloWorld.java file. To compile the code, type:
javac HelloWorld.java
If there are no errors, this will create a file named HelloWorld.class, which contains the Java bytecode.
2. Running the Program
To run the program, use the following command in the terminal:
java HelloWorld
You should see the output:
Hello, World!
Basic Concepts of Java
In addition to learning how to create a simple program, it’s important to understand some fundamental concepts of the Java language.
1. Classes and Objects
Java is an object-oriented language, which means it is based on the concept of classes and objects. A class is a definition of an object, while an object is an instance of a class. For example, if we have a class Car, an object of that class could be a specific car, like Car ferrari = new Car();.
2. Data Types
Java has several data types, which can be classified into primitive and non-primitive types. Primitive types include int, float, double, char, among others. Non-primitive types include classes, arrays, and interfaces.
3. Control Flow
Java provides control flow structures like if, for, while, and switch, which allow controlling the execution flow of the program. For example:
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
Next Steps
After completing your first program in Java, you may wonder: "What now?" Here are some suggestions on how to continue your programming journey:
- Learn about Data Structures: Knowing about lists, queues, stacks, and maps is essential for efficient programming.
- Explore Object-Oriented Programming: Understand concepts like inheritance, polymorphism, and encapsulation.
- Practice with Projects: Try developing small projects, like a calculator or a simple game.
- Join Communities: Join forums and online groups to share knowledge and get help.
Conclusion
Learning Java may seem challenging at first, but with practice and patience, you will become a competent programmer. The 'Hello World' program is just the beginning of an exciting journey in the world of programming. Keep exploring, practicing, and above all, have fun!
FAQ
What is Java 25?Java 25 is a newer version of the Java programming language, which includes new features and improvements over previous versions.
Can I use any text editor to program in Java?Yes, you can use any text editor, but an IDE can greatly simplify development with additional features.
Where can I find more resources to learn Java?There are many online resources, including free courses, tutorials, and books. Websites like Codecademy and Udemy offer great courses.

Eridani Melo
Full Stack Developer