Getting started with Java

This article is based on programing in that aspect what you need to have. There are many ways to program from notepad to more powerful and wiser Integrated development enviroment (IDE). One example is Eclipse.

Thinks you need

Actually if you have notepad++ from my other article where I talked basics of HTML, you are able to use it as well. But if you want to actually run your Java code, you need to use terminal emulator. In this article series about programing with Java, I use Eclipse Kepler standard 4.3 because I wanted to test it. There are other Eclipses like Juno, Indigo and Helios, and there are some parts that aren’t the same. But to get started you can download one of them and see it out. Eclipse home site and here is Java if you don’t have it already.

There are some videos in Youtube.com if you are not able to launch your Eclipse. As for me, I wasn’t able launch it at first time because out-dated Java. Then I updated it and it works fine.

To get Eclipse download it from Eclipse home site and unzip it to the folder where you want to put it. Maybe in program files or somewhere else where you are able to launch it.

First lauch

First time when you launch Eclipse, it ask you to select workplace. This means that all your Java files are going to be saved in that place. I suggest that you create whole new folder for it in your user account. It would be the same place, where you would create public_html folder. This only my suggestion so you can basically create it anywhere you want.

Launch screen

Launch screen should look some what this expext if you run other than Kepler version.

Next press “Ok” and you Eclipse  should open in window with all kinds of help text and other quick starts. After this you are able to run freely and try and out. But does the program actually work? And more overly how do you create code there? Answer in next bullet-in.

Making first Java program

Aren’t you even a little bit excited, we are going to make first Java program. Well what you want to try out in all programing are you able to create code that prints you text “Hello World!” . With Eclipse as our playground let’s make it happen.

First go to left corner and select file  -> new -> other…

Part one, selection

Part one, selection

There select Java-Project and select next. Now you create your Project name like “HelloWorldTest” and select finish. Now you should have Project named “HelloWorldTest” in your upper left corner and it should look some like this. If you don’t have that little arrow in src no worries. I talk it out next

Part two, after project creation

Part two, after project creation

Now next go over src and right-click. Now select new -> package and name it. After that hover over created package and right-click. Then select new -> class . Name it like “HelloWorld” and select the first method as well the last. It automatically types the first parts of the code for you.

Now to the code. I wrote it this how:

package FirstJava;

public class HelloWorld {

 public static void main(String[] args) {
 // TODO Auto-generated method stub

 System.out.println("Hello World");

 }

}

Very simple code.

Next to actually see does this work go to run -> run as -> Java application . Press ok to questions if it asks and then you should this to lower console.

Part three, results as expexted

Part three, results as expected

Conclusion

It’s not hard put it tooks some time to getting used to actually remember all the phases. In much bigger projects there can be multiple projects and packages to run some simpliest applications. Also some database is going to be required.

– Tuomas Törmä

Sources

  •  Studies in Haaga-Helia Autumn 2013 course Introduction to Programing Teacher Lahtinen Seija
  • Eclipse.org (Link)
  • Java.com (Link)

Leave a comment