Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Canada, Ontario, Mississauga
    Posts
    312
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Compile many file.java

    My friend downloaded a java source game, my question is, is there a way to compile all .java files at one time?

    I normally do this to a single file, javac file.java

    what if there is 10 java files?

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    If you have all the classes in one file like file.java then all the classes will compile into their respective class files. So for example if you had your Main.java file with this:

    PHP Code:

    import java
    .io.*;

    class 
    Main{

        public static 
    void main(String args[]) throws IOException{

            
    String name;
            
    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

            
    System.out.print("What is this new person's name: ");
            
    name stdin.readLine();
            
    Person person = new Person(name);

            
    System.out.println("A new person was created with the name " person.getName());
        }
    }

    class 
    Person{            
        
        private 
    String name;

        public 
    Person(String name){
            
    this.name name;
        }

        public 
    String getName(){
            return 
    name;
        }

    Now when you compile Main.java you will notice that you end up with two files Main.class and Person.class.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    Regular Coder
    Join Date
    Apr 2003
    Location
    Canada, Ontario, Mississauga
    Posts
    312
    Thanks
    0
    Thanked 0 Times in 0 Posts
    NNooo......

    I am asking, is there a way to compile more than one .java file?

    If I have 10 .java files, how do I compile them without known the order of it? some java file needs the java file to create an object.

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Well you don't have to know the order of the classes. Java handles all that. Ok then download some free java ide that has a feature for creating projects and will allow you to just compile everything in the project then just add all the java files to the project.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    Regular Coder
    Join Date
    Apr 2003
    Location
    Canada, Ontario, Mississauga
    Posts
    312
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, if I have num1.java and in num1.java has:
    public num2 myObject = new num2();

    but if I compile num1.java before num2.java, the compiler will say cannot file num2

    so I have to compile num2.java, then compile num1.java

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    You wouldn't be compiling more than one java file. As I showed in my first post all the classes are in the same java file. Then you compile just that one java file. Java will figure out where everything is at.

    Anyways just download some free java ide as I mentioned and do it that way. JCreator is a popular one.

    http://www.jcreator.com/download.htm
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can just compile them like this:
    Code:
    javac *.java
    The compiler takes care of the dependencies.

    shmoove

  • #8
    Regular Coder
    Join Date
    Apr 2003
    Location
    Canada, Ontario, Mississauga
    Posts
    312
    Thanks
    0
    Thanked 0 Times in 0 Posts
    javac *.java, that's cool, thanx


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •