Anatt Arbin
06
• Know and explain what a command-line
argument is
• Get input from the user using command-line
argument
• How to pass command-line arguments in
Command prompt
Objective
s
• Command line arguments means a way to pass parameters
to the main function while executing the program.
• A Java application can accept any number of arguments
from the command-line.
• Command-line arguments allow the user to affect the
operation of an application.
• The user enters command-line arguments when invoking
the application and specifies them after the name of the
class to run.
Command-line
Arguments
• In Java, when you invoke an application, the
runtime system passes the command-line
arguments to the application's main method via
an array of Strings.
public static void main( String [] args)
• Each String in the array contains one of the
command-line arguments.
How Java Application Receive Command-line
Arguments
args[ ] array
} }
This keyword is a reference variable that
refers the current object in java. This
keyword can be used for call current class
constructor.
This keyword in
java
What is this Keyword
this is a keyword in Java. Which can be used inside
method or constructor of class.
It(this) works as a reference to current object whose
method or constructor is being invoked. this keyword
can be used to refer any member of current object from
within an instance method or a constructor.
public class Main {
int x;
// Constructor with a parameter
public Main(int x) {
this.x = x;
}
// Call the constructor
public static void main(String[] args) {
Main myObj = new Main(5);
System.out.println("Value of x = " + myObj.x);
}}
Example Using this with a class attribute
(x):
Thank
you

Command line arguments & This keyword.pptx

  • 1.
  • 2.
    • Know andexplain what a command-line argument is • Get input from the user using command-line argument • How to pass command-line arguments in Command prompt Objective s
  • 3.
    • Command linearguments means a way to pass parameters to the main function while executing the program. • A Java application can accept any number of arguments from the command-line. • Command-line arguments allow the user to affect the operation of an application. • The user enters command-line arguments when invoking the application and specifies them after the name of the class to run. Command-line Arguments
  • 5.
    • In Java,when you invoke an application, the runtime system passes the command-line arguments to the application's main method via an array of Strings. public static void main( String [] args) • Each String in the array contains one of the command-line arguments. How Java Application Receive Command-line Arguments
  • 6.
  • 7.
  • 10.
    This keyword isa reference variable that refers the current object in java. This keyword can be used for call current class constructor. This keyword in java
  • 11.
    What is thisKeyword this is a keyword in Java. Which can be used inside method or constructor of class. It(this) works as a reference to current object whose method or constructor is being invoked. this keyword can be used to refer any member of current object from within an instance method or a constructor.
  • 12.
    public class Main{ int x; // Constructor with a parameter public Main(int x) { this.x = x; } // Call the constructor public static void main(String[] args) { Main myObj = new Main(5); System.out.println("Value of x = " + myObj.x); }} Example Using this with a class attribute (x):
  • 13.