Jump to content

[Guide]Starting Java Using Netbeans


Ke$ha

Recommended Posts

1. Brief history and overview:

In the late 70's Bill Joy(vice president of Sun Microsystems), wanted to design a programming language that combines the best features of C and MESA(an old programming language developed by Xerox). Joy as well attempted to re-write the UNIX operating system on C++ years later, but according to him, C++ wasn't the best choice for that specific goal. In January 1991 Bill Joy meets James Gosling, Patrick Naughton, Mike Sheradin in Aspen, Colorado. This was the beginning of the "Stealth project". The idea behind the project was to be simplified the programming of embedded devices plus their business distribution and sales on the market. C++ was considered as too sophisticated and not "flexible" enough. The software gurus behind the "Stealth project" then divided the goals and James Gosling was the person to develop the software for the new business solutions. Others took the business management and so on...Gosling named the new programming language "Oak", "thanks" to an Oak three outside his window. However, later the name "Oak" appeared as patent to other programming language. And Gosling was forced to change it. Then, surprisingly the language was named after a local coffee shop in the neighborhood of Gosling. It was perfect choice,just because the name also combined the initials of the programmers: James gosling, Arthur Van hoff, Andy bechtolsheim. After several years of tests and innovations plus millions invested, the new language appears as Java 1.0. The motto behind the release was: "Write Once, Run Everywhere".

 

 

The Java influence nowadays:

googlehits.png

 

The example above (date: 2004, April) shows the extreme popularity of Java. And not only that, but it shows that Java is the MOST POPULAR LANGUAGE. In fact although it's not mentioned in the above diagram, only C has more popularity, but assuming that on the Google searches, most software developers search for C in order to understand languages like C++ or C#, we can be sure that Java is by itself number 1 leader as popularity among the programmers nowadays. And...according to some surveys Java is also the programming language with best future. It is as well the leader when it comes to mobile phone applications, and we know the mobile phones became a top business target for companies like Google and Yahoo. At the end, it would be interesting to be mentioned that Google.com itself uses Java technologies. So, at the moment if you weren't aware of the great popularity, long history and perspective of Java, you are now maybe pretty interested to learn more of the Java language and of course, to learn how can you use this gem. Let's start.

 

 

2. Setup your computer to work with Java:

Java is FREE and multiplatform. You can run it on Windows (XP, Vista, and others), Linux, Mac OS, Solaris. However, for the current tutorial we will give a very detailed example how to install Java on Windows, and as well you will find that the installation is relatively similar on other operating systems. On Linux for example you could better use the compiled RPM package for easier installation. Then (on Linux) assuming that you use for example Redhat based distro, just open it with the "software installer" and you will have it installed in a minute. Now, lets see on Windows, what do you need:

 

2.1 Download Java:

At first sight, the tools needed to program on Java might be confusing for the newbie. But in fact programming on Java is pretty simple. All you need is the Java interpreter(which actually executes the Java programs) and some IDE that transforms the Java code into a program. In simple words, you write your Java code on the Java IDE and then later you test it thanks to the Java interpreter. Just two programs...

 

2.2 Download and install the Java platform (the interpreter):

Go here and save the dialog that appears: http://javadl.sun.com/webapps/download/AutoDL?BundleId=18713

This is the installer, which is about 15MB.

 

2.3 Running the Java installer:

Run the installer, chose "Accept":

javasetupjre1.jpg

You should see this:

javasetupjre2.jpg

After the installer finishes, you should see this:

javasetupjre3.jpg

And, this is it! You now have the Java platform installed, which does anything necessary so that you can now launch Java applications on your computer. Now that we have Java installed, lets install and the development environment, so we can create our own Java applications!

 

2.4 Download JDK + Netbeans(the Java development tools):

Go here:Download Java SE Development Kit 6u5 with NetBeans IDE 6.0.1 Bundle

1. Click on the "download" button.

2. Chose your OS. For this tutorial we use Windows;

3. Accept the Terms and conditions and click "Next".

4. On the next page your download will either start automatically if you use IE, or if you use some other browser you must save the link: jdk-1_5_0_15-nb-6_0_1-windows-ml.exe. This is located below "Required files"...

 

2.5 Install JDK + Netbeans:

Start the installer, you must see this:

javasetup1.jpg

Now you must see screen similar to this, click "Next":

javasetup2.jpg

On the next screen accept the "terms and conditions" and click "Next":

javasetup3.jpg

Chose installation directory and click "Next":

javasetup4.jpg

Select directory to install "Netbeans" and click "Next":

javasetup5.jpg

Now click "Install":

http://forum.codecall.net/images/Tutorials/apps/javasetup6.jpg

Now you must see the installation:

javasetup7.jpg

After the installation is over you should see this below...you have option to register "Netbeans" and Java, but I chose not to do, so I won't receive any ad emails...at the end click "Finish":

javasetup8.jpg

OK, so now you have the Java interpreter already installed + you have just installed the development environment so that you can now start the real programming! Now, on your Desktop you will have icon named NetBeans IDE 6.0.1. Click twice on it to open it.

 

 

3. Your first Java program:

After you open Netbeans you should see screen similar to this one below. Click on the image to see in full size.

javawelcome1-small.jpg

Now click on "File -> New project":

Click on the image to see in full size:

javawelcome2-small.jpg

Then chose "Java -> "Java application" and click "Next":

javawelcome3.jpg

Then, name your application as you wish and click "Finish":

javawelcome4.jpg

Then you should see a screen similar to this:

javawelcome5-small.jpg

Now, you can just copy the text below and paste it on a clean screen on the Neatbeans, you can even modify the code here and then paste it on the IDE:

     
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package javaapplicationmyap;

/**
*
* @author Deus
*/
public class Main {

   /**
    * @param args the command line arguments
    */
   public static void main(String[] args) {
       // TODO code application logic here
       
       System.out.println("Hello World");
   }

}

Another closer screenshot on the "Hello world" program:

 

 

 

Now click "F6" on the keyboard OR you can chose "Run -> "Run main project":

Click on the image to see the full size:

javawelcome7-small.jpg

 

You should now see this, take a look on the bottom of the Netbeans, the execution of the program showing the string "Hello world".Click on the image to see full size:

 

javawelcome8-small.jpg

Though this program might seem "Easy" to you, it actually shows you many aspects of the OOP programming plus the Java programming itself. Lets explain the program in detail:

 

On the very top of your application you will spot the pale/gray lines:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/ 

 

In fact these lines are NOT 100% necessary. These are the so called "comments". A comment is just line of explanation written by the programmer to explain to other programmers what the purpose of certain thing in the program is. The compiler actually neglects the comments. But of course, as any part of the programs the comments have own syntax. Note the "/*" signs. Every comment must start either with the /* sign and end with a closing *\ or IF your comment is just on a single line you can use //. These are the so called "C like" comments. Just because the C language was the first one to use such style of comments.

 

The first line "package javaapplicationmyap;" , simply shows you that everything in your application belongs to a package of classes called " javaapplicationmyap". The word "package" is a keyword, the " javaapplicationmyap" is the package of classes and the ";" is the semicolon identificator which is nothing special but a way to close the current line.

 

The second line of your first program "public class Main" defines the class.

 

The third line is the so called "method". For now you can think of the "method" as an obligatory part of any Java program. All Java programs must have the so called Main method which you use here as well...public static void main(String[] args).The word "public" means that this method can be accessed anywhere later in your program. The word "static" means that this method doesn't read any data out of that specific class, the word "void" means that nothing is expected to be returned by the method and "main" is as we mentioned the required method, stating that this is the famous and required "main" method.

 

And below is the heart of your program. Within the quotation marks you can write ANY sentence you want, just to have some fun with your first program. Such as you can write your name there or the name of your beloved one. It's up to you, but remember Java can DO a lot more than that! As we stated in the very beginning of this tutorial it is used in Google, it is even on Mars, since the Mars tutor is programmed on Java. It is on the mobile phones.

 

System.out.printIn("Hello world");

 

Credits Jordan

 

 

 

Link to comment
Share on other sites

Well explained, but..

 

Eclipse is much better for coding than NetBeans.

 

thnx! ok eclipse is much better and for me ! but i just want to help ppl that hate eclipse! i know lot of ppl that cant work with eclipse :)

Link to comment
Share on other sites

thnx! ok eclipse is much better and for me ! but i just want to help ppl that hate eclipse! i know lot of ppl that cant work with eclipse :)

 

Yeap, maybe.

 

NetBeans has very good GUI Builer (100x times better than Eclipse GUI Builer plugin)

 

But Eclipse code editor is 101x times better than NetBeans.

 

- in my opinion of course.

Link to comment
Share on other sites

I must say I nice guide, even though I am already using netbeans and it is great. Eclipse better than netbeans ? I would not say so, I used to use netbeans and it kept hugging all memory and crashing etc. Netbeans has not crashed once for me and does not use as much resources as eclipse did. Also Netbeans has better identions and hints.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


×
×
  • Create New...