Java statements


(Tap the post to see more)


Java Statements

        Statements are similar to sentences in the English language.
        A Java statement is just an instruction that explains what should happen.

Types of Java Statements

Java supports three different types of statements:

        Expression statements:    
        change values of variables, call methods and create objects.

        Declaration statements :
        To declare variables.

        Control-flow statements:
            To determine the order that which statements are executed. 
1.   Selection statement (if, if else, switch)
2.   Iteration Statement (for, while, do-while)
3.   Jump Statement (break, continue, return)


 

Command-line Argument


Meaning:

  • A command-line argument is nothing but the information that we pass after typing the name of the Java program during the program execution. 
  • The command requires no arguments. 
  • The code illustrates that args length gives us the number of command line arguments. 
  • If we neglected to check the args length, the command would crash if the user ran it with too few command-line arguments.
  • A command-line argument is information that directly follows the program's name 
  • on the command line when it is executed. 
  • Accessing the command-line arguments inside a Java program is quite easy. 
  • They are stored as strings in the String array passed to main ( ). 


Program

class command
{
public static void main(String a[])
{
System.out.println("Welcome to java programming");
}
}


Output:

Welcome to java programming


First Java program:

Let's write our first Java program:


Program:

class command  

{

public static void main(String args[])

{

System.out.println("Welcome to java programming");

}

}


Explanation:

First, we have created a class (as Java is a general purpose oops language) our program should be within a class and we have created a class named "command".

Next, is our public static void main(String args[]): the reason we are using this, is because our main() method is the execution point of our program.

The "System.out.println" is the standard output statement - that we can use to print our output.


Output:

Welcome to Java programming


← Back Next →

Comments

Popular posts from this blog

Wrapper Class

Information Security & Essential Terminology

Information Security Threat Categories