SECTION I. in this section you will explore writing and compiling a java class w
ID: 3737524 • Letter: S
Question
SECTION I. in this section you will explore writing and compiling a java class without the use of an IDE. You will also arguments to supply parameters to your program Note: these instructions are for written for the Microsoft Windows environment. Iif you choose to work in Linux or OSX, you will have to use slightly different commands. 1. 2. Open a text editor (Notepad+ +. Notepad, Textwringler, etc.) Type in the following java code: public class Parans public static void nain(string argsI]) int nunArgs args. length; System.out.printIn("Number of command line arguments provided nunAr gs): if(nunArgs ) systen out printin( The command line argunents are:) for (String it: args) System-out . pr int f ( -Argument is %ssn., item); 3. Save the fle to the root of your flash drive with the name parms.java. Take note of the drive letter of your flash drive. 4. Click the Windows Start button and type cmd and press Enter s. Change the current drive to your flash drive by typing the drive letter followed by a colon and pressing Enter, e.g.: E: 6. Type dir and press Enter to see a list of files. Make sure you see parms java in the list. 7. At the command prompt. type javac Params.java and press Enter a. javac is the Java command line compler command. b. if no errors are reported, your class is compiled. c. If errors are reported, return to the text editor and make corrections. 8. To run your compiled class, type java Params and press Enter. The output should be: Number of comand line arguments provided 9. Now type java Params followd by your first and last name, CM111 FALL-2017, e.g: Java parms John Smith CM111 FALL-2017Explanation / Answer
Params.java
public class Params
{
public static void main (String[] args)
{
int numArgs = args.length;
System.out.println("Number of command line arguments provided "+ numArgs);
if(numArgs > 0)
{
System.out.println("The command line arguments are : ");
for(String item : args)
{
System.out.printf("Argument is %s%n",item);
}
}
}
}
8. java Params
Output:
Number of command line arguments provided 0
9. java Params John Smith CM111 Fall 2017
Output:
Number of command line arguments provided 5
The command line arguments are :
Argument is John
Argument is Smith
Argument is CM111
Argument is Fall
Argument is 2017
The Params program in java is displaying the count of command line arguments and then using for loop and printf() function %s is displaying the command line arguments as strings on seperate lines as %n is new line character.
Do ask if any doubt. Please upvote.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.