Java Image Header

Learn Java 1- Project Setup and First Program

This is the first official in the Java coding series. However, the introuctory article, What is Java, can be found at the following link: http://nytjournal.org/articles/intro_to_java.html

In this tutorial, we will go over a very basic intro to Java (no prior programming experience is required). First, you will learn how to set up a Java project (throughout this Java tutorial series, Eclipse will be the editor used for development). Then, you will transition into writing a basic primary program. As is tradition when discovering a new programming language, whether it is the first or fifth that you are learning, we will start with the classic “hello, world” program.

Note: In this tutorial, and all subsequent tutorials assumes you have installed the Java Development Kit (included with it the JRE). To download the latest version of the Java Development Kit (JDK), click here, or refer to this "What is Java?" article. In addition, all Java tutorials from this point on will assume that you have installed the Eclipse IDE or some other equivalent editor.

Before beginning to code, we need to download the IDE (Integrated Development Environment) we will use to write our code. This tutorial will use Eclipse, a versatile, open source editor that can be easily downloaded here. Simply click the download button and begin installation. However, in the event that the link does not work, here is the download process by itself (if the link works, you can skip to step 4 of the process, otherwise begin at step 1):

  1. Visit Eclipse’s website (www.eclipse.org)
  2. This should take you to the following “home” page:

  3. Next, locate and press the download button (in this case in the top right corner)
  4. Should the screen not look like the above screen, simply look for the downloads page. This should bring you to a page looking like:

  5. Click the ‘Download 64 Bit’ button (which in your case may look slightly different)
  6. This should take you to a final download screen with a button prompting you to download it from a specified “window”, based on your computer’s specifications:

  7. After clicking the download button and opening the subsequent file, launch the Eclipse Installer and select ‘Eclipse IDE for Java Developers’, the first item in the menu.
  8. Unless you have a different location you would like eclipse to locate its program files, click ‘Install’ and wait for it to finish installation.

Congratulations! You successfully downloaded Eclipse, and you are ready to begin creating programs.

Once the installation process is finished, open Eclipse and designate a workspace folder for your projects to be stored in. As a general guideline, if you plan on working on your project with multiple devices, create a workspace folder stored in the cloud with Google Drive or Dropbox (Dropbox is preferred). However, if the device you are currently using is the only one you plan on working on, create your workspace folder anywhere on it that you would like, and give it a name.

After choosing your workspace, hit ‘Launch’, and, once the window loads, delete the Welcome screen. It is now time to create your first Java project! To create a project, navigate to File > New….and select Java Project (keyboard shortcut: Alt + Shift + N on Windows and Alt + Command + N on iOS). Name the project ‘HelloWorld’ and select ‘Finish’.

Inside of your new project should be an ‘src’ folder, which houses all of your source code (Java code). Right click on this folder and select New > Class (we will cover what classes are in another tutorial), and name this class ‘HelloWorld’. In order to be able to run this program, the class needs a main method, which you can add by typing this inside of the { }:


public static void main(String[] args) {

}


We will go over what exactly all of this means in a later article, but for now just know that it is a ‘method’. Next, add one line of code to this method:

System.out.println(“hello, world”);

Looking at this line of code, it may seem very cryptic. In fact, that is to be expected, especially if you are not a seasoned programmer. However, there is one important thing to note: the use of the semicolon at the end of the line. For now, just know that a semicolon is used to end a line of code that is inside of a pair of curly braces (we will go over technical terms for this later). This is a crucial piece of information that is necessary for functional programs.

Once this line of code is added to your program, you should be able to run it by clicking the “run button” (a green button with a white triangle inside). You should see a line of output in the console that says “hello, world”.

And just like that, you have just successfully written your first Java program!

Tagged in :Computer Science

Arthur Lafrance Image

Arthur Lafrance

Arthur Lafrance is a junior at Homestead High School in Cupertino, CA. Having worked with computers and computer programming since elementary school, he loves to learn and educate others about tech, and plans to pursue studies in the fields of computer science and computer engineering.