Getting started with Java, compiling HelloWorld.java
Hey, I know this is a worn out topic but all the search results I found on Google told me to apt-get a program which wasn't in the repository.
I basically need to compile a simple java program, and run it. The program is just a simple Hello World program: Code:
public class HelloWorld |
Save that code to a file with the "HelloWorld.java" (same name as public class + ".java").
In a shell go to the direcotory where "HelloWorld.java" is stored, and type the command: javac HelloWorld.java Then run it with the command: java HelloWorld |
Quote:
This is so much hassle though, it creates a HelloWorld.class file and you have name the file the same as the public class (you don't have to do that in C++ or Python).. Is it possible to compile and run the program in the same command? Most of the time you just want to test the program and you don't need the .class file. Why do you write $ java HelloWorld though in the second step? There isn't any file or folder called HelloWorld, what file does the program call and why don't you write $ java HelloWorld.java or $ java HelloWorld.class? What does the .class file do anyway? |
Quote:
|
Hi -
Quote:
Quote:
Google for "Netbeans" or "Eclipse" (two excellent Java IDE's); and "ant" or "maven" (for automated Java build and deployment tasks). All Open Source and freely downloadable. |
When I tried my first steps on the slippery road to Java, I found this website helpful: http://java.sun.com/docs/books/tutorial/
Ant was a great help also for me when I had to compile a large project without any instructions: http://ant.apache.org/ jlinkels |
All times are GMT -5. The time now is 12:47 AM. |