Main Method
Since your very first Java program you've written this method:
public static void main(String[] args) {
}
String[] args?
Drill¶
ArgsArray/src/drills/
In the drills folder create a new Java program, ShowMe.java and give it a main method.
* In main add:
System.out.println(args);
Practice Exercise¶
When you print the reference value for an array, you'll see something like:
* [Ljava.lang.String;@3d4eac69
* [ means it's an array reference.
* L means the elements of the array are objects of a cLass.
* java.lang.String; is the class of objects the array holds.
* @3d4eac69 is ... well, never mind for now.
To understand args we need to go back to the command line.
Drill¶
Open a terminal and navigate to the Eclipse project folder for this section.
cd ~/SD/Java/workspace/ # Go to the workspace directory
ls # list the files and folders here
cd ArgsArray/ # Go to the project folder for this section
find . # Find and print the name of everything in and under the current directory.
cd bin/ # This is where Eclipse puts compiled classes.
ShowMe program from the command line:
java drills.ShowMe
ShowMe.java in Eclipse and save, Eclipse compiles our changes and recreates drills/ShowMe.class, which we'll run in our terminal with java drills.ShowMe.