0

Please click this image for the description

Hi guys, so my homework is asking that I run my program on command prompt which would be Terminal for Mac users like me.

How would I run this on Terminal? How to I access bin?

Also for the >java Echo "echo this string"

How can "echo this string" be accessed as arg[0] and arg1? Which is which for arg[0] and arg1???

3 Answers3

0

If you already have your Echo.java file, compile it with javac Echo.java.

After that, you can run the generated Echo.class with java Echo "echo this string".

0

How can "echo this string" be accessed as arg[0] and arg1? Which is which for arg[0] and arg1???

you just System.out.print them in your code and that's it.

on how to start your app from the terminal use

java MyClass 

if it's a class or

java -jar MyClass.jar

if it's a jar file

and you can add the Sting [] args in your command like this

java MyClass first_arg second_arg ect...

the array is seperated by white spaces and it's just accessed within your main with the args[] array .

here is what your Echo class might look like :

public class Echo
{
public static void main (String [] args )
{
for (String str : args )
{
System.out.print(str +" " );
}
}
}
0

from https://www.oracle.com/technetwork/java/compile-136656.html the official Oracle techno document

//A Very Simple Example
class ExampleProgram {
  public static void main(String[] args){
    System.out.println("I'm a Simple Program");
  }
}

Compiling the Program

The Java compiler is invoked at the command line on Unix and DOS shell operating systems as follows:

  javac ExampleProgram.java

Interpreting and Running the Program

The Java interpreter is invoked at the command line on Unix and DOS shell operating systems as follows:

java ExampleProgram

At the command line, you should see:

I'm a Simple Program
mcvkr
  • 3,209
  • 6
  • 38
  • 63