Tuesday, June 23, 2015

Java Compiler for linux


You could use eclipse editor and stuff. This is the simplest method, where you just need any editor, like gedit, and a java compiler and java interpreter (Java Runtime Environment etc) for executing, I don't know much actually.

To compile a java program in linux, you need the java compiler, javac... like gcc for C and g++ for C++

To get javac, type this in terminal :

sudo apt-get install openjdk-8-jdk

and to execute, you need the 'java' command, I think it's preinstalled in the new versions of ubuntu, so, just type in the terminal :

java

and you should see many options for the command. Which means, it is already installed.

Or get it by typing this :

sudo apt-get install openjdk-8-jre


To verify it's working, open gedit or some editor and type this code :

class test
{
    public static void main(String[] args)
    {
        System.out.println("Hello World");
    }
}

And save this as test.java (don't change the name)

and run the following commands one by one :

javac test.java

java test

and it should print "Hello World" as output. Good luck ! :)


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.