Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Dec 2, 2012

How to Install JDK 7 on Ubuntu


There are several JDK implementations available for Linux, such as Oracle JDK 7, OpenJDK, Sun JDK 6, IBM JDK and GNU Java Compiler. We shall choose the Oracle JDK 7 (Ubuntu chooses OpenJDK as its default JDK, which is not 100% compatible with Oracle JDK).



Step 1 : Check if JDK has already been Installed


 


Open a Terminal or press Ctrl + Alt + T and issue this command:


 


javac -version


 


If a JDK version number (e.g., "javac 1.7.0_{xx}") appears, JDK has already been installed. You can skip the installation and goto step 3.


 


Step 2 : Download and Install JDK


 


Goto JDK (Java SE) download site at



Select "Java SE 7ux" ⇒ JDK ⇒ Download ⇒ "Accept Licence Agreement" ⇒ Select Linux x86 (for 32-bit system) or Linux x64 (for 64-bit system) "tar.gz" package, e.g., "jdk-7ux-linux-i586.tar.gz". The tarball will be stored in folder "~/Downloads", by default.


We shall install JDK under "/usr/lib/jvm". First, create a directory "jvm" under "/usr/lib" (with superuser authority "sudo"). Open a Terminal and issue these commands:


 


cd /usr/lib


sudo mkdir jvm


 

Dec 1, 2012

How to Install NetBeans on Ubuntu


To use NetBeans for Java, PHP programming, you need to first install JDK. Read "How to install JDK on Ubuntu".



Step 1 : Download netbeans


 


Download NetBeans from http://netbeans.org/downloads/. Choose platform "Linux (x86/x64)" ⇒ "Java SE". You shall receive a sh file (e.g., "netbeans-7.x-ml-javase-linux.sh") in "~/Downloads".


Set the downloaded sh file to executable and run the sh file.




Step 2 : Install netbeans


 


Open a Terminal and type the following commands.


 


cd ~/Downloads


chmod a+x netbeans-7.x-ml-javase-linux.sh   // Set to executable for all (a+x)


./netbeans-7.x-ml-javase-linux.sh                   // Run


 


Follow the instructions to install NetBeans.




Jul 3, 2012

Compile and Run a Hello-world Java Program


Step 1


 


Open "Folder" and create a new directory called "myproject" under your home directory to keep all your works.




Step 2


 


Open "Text Editor" (gedit). Enter the following source code and save as "Hello.java" under the "~/myproject" directory created eariler.


 


    public class Hello {   // To save as "Hello.java" under "~/myproject"


       public static void main(String[] args) {


          System.out.println("Hello, world from Ubuntu!");


       }



    }