quick help with terminal command

Joined
Sep 12, 2009
Messages
31
Reaction score
0
Points
6
Could anyone tell me the command for compile in terminal? Trying to compile some java documents to run.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
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
 
OP
M
Joined
Sep 12, 2009
Messages
31
Reaction score
0
Points
6
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.
 
OP
M
Joined
Sep 12, 2009
Messages
31
Reaction score
0
Points
6
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

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
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.
 
OP
M
Joined
Sep 12, 2009
Messages
31
Reaction score
0
Points
6
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?
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top