728x90
Java Applications
General Steps to Creating, Compiling and Running Java Programs
Applications in Unix & Linux server
- Open a Unix window.
- Now, change to the directory of your choice from within the window.
For example:prompt% cd MyJavaStuff
- Using the editor of your choice, create some Java source code
For example, suppose we want a Java class named "Test",
then we would start vi, emacs, pico, or whatever editor you use
with the name of the Java file:
orprompt% vi Test.java
orprompt% emacs Test.java
prompt% pico Test.java
- The source code, Test.java, might look like this:
Don't forget to save the file!public class Test { public static void main(String args[]) { System.out.println("We work!"); } }
- Double check the name of the Java program file you just saved
by listing out the files in the current directory:prompt% ls
- If the name of the Java program file listed does not end in .java,
you need to rename or move (mv) it so that it does
For instance, if the file appears as A.java.txt, type Now if you list the files in the directory, you should see it named correctlyprompt% mv A.java.txt A.java
- Assuming we saved the Java source code (as in step 4) from within our editor,
we can now go back to the command prompt and compile it.
This is done with the javac compiler command:prompt% javac Test.java
- If it doesn't compile, go back to the editor and edit the A.java file
to remove the error.
Then repeat step 7 after saving the changes.
You may have to do this several times before there are no more compile errors. - When it compiles fine
(we know this by the fact we had no error messages
and the "Test.class" file exists),
we can run the application (found in Test.class) using the java command
followed by the name of the class (without the extension):prompt% java Test
- At this point you should see:
We work!
'my_lesson > _JAVA' 카테고리의 다른 글
Java JDBC (0) | 2016.05.10 |
---|---|
Java Applet (1) | 2016.02.16 |
Java Platform Standard Edition 8 Documentation (0) | 2016.02.16 |
댓글