Results 1 to 6 of 6
  1. #1
    quick help with terminal command

    Member Since
    Sep 12, 2009
    Posts
    31
    quick help with terminal command
    Could anyone tell me the command for compile in terminal? Trying to compile some java documents to run.

  2. #2
    quick help with terminal command
    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,393
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    If it's Java, try the following:
    Code:
    javac <name of file>
    Replace <name of file> with the .java file. That will create the required class files. Then, simply execute the following to run it:
    Code:
    java <name of class file>
    One thing to note here that is important - do not include the .class extension when executing java in that last command. For example, you would execute:
    Code:
    java MyClassFile
    instead of:
    Code:
    java MyClassFile.class
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  3. #3
    quick help with terminal command

    Member Since
    Sep 12, 2009
    Posts
    31
    Thanks, I knew how it all works just on DOS just didn't know what to replace the dos "compile" and "run" commands with for terminal. Having a few speed bumps in the transition but hoping its worth it in the long run.

    +rep for quick and accurate reply

    Thanks again.

  4. #4
    quick help with terminal command

    Member Since
    Sep 12, 2009
    Posts
    31
    Having another issue now, maybe I am pointing to the file incorrectly? Hiccups learning terminal, forgive me. This is my error:

    my terminal command:
    matthew-lastname-MacBook-Pro-2:~ Matt$ javac Documents/Professional/2011_Seg_C/java/Countertest.java



    result:

    Matt$ Documents/Professional/2011_Seg_C/java/ \\The previous is abbreviated in the following:

    java/CounterTest.java
    java/CounterTest.java: line 2: /Applications: is a directory
    java/CounterTest.java: line 3: 2010_BikeMapForWeb.pdf: command not found
    java/CounterTest.java: line 4: 2010_BikeMapForWeb.pdf: command not found
    java/CounterTest.java: line 5: 2010_BikeMapForWeb.pdf: command not found
    java/CounterTest.java: line 6: Desktop/: is a directory
    java/CounterTest.java: line 7: public: command not found
    java/CounterTest.java: line 8: /Applications: is a directory
    java/CounterTest.java: line 9: 2010_BikeMapForWeb.pdf: command not found
    java/CounterTest.java: line 10: 2010_BikeMapForWeb.pdf: command not found
    java/CounterTest.java: line 11: 2010_BikeMapForWeb.pdf: command not found
    java/CounterTest.java: line 12: Desktop/: is a directory
    java/CounterTest.java: line 13: syntax error near unexpected token `('
    java/CounterTest.java: line 13: ` public static void main(String[] args) {'


    I saw this and am bewildered and not even sure what to think as I have only coded a very basic counter. Why is this targeting my city bike path route pdf and such? This makes absolutely no sense to me. I have included my code below:


    /**
    * Description of the Class
    *
    * @author XXXX
    */
    public class Countertest {
    /**
    * This is the main method for this class
    *
    * @param args
    */
    public static void main(String[] args) {
    int counter;
    counter = 0;
    while (counter <= 10) {
    counter++;
    System.out.println("counter" + counter) ("counter" + counter*counter);
    }

    }
    }


    Maybe I should move this question to a different section of the forums?

  5. #5
    quick help with terminal command
    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,393
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    Yes, programming questions should be in the development forum.

    In the meantime, I tried to compile the code and got 3 errors all to do with the println line. It makes sense - why do you have the ("counter" + counter*counter) after the println statement?

    Another thing to note - the name of your file and the name of the class have to be exactly the same. While you have the same word, the case has to be the same as well. So, either name the file Countertest.java or rename the class CounterTest.
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  6. #6
    quick help with terminal command

    Member Since
    Sep 12, 2009
    Posts
    31
    The class designations was actually an error on my part because when I copy and pasted the code I didn't think the file name was capitalized. (but it is in reality).

    I'm no expert and am still learning java. The ("counter" + counter*counter) after the println statement is in response to the following requirement:

    "In the while loop, output the counter variable. Then output counter squared on the same line with a space in between the two values."

    I tried to run even some very basic code:

    /**
    * This is the main method for this class
    *
    *
    * @author XXXXXX
    * @param args
    */

    public class testcheck {
    public static void main(String[] args) {
    int one;
    String name;
    one = 25;
    name = "Fred";
    System.out.println("The integer is: " + one + "\n"
    + "The name is: " + name);
    }
    }

    with the following:

    Matthew-lastname-MacBook-Pro-2:~ Matt$ javac Documents/Professional/java/testcheck.java


    Documents/Professional/java/testcheck.java:20: illegal character: \0

    ^
    Documents/Professional/java/testcheck.java:20: illegal character: \0

    ^
    Documents/Professional/java/testcheck.java:20: illegal character: \0

    (This error repeats 100x)

    --This compiled and ran with no errors in DOS

    I know java is integrated, but is there anything at all I need to download that could be causing this? An update or package or anything?

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Similar Threads

  1. Terminal command help.
    By ladylisak in forum OS X - Operating System
    Replies: 2
    Last Post: 10-18-2013, 01:47 PM
  2. Terminal 'ls' Command Help
    By xxSwagPanda in forum OS X - Operating System
    Replies: 1
    Last Post: 03-26-2013, 11:18 PM
  3. Please help me with this Terminal command
    By nowakchr in forum OS X - Operating System
    Replies: 2
    Last Post: 12-12-2010, 10:39 AM
  4. terminal command help
    By ytbryan in forum OS X - Development and Darwin
    Replies: 2
    Last Post: 09-18-2009, 05:22 PM
  5. cd Terminal Command
    By Mac_Daddy in forum OS X - Operating System
    Replies: 4
    Last Post: 11-19-2007, 09:18 PM

Posting Permissions

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