How can I compile a .java file. What programs will I need and if I need java jdk I need help installing that. I'm very new to ubuntu so any program I need to install I will need a tutorial on how to install them.
To compile the file, open your terminal and type
To run the generated class file, use
But to do this you need to have the Java JDK installed in your computer. You can install it with the instructions in How do I install Java?.
OpenJDK work best for me. It's simple and I have never face any problem. Just follow these simple steps:
You can use any text editor (like gedit) ,
replace the filename with watever name you want
you need to be on same directory as the "present working directory" (got by running
You need to install a JDK, Java Development Kit. Ubuntu contains a metapackage default-jdk, which depends on currently prefered JDK. Now it is openjdk-6-jdk.
To compile a Java file to runnable .class file you can run
and run it
It is the most simple use-case and mostly it doesn't work because java classes mostly depends on other java classes placed in libraries.
So you would probably like to use some more sophisticated solutions. Most text editors supports Java syntax highlighting, for example jEdit, kate or vim, but they don't solve your compilation issue.
You have another option - you can install a full featured Java IDE. Ubuntu comes with both main OpenSource Java IDEs - NetBeans and Eclipse.
If for example your file is
You want to do:
However, it is a common convention to give classes and files the same name.
For more detailed official Java documentation, please visit this link.