Simple Hello World Program In Java
Linux tutorials and code.
1 post
Page 1 of 1
Code: Select all
Were gonna save it as helloworld.java on our desktop.public class helloworld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Now open up your terminal and navigate to the desktop by putting down the following terminal command.
Code: Select all
This will change the directory to our desktop.cd Desktop
We will now be using the OpenJDK Java 6 Runtime as our compiler for our program.
If not already installed go ahead and use the following terminal command to install OpenJDK.
Code: Select all
Now that we have our compiler we need to compile our program that way it'll run. (Assuming you're still in the desktop directory on your terminal) Type in the following code in your terminal.
sudo apt-get install openjdk-6-jre
Code: Select all
Now if there's any errors in the code the compiler will automatically detect the error, but in our case we don't so in order to run our program lets put down the following terminal command, and we will now see our program. (Note: Your java program should be a .class file)
javac helloworld.java
Code: Select all
java helloworld
You do not have the required permissions to view the files attached to this post.
1 post
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023