Assignment: Module 02 - Part 01
01. Compile and run the code from the command line using the javac and java command.Java Fundamentals Module 02 - Part 01
Output: “Grazitti Skillstone Welcomes You All to Java Learning”.
Here is an example of a Java program that takes an argument from the command line and outputs the message "Grazitti Skillstone Welcomes You All to Java Learning":
public class FirstArgumentProgram { public static void main(String[] args) { if (args.length > 0) { System.out.println("Grazitti Skillstone Welcomes You All to " + args[0]); } else { System.out.println("No argument passed!"); } } }
To compile and run the code from the command line using the javac and java command, you would use the following steps:
- Open the command prompt and navigate to the directory where the "FirstArgumentProgram.java" file is located.
- Use the command "javac FirstArgumentProgram.java" to compile the code. This will create a new file called "FirstArgumentProgram.class" in the same directory.
- Use the command "java FirstArgumentProgram Java Learning" to run the program. The argument "Java Learning" will be passed to the program as the first argument, and the program will output "Grazitti Skillstone Welcomes You All to Java Learning".
Note: Before you run the above commands, you need to make sure that the path of JDK is added to the system's environmental variables.