Mac Forums

Mac Forums (http://www.mac-forums.com/forums/)
-   OS X - Operating System (http://www.mac-forums.com/forums/os-x-operating-system/)
-   -   quick help with terminal command (http://www.mac-forums.com/forums/os-x-operating-system/226300-quick-help-terminal-command.html)

MKoop 01-13-2011 08:39 PM

quick help with terminal command
 
Could anyone tell me the command for compile in terminal? Trying to compile some java documents to run.

vansmith 01-13-2011 09:57 PM

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

MKoop 01-13-2011 11:12 PM

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.

MKoop 01-13-2011 11:26 PM

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?

vansmith 01-14-2011 12:25 AM

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.

MKoop 01-14-2011 12:35 AM

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?


All times are GMT -4. The time now is 08:12 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.