person/developer => Java code => compiler (Javac) => byte code => jvm (built different for each machines) => os ==> hw
- executes only public static void main (
String a[])
- java is an oject oriented programming language
- object oriented programming languages means everything is an object
class Hello {
public static void main(String a[]){
system.out.println("Hello world!");
}
}- jvm is part of jre(java runtime environment)
-
java is platform independent bcz of jvm , the other machine need only jvm and jre and no need for
JDKto execute java code. -
jdk is needed by developer for development and jdk brings new/updated jre and jvm
System.out.println() // ==> moves control to next lineIn Java, String[] args is a parameter in the main method declaration. It is an array of strings that allows you to pass command-line arguments to your Java program when you run it from the command line. Let's break it down in detail:
String[]: This denotes thatargsis an array of strings. It means that you can store multiple strings in theargsarray.args: This is just a variable name. You can name it whatever you like, butargsis a conventional name used in Java programs. It stands for "arguments".
The String[] args parameter allows you to pass information to your Java program from the command line when you execute the program. This can be useful for various purposes, such as:
-
Configuration: You can pass configuration parameters to your program at runtime, such as file paths, database connection details, or other settings.
-
Customization: It allows users to customize the behavior of your program by providing arguments when they run it.
-
Input: You can pass input data to your program from the command line, which your program can then process.
-
Testing: It facilitates testing your program with different inputs without modifying the source code.
Here's a simple example demonstrating how to use String[] args in a Java program:
public class CommandLineArgumentsExample {
public static void main(String[] args) {
// Printing all the command-line arguments passed to the program
for (String arg : args) {
System.out.println(arg);
}
}
}- if you compile and run this program from the command line like this:
java CommandLineArgumentsExample arg1 arg2 arg3
- it will output:
arg1
arg2
arg3
- In summary, String[] args in Java is a mechanism to pass command-line arguments to your program. While not strictly necessary for all programs, it is a convenient and powerful feature that allows your Java applications to be more flexible and customizable based on user input or configuration parameters provided at runtime.