To use the method described in this article, you must have a Java development environment such as Oracle Java, OpenJDK, or IBM Java installed on your computer. If not, read this article or simply enter (in the terminal) the command sudo apt-get install openjdk-7-jdk
If you have Java installed on your computer, create a new environment so that you can write your first Java program later. Some users use an IDE such as the Eclipse IDE or NetBeans IDE in which to write programs. This approach simplifies programming when many Java class files are used.
This article describes Java programming without using an IDE, but using the Java JDK, directory, Java text file, and text editor.
Steps

Step 1. Open Terminal when Java is installed

Step 2. Create a folder for Java programs
Open a terminal and create a folder. For this:
3 Enter the command mkdir Java_Applications Type (or copy and paste) the cd Java_Applications command For example, let's write a simple Hello World program. In a text editor, you need to enter several lines of program code.
The folder "Java_Applications" will be created
Step 4. Go to the "Java_Applications" folder
You will be taken to the created folder "Java_Applications"
Step 5. In a text editor such as nano or gedit, create a Java file
Step 6. Now enter the following lines of code
import javax.swing. *; public class HelloWorld extends JFrame {public static void main (String [] args) {new HelloWorld (); } public HelloWorld () {JPanel panel1 = new JPanel (); JLabel label1 = new JLabel ("Hello world; this is my first Java program on Ubuntu Linux"); panel1.add (label1); this.add (panel1); this.setTitle ("Hello world"); this.setSize (500, 500); this.setDefaultCloseOperation (JFrame. EXIT_ON_CLOSE); this.setVisible (true); }}
Step 7. Save the file as HelloWorld.java 8 Compile the HelloWorld.java file into a Java class file
To do this, enter the following command.
- javac HelloWorld.java
- (the file will not compile if there is no javac on the computer; in this case, read the information in the introduction or enter (in a terminal) the command sudo apt-get install openjdk-7-jdk)
Step 9. Run the created program
To do this, enter the following command.