1. Home
  2. Training Library
  3. Programming
  4. Programming Courses
  5. Introduction to Java and Environment Setup

First Java Program

Start course
Overview
Difficulty
Beginner
Duration
56m
Students
61
Ratings
5/5
starstarstarstarstar
Description

In this course, we learn about Java technology and get you started with writing and running a Java program. 

Learning Objectives

  • What is the Java programming language?
  • Java Development Kit (JDK)
  • Java Runtime Environment (JRE)
  • Java Virtual Machine (JVM)
  • Integrated Development Environment (IDE)
  • Installation of Eclipse
  • Write a Java program
  • compile and run a Java program

Intended Audience

  • Anyone looking to get Oracle Java Certification
  • Those who want to learn the Java Programming language from scratch
  • Java developers who want to increase their knowledge
  • Beginners with no previous coding experience in Java programming
  • Those who want to learn tips and tricks in Oracle Certified Associate – Java SE 8 Programmer certification exams

Prerequisites

  • No prior knowledge is required about the Java programming language
  • Basic computer knowledge
Transcript

Hi there. In the previous video, we installed the Eclipse. So, we are ready to write our first Java program. Let's move on to the Eclipse. Hello World will be our first program. It's the tradition in the programming world to create a small program which writes the 'Hello World' phrase to the console. First, we will create a Java project in Eclipse. In order to create a Java project, please choose 'File' menu and 'New', and then choose 'Java Project'. Then enter the project name in this field. The project name can be MyFirstJavaProject. You can also change the file location where the project will be saved from this section. I will not change. My projects will be saved in the Java Projects folder I created earlier. If you have multiple versions of Java Runtime Environment, you can choose the JRE that your project is targeting. By default, the newest JRE will be selected. We choose the Java SE 8 or Java 1.8. 

There is no need to change other options. And to create the Java project, I click the 'Finish' button. Yes, our new Java project was created in Project Explorer view. After that, we'll create a Java class in this project. To create a Java class from the source folder SRC, on the Project Explorer pane on the left side of the Eclipse IDE, right click to show the context menu and choose the menu item, 'New' and 'Class'. In this screen, enter helloworld as the package name. A package can be thought of as a folder and the package name starts with a lowercase letter. By convention, package names usually start with a lowercase letter. Also, we must specify the class name. Let's give the HelloWorld name for the new class. 

The class name must also begin with a capital letter. Also, the package name and class name must not contain spaces, otherwise the editor will warn us. This is what we call naming conventions in Java. We will explain this in detail in the course. And lastly, I will check the box, public static void main, to let Eclipse create the main method. The main method is the entry point for your application and will subsequently invoke all other methods required by your program. In the Java programming language, every application must contain the main method like this. In our next lessons, we will talk about the main method in detail. Now we can click the 'Finish' button. You see the HelloWorld class with the package in the Project Explorer view. Also, you see a comment line on the code area. TODO Auto-generated method stub. This is an Eclipse code template that is automatically created. 

If we don't like this template, we can change the templates via Window, 'Preferences', 'Java', 'Code Style' and 'Code Templates'. Select 'Code' and 'Method Body' and press 'Edit' to edit this template, and remove the TODO comment. Then press the 'Apply and Close' button. This comment line will no longer appear in the new classes we will create. We'll give detailed information about comment lines in Java in our next lessons. Now let's change the code of this HelloWorld.java file to the following code, but before, I will delete this line and I write System.out.println(). I put double quotes inside the parentheses, and inside the parentheses, I write Hello World. This method prints the contents inside the double quotes into the console and inserts a new line after. And in Java, it's necessary to add a semicolon at the end of the statement. Yes, that's all. To execute the Java Hello World program, right click on your program file and choose 'Run As', 'Java application'. At this stage, a pop-up window may appear asking if we want to save the application before running it. From here, you can select the always save option and click the 'OK' button. If everything is correct, you will see 'Hello World' in the console window. Congratulations. We did the first Java program. In our next lesson, we will go over this code in detail. 

Before ending the lesson, I also want to show you how to close Eclipse and open it again. After clicking the 'File' menu from the upper left corner of the interface and choosing the 'Exit' option at the bottom, you will have closed Eclipse. Of course, the editor can ask us if we want to save the project. After saving, our project will close successfully. Now let's restart Eclipse. While installing Eclipse, we created a shortcut on the desktop. From here, we can start Eclipse just by double click. And here we must choose a path for the workspace. I will use the default path and click the 'Launch' button. Please wait while Eclipse is being opened. And as you can see, the Eclipse was opened. Now, let's take a short break here, we'll continue in the next lesson.

 

About the Author
Students
458
Courses
47
Learning Paths
3

OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.

Covered Topics