Lesson 1: Get started with Java

Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented. And it's specifically designed to have as few implementation dependencies as possible, so it's platform-independent. Java applications are compiled to bytecode that can run on any Java Virtual Machine, or JVM, regardless of the underlying computer architecture. Java uses an automatic garbage collector to automatically manage memory in the object life cycle. The syntax of Java is heavily borrowed from C++. And It is important to note that Java and JavaScript are two separate languages.


JVM, JRE, JDK and IDE

A Java virtual machine (JVM) is an abstract computing machine that enables a computer to run a Java program.

Java Runtime Environment (JRE) is a software package that contains what is required to run a Java program.

Java Development Kit (JDK) is a superset of a JRE and contains also tools for Java programmers, e.g. a javac compiler.

An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of a source code editor, build automation tools and a debugger. Most modern IDEs have an intelligent code completion.


Install JDK and Eclipse IDE

There are many Java IDEs that you can download, but in this tutorial we will be using Eclipse IDE which is one of the most common tools used to develop Java applications.

Before you download Eclipse IDE, you should first install the Java Development Kit (JDK) by going to:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

To download the JDK, simply tick the box to 'Accept License Agreement' and click on the download link for your operating system.

Next we will install the Eclipse IDE.

To download Eclipse go to the following link: https://www.eclipse.org/downloads/
Make sure to download Eclipse for the correct operating system.
If you dont know whether your operating system is 32-bit or 64-bit:

  1. Right click on 'My Computer'
  2. Click on 'Properties'
  3. This should open up a new window
  4. Next to 'System type' you should see either 32-bit or 64-bit

Exploring the Eclipse IDE

Open up Eclipse and you should see a window asking you to choose a workspace.
You can create a folder somewhere on your hard drive and select that path or just use the default workspace created by Eclipse.

To create a new project.
Click: File -> New -> Java project

(img placeholder)

You can name the project whatever you want, but I will name it demo.
Right click on your project folder in the package explorer.
Then select: New -> Class

(img placeholder)

Name it 'Helloworld' and tick the 'public static void main(String[] args)' checkbox.
This will allow Eclipse to automatically generate a Main method.
The 'main' method is the first thing that is executed when the program starts.

(img placeholder)

Inside the 'main' method, enter the following line of code:
System.out.println("Hello World!");

(img placeholder)

Now if you save the file (ctrl+s) and click on the green button (looks like a play button), your 'Helloworld' program should execute.
You should now see 'Hello World!' printed to your console.

(img placeholder)

Congratulations! You have just created your first Java program!

Exercises:

  1. Try printing out: I am 'yourname' in your console by editing the current code.
  2. There is something wrong with the following lines of code, try fixing them:
    System.out.println(What is your name?);
    System.println("What is your name?");
    System.out.println('What is your name?');
  3. Print a list of numbers 1 to 5 (each number in a new line).