Java Programing laungage

Core Java Tutorial

Introduction of Core Java

How To Install JDk and Set of Path

Syntax of java Program

Difference between Java and C/C++

Advantage and Disadvantage of Java

What is Java

Why Java is not Pure Object Oriented Language

Java has Following Features/Characteristics

Limitation of Java Language and Java Internet

Common Misconception about Java

Simple Program of Java

Integrated Development Environment in java

Compile and Run Java Program

Applet and Comments in Java

Tokens in Java

Keywords in Java

Identifier and Variables in Java

Literals/Constants

Data Type in Java

Assignments and Initialization in Java

Operators in Java

Rule of Precedence in Java

Operator on Integer and Separators in Java Programming

Java Control Flow of Statements

If and If-else Selection Statement

Nested If-else and If-else-If Selection Statement

switch case and conditional operator Selection Statement

for and while Loop

do..while and for each Loop

break and labeled break statement

continue and labeled continue statement

return Statement and exit() Method

Escape Sequence for Special Characters and Unicode Code

Constants and Block or Scope

Statement in Java

Conversions between Numeric Types in Java

Import Statement in Java

User Input in Java using Scanner Class

User Input in Java using Console Class

Array in Java

One Dimensional Array

Two Dimensional Array

Two Dimensional Array Program

Command Line Argument in Java

String args Types in Java

Uneven/Jagged array in java

Math Class Function and Constant

Math Class all Function used in a program

Enumerated Types in Java

Object Oriented Programming v/s Procedural Programming

Object Oriented Programming Concepts in Java

Introduction to Class,Object and Method in Java

Class Declaration in Java

Class & Objects in java

Encapsulation in Java

Modifiers/Visibility for a Class or Interrface or member of a Class

Polymorphism in Java

Runtime polymorphism (dynamic binding or method overriding)

Control Flow In Java
Previous Home Next

Java supports both conditional statements and loops to determine control flow just like C and C++. First we deal with the conditional statements and then move on to loops. In end we discuss the somewhat cumbersome switch statement that we can use when we have to test for many values of a single expression.

Block Scope

A block or compound statement is any number of simple Java statements that are surrounded by a pair of braces. Blocks define the scope of your variables and can be nested inside one another. Here is a block that is nested inside the block of the main method.

Example


public static void main(String[] args)
{
int p;
. . .
{
int q;
. . .
} // q's scope is upto here
}

It is not possible to declare same named variables in two nested blocks.

Conditional Statement

he conditional statement in Java has the form if (condition) statement, just like in C and C++. In Java you will often execute multiple statements when a single condition is true. For this you use a block statement that takes the form.

Example


{
statement1;
statement2;
. . .
}
For instance,
   if (num >= 10)
     {
       System.out.println("The value of num is :"+num);
     }

In above example the statements surrounded by the braces will be executed when num is greater than or equal to 10.

 

if-else Statement

Java, like C and C++ also has if-else conditional statements which takes the form

Example


(condition is true)
     {
//will execute statements if condition is true otherwise control passes to else block
   statment1;
    statement2;
      }
  else
     {
 // will execute if condition is false
    statement3;
     }

if-else-if Statement

Java uses this statement for the execution of the multiple alternatives and is quite common,

Example


f (totalmarks >= 400)
{
Grade = "A";
result = "Excellent";
}
else if(totalmarks>=300)
{
Grade = "B";
result = "Good";
}
else if (totalmarks>=200)
{
Grade = "C";
result = "Average";
}
else
{
System.out.println("Failed");
}

Previous Home Next