Welcome to Dung.L.T's Blog

JDK/Netbeans on Ubuntu

,

The software packages you'll need are these installation files (from the course website).
jdk-6u11-linux-i586.bin (JDK: Java Development Kit — see the JDK Installation section)
netbeans-6.5-ml-javase-linux.sh (NetBeans)
jdk-6u10-docs.zip (Java Documentation)
The key JDK package must be installed first. This package may be part of a Linux distribution which you can use. These packages and other related ones are available from the respective home sites below. The Java site provides a cobundle version with JDK and NetBeans, but I prefer separate installations. The Java Documentation is not strictly necessary, but it is needed to provide online Javadoc reference in Netbeans.

FROM: http://www.cs.wcupa.edu/rkline/netbeans-lin.html

Software Home Download
Java http://java.sun.com http://java.sun.com/javase/downloads/
NetBeans http://www.netbeans.org http://www.netbeans.org/downloads/
JDK Installation
Sun has recently begun freeing their Java implementation and thereby opening the way for free software developers to create an entirely free implementation of Java. This free form is now available as the OpenJDK package.

In Linux, it is common to run installations as shell commands. Additionally, you need to validate yourself as root to perform many of the installation steps. I'll assume that you know about and/or have configured sudo to run as root (and validate against your login if necessary).

As of Ubuntu 8.10, the OpenJDK is available for installation like this:

$ sudo apt-get install openjdk-6-jdk

Alternatively, the Sun JDK installation can be installed like this:

$ sudo apt-get install sun-java6-jdk

With the SUN installation, you have to do some license-accepting, so be ready to tab to the OK button and hit Enter.
Your own installation
Otherwise, do the installation by hand into the directory of choice. It is common to install such non-package software into the /usr/local/ directory and we will assume this. In a shell, navigate to where the JDK archive has been downloaded and follow these steps.

$ chmod +x jdk-6u11-linux-i586.bin
$ sudo mv jdk-6u11-linux-i586.bin /usr/local
$ cd /usr/local
$ sudo ./jdk-6u11-linux-i586.bin

The installation throws you into the more utility to force you to read the license. Type q and follow instructions to leave this reader and begin the installation. The installation directory is

/usr/local/jdk1.6.0_11

It's a good idea to make the installation version-independent with the following command:

# ln -s jdk1.6.0_11 jdk

The JDK installation now has version-independent installation "directory"

/usr/local/jdk

You will also probably want to make the Java executables available to the shell. To do so, add these settings to your ~/.profile file:

export JAVA_HOME=/usr/local/jdk
PATH=$JAVA_HOME/bin:$PATH

You will need to use a text editor to edit the file of choice. If you know little about what you're doing, the simplest choice is probably the GNOME editor gedit. You can invoke it like this:

$ gedit ~/.profile (assuming Ubuntu)

After adding them, log out and log back in again and then confirm that these settings are in effect by doing:

$ echo $JAVA_HOME
$ echo $PATH

Netbeans Installation
NetBeans is SUN Microsystems' full-featured community-based Integrated Development Environment (IDE) for a variety of software development interests including a Java Visual GUI editor, Web developement for Java, Php, Ruby, C/C++, etc.

The download site offers a bewildering array of choices of Netbeans, they are differentiated by a "download-type" term embedded in the download file. I generally prefer to be minimalistic and augment the features as needed. Other features can easily be added through Netbean's plugin facility or by separate downloads. The download type I'm using is javase as seen in the file:

netbeans-6.5-ml-javase-linux.sh

This contains only the salient Java features needed for us to get started. Others will be added later.

Install by executing and following the installation wizard. A NetBeans executable shortcut can be found in the Applications Programming menu.
Configuration
The configuation of NetBeans is effected through the configurator activated by Tools Options. Certain modifiable features may not be accessible through this configurator. For example, the editor's default line height has been known to be too large. To change this, you'll need to edit the file

org-netbeans-modules-editor-settings-CustomPreferences.xml

found in the folder (HOME is your home directory)

HOME/.netbeans/6.5/config/Editors/Preferences/

To reset the line height, add this XML entry within the editor-preferences tags:

<entry javaType="java.lang.Float" name="line-height-correction"
xml:space="preserve">
<value><![CDATA[0.75]]></value>
</entry>

Hello World Program
NetBeans creates directories called src which consist of one or more package of Java source files along with other types of support files. The compiled classes are kept in a separate build directory.

To create a simple "Hello World" program, start up NetBeans and follow the steps below.

1. Select File New Project
2. In the New Project window, select the Java category, and choose Java Application, then Next.
3. Choose the project name HelloWorld. The other settings have default values which you probably want to use. The project location cannot be an existing directory.

NetBeans also pre-checks the boxes Set As Main Project and Create Main Class. Leave these checked. Click Finish.
4. In the left-hand window there you can observe three views of the netbeans contents: Projects, Files, Services. For the most part you can work from the Projects view. In the Projects window you will see the file Main.java as part of the automatically-created helloworld package.
5.

Go to the Files view and observe the structure which NetBeans creates. The Main.java file is in a package directory helloworld within the src directory, meant to hold all the source packages.
6. Within the public static void main function (not the Main constructor), type

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

Observe the various syntactic assists which the editor offers when you pause after typing a ".".
7. Select File Save (or Ctrl-S) to save.
8.

There are several ways to compile and run this application. One way is to right-click on Main.java and select Run File from the popup menu. This will compile and execute the file. Look for the output in the Output window at the bottom. The program output is viewable between the run-single: and BUILD SUCCESSFUL lines.
9. Another way to build and run the project is by selecting Build Build Main Project or F11. This operation goes a step further and archives the compiled classes into the jar file Hello_World.jar found in the newly created dist directory.

Afterwards, select Run Run Main Project or F6.

Shell Execution
NetBeans makes it easy to run its applications through the shell, assuming that your java executable is accessible. First of all, you have to execute "Clean and Build" to create the JAR file. The output of this operation indicates what should be done.

After doing so, open a shell and navigate to the dist folder in the HelloWorld. From this folder run:

java -jar HelloWorld.jar

The dist folder is meant to be for "distribution." NetBeans will put all relevant libraries in this folder as well so that this can act as a standalone executable which can run on any system which has JRE installed. All Windows systems will have it installed; the only hitch is making sure that the version is up to a suitable level.
Install Javadoc Documentation
Choose a permanent location in your system for the documentation zip file jdk-6u10-docs.zip. For the sake of specificity, let's say it is this:

/usr/local/share/docs/java/jdk-6u10-docs.zip

In Netbeans, open Tools Java Platforms and select the Javadoc tab from the Java Platform Manager. Click the Add ZIP/Folder ... button and navigate to select the above zip archive.

To see what effect this has, right-click on the "println" portion of the statement

System.out.println("Hello World")

in the Main.java file. From the popup menu, select Show Javadoc.

FROM: http://www.cs.wcupa.edu/rkline/netbeans-lin.html

Install Java JRE 1.6.0 (Update x) on Hardy as the Default Java RuntimeLan dau sua loi trong Ubuntu

Comments

Dung L.T.Nobita2708 Sunday, January 18, 2009 4:17:13 PM

Moi thu deu tot. He he. Tu nhien nho ra minh co cai dia NetBean duoc tang hoi nam thu nhat. May qua. Do phai down. Ubuntu that la tuyet voi

Anonymous Monday, September 20, 2010 7:37:34 AM

duyluong writes: khong biet sao nhung cai lan dau dc sau cai lai ubuntu bjo khong cai dc netbean nua bjo lam lai xem sao

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies