본문 바로가기
my_lesson/_JAVA

Java Applications

by boolean 2016. 2. 16.
728x90

Java Applications

General Steps to Creating, Compiling and Running Java Programs
Applications in Unix & Linux server


  1. Open a Unix window.

  2. Now, change to the directory of your choice from within the window. 
    For example: 
     prompt% cd MyJavaStuff 
    

  3. 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 viemacspico, or whatever editor you use 
            with the name of the Java file: 
     prompt% vi Test.java  
    
    or
     prompt% emacs Test.java  
    
    or
     prompt% pico Test.java  
    

  4. The source code, Test.java, might look like this: 
     public class Test
     {
            public static void main(String args[])  
            {
             	System.out.println("We work!");  
            }
     }
    
    Don't forget to save the file!

  5. Double check the name of the Java program file you just saved 
        by listing out the files in the current directory: 
     prompt% ls  
    

  6. 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
     prompt% mv  A.java.txt  A.java  
    
    Now if you list the files in the directory, you should see it named correctly

  7. 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  
    

  8. 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.

  9. 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  
    

  10. 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

댓글