How to Start Working on Java

Download Eclipse

Eclipse is the IDE (Integrated Development Environment) for Java. This means that this is where you write your Java Programs. Before you do anything, make sure to go to the URL below and download eclipse. The website will show you eclipse neon (64 bits). Download this, then open it up.

http://www.eclipse.org/downloads/

 

What You need to Know before Starting Java

In Java, there are packages. These packages contain classes. The class is where the program is. The class contains functions and variables.

Setting it Up

On the quick access bar on the top, you will see a package icon that says “New Java Package”. Click on that and name your package as com.test.(You could name it anything else as long as it starts with a com.) Then, click on the icon next to the package icon. This says New Java Class. Name your class as HelloWorld.java.

Writing Your First Java Program

// When writing  like this, you are writing a comment

//Just like the arduino IDE, eclipse does not read this

//These are just for you to understand the program better

 

//In this program, we will write the words “hello world” on the blank screen.

//Copy this program down onto eclipse. The comments will help you understand it.

 

// Class that prints “Hello World 2016″ on the screen
public class HelloWorld {

     //defining variables

     static String myString = “Hello World”//A string is a type of variable that replaces a group of letters or words

     static int year = 2016;  //int is another type of variable that replaces an integer. 

 

     //defining functions/methods

     //the main function is where the action happens.

     public static void main(String… args) {

System.out.println(myString + year); //This tells the IDE to write down the variable myString and the variable           year.

 

}
}

The code

The first part of the code says static String myString = “Hello World”.

Static means that the variable isn’t changing throughout the program.

A string is a variable that replaces words or letters. It could be anything as long as it has only letters.

 

The second part of the code says static int year = 2016.

Int is another variable that replaces integers and nothing else. It can only consist of numbers. In this case, int is replacing 2016. The year does not change, so it is static.

 

The third part of the code says public static void main (String… args)  {

When we say public in Java, we mean that the function can be called by any other functions.

Void is used when no value or variable is returned. If it returned an integer, we would have used int. If it returned a letter or word, we would have used string.

In  the main function, it say System.out.println ( myString + year ) This tells the IDE to print the variable myString and the variable year. 

 

Run the Procedure

When you finish writing your program, go to the left and expand your package. You should see the class HelloWorld. Right click on the class and press run as. Then press one java application when it pops up. You should now see Hello World 2016 on the screen. Make sure you save your program every time before doing this.

Congratulations! You have just finished your first java program!

Leave a comment