My First Program in Java (Hello World!)
Page 1 of 1 • Share
My First Program in Java (Hello World!)
Yes, yes. I'm finally taking some programming classes and expanding my knowledge about computers, programming, and engineering. I wanted to post my first program here for everyone to see, and hopefully run it as well on their computers with me. First, you need a java compiler or a java machine installed on your operating system. If you have a Mac, OS X comes with all that already, and this tutorial was made for that.
First, open your Terminal. We will use the OS X Terminal to compile and execute our program today. From their, you want to type the following:
Then
Then
What we did here was create a new folder for our project to separate our files from the user-directory level. Then, we moved our Terminal to the new folder by using the command cd. Vi is the editor built in the terminal of the OS X. We created a new text editor file, and we declared it HelloWorld.java. In there you press the key (i) and you type:
One done, press ESC, and hold shift and press the key Z twice to save and exit the editor. Now type:
to compile your text file, and then finally type:
to see the results!
First, open your Terminal. We will use the OS X Terminal to compile and execute our program today. From their, you want to type the following:
- Code:
mkdir bin
Then
- Code:
cd bin
Then
- Code:
vi HelloWorld.java
What we did here was create a new folder for our project to separate our files from the user-directory level. Then, we moved our Terminal to the new folder by using the command cd. Vi is the editor built in the terminal of the OS X. We created a new text editor file, and we declared it HelloWorld.java. In there you press the key (i) and you type:
- Code:
public class HelloWord{
public static void main(String [] args){
System.out.println("Hello World!");
}
}
One done, press ESC, and hold shift and press the key Z twice to save and exit the editor. Now type:
- Code:
javac HelloWorld.java
to compile your text file, and then finally type:
- Code:
java HelloWorld
to see the results!
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|