Tools we need
- JDK 8 (could be a newer version as well)
- The Java Development Kit is the development environment we use for writing applications using the Java Programming language
- An IDE (Integrated Development Environment),
- This tool help developers to go faster in the development of applications, even though is not mandatory it’ll help you to go faster and easier in the dev process
- Popular IDEs options for Java are Netbeans and Eclipse
Hello World Java
After installing the JDK and the chosen IDE, you must run the IDE and create a new project on it.
Netbeans
- Open Netbeans
- Go to File -> New Project
- Choose the Java Application project type from the Java category, and press the next button
- Assign the project’s name, location. Be sure to uncheck the “Create Main Class” option.
- Press the Finish button
Eclipse
- Open Eclipse
- Go to File-> New -> Java Project
- Assign the project’s name and leave other fields with their default values
- Press the Finish button
Java is an Object-Oriented programming language, so the concepts of Objects and Classes are crucial to learn how to write programs using this platform. To start writing our code let’s add a new class to our project
Netbeans
- Right-click over the project’s name
- Go to New->Java Class
- Set the class’ name to: HelloWorld and its package to: hello
- Let default values for every other field and click on finsh
The class will now appear under the Source Packages folder and the hello package
Eclipse
- Right-click over the project’s name
- Go to New-> Class
- Set the class’ name to: HelloWorld and its package to: hello
- Let default values for every other field and click on finish
The class will now appear under the src folder and the hello package
Finally, let’s add the following code to the created class
package hello;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
After saving the file, let’s run it now
Netbeans
To run a project in Netbeans, right-click over the main class file and choose the “Run File” option
Eclipse
To run a project in Eclipse, right-click over the main class file and choose the Run As-> Java Application option
The output you get after running, should look like this:
Netbeans
Eclipse
Classes Eclipse Hello World Java Netbeans Object Oriented Programming Objects