Setup Java Development Kit(JDK) on Ubuntu

Introduction to java

Java is a programming language originally developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture. Java is a general-purpose, concurrent, class-based, object-oriented language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere" (WORA), meaning that code that runs on one platform does not need to be recompiled to run on another. Java is currently one of the most popular programming languages in use, particularly for client-server web applications, with a reported 10 million users.


    Download JDK

  1. First you need to download JDK Tool kit from Oracle.
  2. Select correct architecture according to your computer.In most cases it automatically detect the architecture.
  3. If you are not sure, you can find the cpu architecture by typing lscpu in terminal.

  4. Extract JDK

  5. Once you get the JDK binary file it looks something like this jdk-[version]-linux-[architecture].bin
  6. Now open terminal and go to download directory.
  7. Type chmod +x jdk-[version]-linux-[architecture].bin to enable executions on file.
  8. Now execute the bin file by typing ./jdk-[version]-linux-[architecture].bin in the terminal.You get something like this as output.
  9. Press enter and you get web page that asking to register the product.Register there by continuing the steps.(optional)
  10. You see it creates folder called jdk[version] in execution path.Now you have the JDK.
  11. Configure JDK

  12. First you have to copy JDK to standard location by typing sudo mv jdk[version] /usr/local in the terminal.(by default system looks these places for installed softwares)
  13. Now change the path of the terminal to /usr/local by typing cd /usr/local in the terminal.
  14. Then make jdk folder executable for all by typing chmod +x jdk[version] in the terminal.
  15. Now you have to setup JAVA_HOME environment variable and add java to system path.
  16. Open the system wide bash configuration file by typing sudo gedit /etc/bash.bashrc in the terminal.
  17. Go to the bottom of the configuration file and add :
    JAVA_HOME=/usr/local/jdk[version]
    PATH=$PATH:$JAVA_HOME/bin
  18. Now save the document and close the editor and terminal.Now you are ready for work.
  19. Open your favorite text editor and try this.
  20. 
    public class HelloWorld{
        public static void main(String args[]){
            System.out.println("Hello World");
        }
    }
                    
                    
  21. Save this in a file named HelloWorld.java and compile by typing javac HelloWorld.java in the termainl.
  22. Run this by typing java HelloWorld in the terminal.If everything goes right you can see Hello World in the terminal window.

0 comments:

Post a Comment