hereral/Clara-Training-Data huggingface dataset:
Question: What is Java if-else Statement?
Answer: The Java if-else statement also tests the condition. It executes the if block if condition is true otherwise else block is executed.

Syntax:

if(condition){  
//code if condition is true  
}else{  
//code if condition is false  
}  
Example:

//A Java Program to demonstrate the use of if-else statement.  
//It is a program of odd and even number.  
public class IfElseExample {  
public static void main(String[] args) {  
    //defining a variable  
    int number=13;  
    //Check if the number is divisible by 2 or not  
    if(number%2==0){  
        System.out.println("even number");  
    }else{  
        System.out.println("odd number");  
    }  
}  
}  
Output:
odd number
Question: How to use Ternary Operator in Java?
Answer: We can also use ternary operator (? :) to perform the task of if...else statement. It is a shorthand way to check the condition. If the condition is true, the result of ? is returned. But, if the condition is false, the result of : is returned.
Example:
public class IfElseTernaryExample {    
public static void main(String[] args) {    
    int number=13;    
    //Using ternary operator  
    String output=(number%2==0)?"even number":"odd number";    
    System.out.println(output);  
}    
}    
Output:
odd number
Question: What is Java if-else-if ladder Statement?
Answer: The if-else-if ladder statement executes one condition from multiple statements.
Syntax:
if(condition1){  
//code to be executed if condition1 is true  
}else if(condition2){  
//code to be executed if condition2 is true  
}  
else if(condition3){  
//code to be executed if condition3 is true  
}  
...  
else{  
//code to be executed if all the conditions are false  
}  
Example:
//Java Program to demonstrate the use of If else-if ladder.  
//It is a program of grading system for fail, D grade, C grade, B grade, A grade and A+.  
public class IfElseIfExample {  
public static void main(String[] args) {  
    int marks=65;  
      
    if(marks<50){  
        System.out.println("fail");  
    }  
    else if(marks>=50 && marks<60){  
        System.out.println("D grade");  
    }  
    else if(marks>=60 && marks<70){  
        System.out.println("C grade");  
    }  
    else if(marks>=70 && marks<80){  
        System.out.println("B grade");  
    }  
    else if(marks>=80 && marks<90){  
        System.out.println("A grade");  
    }else if(marks>=90 && marks<100){  
        System.out.println("A+ grade");  
    }else{  
        System.out.println("Invalid!");  
    }  
}  
}  
Output:
C grade
Question: What is Java Nested if statement?
Answer: The nested if statement represents the if block within another if block. Here, the inner if block condition executes only when outer if block condition is true.
Syntax:

if(condition){    
     //code to be executed    
          if(condition){  
             //code to be executed    
    }    
}  
Example:

//Java Program to demonstrate the use of Nested If Statement.  
public class JavaNestedIfExample {    
public static void main(String[] args) {    
    //Creating two variables for age and weight  
    int age=20;  
    int weight=80;    
    //applying condition on age and weight  
    if(age>=18){    
        if(weight>50){  
            System.out.println("You are eligible to donate blood");  
        }    
    }    
}}  
Output:
You are eligible to donate blood
Question: What is Java Switch Statement?
Answer: The Java switch statement executes one statement from multiple conditions. It is like if-else-if ladder statement. The switch statement works with byte, short, int, long, enum types, String and some wrapper types like Byte, Short, Int, and Long. Since Java 7, you can use strings in the switch statement.

In other words, the switch statement tests the equality of a variable against multiple values.
Question: Can you provide an example of Switch Example in java?
Answer: SwitchExample.java

public class SwitchExample {  
public static void main(String[] args) {  
    //Declaring a variable for switch expression  
    int number=20;  
    //Switch expression  
    switch(number){  
    //Case statements  
    case 10: System.out.println("10");  
    break;  
    case 20: System.out.println("20");  
    break;  
    case 30: System.out.println("30");  
    break;  
    //Default case statement  
    default:System.out.println("Not in 10, 20 or 30");  
    }  
}  
}  
Output:
20
Question: Can you provide an example of Switch Month Example in java?
Answer: //Java Program to demonstrate the example of Switch statement  
//where we are printing month name for the given number  
public class SwitchMonthExample {    
public static void main(String[] args) {    
    //Specifying month number  
    int month=7;    
    String monthString="";  
    //Switch statement  
    switch(month){    
    //case statements within the switch block  
    case 1: monthString="1 - January";  
    break;    
    case 2: monthString="2 - February";  
    break;    
    case 3: monthString="3 - March";  
    break;    
    case 4: monthString="4 - April";  
    break;    
    case 5: monthString="5 - May";  
    break;    
    case 6: monthString="6 - June";  
    break;    
    case 7: monthString="7 - July";  
    break;    
    case 8: monthString="8 - August";  
    break;    
    case 9: monthString="9 - September";  
    break;    
    case 10: monthString="10 - October";  
    break;    
    case 11: monthString="11 - November";  
    break;    
    case 12: monthString="12 - December";  
    break;    
    default:System.out.println("Invalid Month!");    
    }    
    //Printing month of the given number  
    System.out.println(monthString);  
}    
}   
Output:
7 - July
Question: Can you provide an example of Switch Vowel Example in java?
Answer: SwitchVowelExample.java

public class SwitchVowelExample {    
public static void main(String[] args) {    
    char ch='O';    
    switch(ch)  
    {  
        case 'a':   
            System.out.println("Vowel");  
            break;  
        case 'e':   
            System.out.println("Vowel");  
            break;  
        case 'i':   
            System.out.println("Vowel");  
            break;  
        case 'o':   
            System.out.println("Vowel");  
            break;  
        case 'u':   
            System.out.println("Vowel");  
            break;  
        case 'A':   
            System.out.println("Vowel");  
            break;  
        case 'E':   
            System.out.println("Vowel");  
            break;  
        case 'I':   
            System.out.println("Vowel");  
            break;  
        case 'O':   
            System.out.println("Vowel");  
            break;  
        case 'U':   
            System.out.println("Vowel");  
            break;  
        default:   
            System.out.println("Consonant");  
    }  
}    
}   
Output:

Vowel
Question: Is Java Switch Statement is fall-through?
Answer: Java Switch Statement is fall-through
The Java switch statement is fall-through. It means it executes all statements after the first match if a break statement is not present.
Question: Can you provide an example of Java Switch Statement with String?
Answer: Example:

SwitchExample2.java
//Java Switch Example where we are omitting the  
//break statement  
public class SwitchExample2 {  
public static void main(String[] args) {  
    int number=20;  
    //switch expression with int value  
    switch(number){  
    //switch cases without break statements  
    case 10: System.out.println("10");  
    case 20: System.out.println("20");  
    case 30: System.out.println("30");  
    default:System.out.println("Not in 10, 20 or 30");  
    }  
}  
}  
Output:
20
30
Not in 10, 20 or 30
Question: What is Java Nested Switch Statement?
Answer: We can use switch statement inside other switch statement in Java. It is known as nested switch statement.

Example:

NestedSwitchExample.java

//Java Program to demonstrate the use of Java Nested Switch  
public class NestedSwitchExample {    
    public static void main(String args[])  
      {  
      //C - CSE, E - ECE, M - Mechanical  
        char branch = 'C';                 
        int collegeYear = 4;  
        switch( collegeYear )  
        {  
            case 1:  
                System.out.println("English, Maths, Science");  
                break;  
            case 2:  
                switch( branch )   
                {  
                    case 'C':  
                        System.out.println("Operating System, Java, Data Structure");  
                        break;  
                    case 'E':  
                        System.out.println("Micro processors, Logic switching theory");  
                        break;  
                    case 'M':  
                        System.out.println("Drawing, Manufacturing Machines");  
                        break;  
                }  
                break;  
            case 3:  
                switch( branch )   
                {  
                    case 'C':  
                        System.out.println("Computer Organization, MultiMedia");  
                        break;  
                    case 'E':  
                        System.out.println("Fundamentals of Logic Design, Microelectronics");  
                        break;  
                    case 'M':  
                        System.out.println("Internal Combustion Engines, Mechanical Vibration");  
                        break;  
                }  
                break;  
            case 4:  
                switch( branch )   
                {  
                    case 'C':  
                        System.out.println("Data Communication and Networks, MultiMedia");  
                        break;  
                    case 'E':  
                        System.out.println("Embedded System, Image Processing");  
                        break;  
                    case 'M':  
                        System.out.println("Production Technology, Thermal Engineering");  
                        break;  
                }  
                break;  
        }  
    }  
}  
Output:

Data Communication and Networks, MultiMedia
Question: What is Java Enum in Switch Statement?
Answer: Java allows us to use enum in switch statement. Java enum is a class that represent the group of constants. (immutable such as final variables). We use the keyword enum and put the constants in curly braces separated by comma.

Example:

JavaSwitchEnumExample.java

//Java Program to demonstrate the use of Enum  
//in switch statement  
public class JavaSwitchEnumExample {      
       public enum Day {  Sun, Mon, Tue, Wed, Thu, Fri, Sat  }    
       public static void main(String args[])    
       {    
         Day[] DayNow = Day.values();    
           for (Day Now : DayNow)    
           {    
                switch (Now)    
                {    
                    case Sun:    
                        System.out.println("Sunday");    
                        break;    
                    case Mon:    
                        System.out.println("Monday");    
                        break;    
                    case Tue:    
                        System.out.println("Tuesday");    
                        break;         
                    case Wed:    
                        System.out.println("Wednesday");    
                        break;    
                    case Thu:    
                        System.out.println("Thursday");    
                        break;    
                    case Fri:    
                        System.out.println("Friday");    
                        break;    
                    case Sat:    
                        System.out.println("Saturday");    
                        break;    
                }    
            }    
        }    
}    
Output:

Sunday
Monday
Twesday
Wednesday
Thursday
Friday
Saturday
Question: What is Java Wrapper in Switch Statement?
Answer: Java allows us to use four wrapper classes: Byte, Short, Integer and Long in switch statement.

Example:

WrapperInSwitchCaseExample.java

//Java Program to demonstrate the use of Wrapper class  
//in switch statement  
public class WrapperInSwitchCaseExample {       
       public static void main(String args[])  
       {         
            Integer age = 18;        
            switch (age)  
            {  
                case (16):            
                    System.out.println("You are under 18.");  
                    break;  
                case (18):                
                    System.out.println("You are eligible for vote.");  
                    break;  
                case (65):                
                    System.out.println("You are senior citizen.");  
                    break;  
                default:  
                    System.out.println("Please give the valid age.");  
                    break;  
            }             
        }  
}  
Output:

You are eligible for vote.
Question: What is Loops in Java?
Answer: The Java for loop is used to iterate a part of the program several times. If the number of iteration is fixed, it is recommended to use for loop.
There are three types of for loops in Java.

-Simple for Loop
-For-each or Enhanced for Loop
-Labeled for Loop
Question: Can you provide an example of Java Simple for Loop?
Answer: A simple for loop is the same as C/C++. We can initialize the variable, check condition and increment/decrement value. It consists of four parts:

Initialization: It is the initial condition which is executed once when the loop starts. Here, we can initialize the variable, or we can use an already initialized variable. It is an optional condition.
Condition: It is the second condition which is executed each time to test the condition of the loop. It continues execution until the condition is false. It must return boolean value either true or false. It is an optional condition.
Increment/Decrement: It increments or decrements the variable value. It is an optional condition.
Statement: The statement of the loop is executed each time until the second condition is false.


Syntax:

for(initialization; condition; increment/decrement){    
//statement or code to be executed    
}    

Example:

ForExample.java
//Java Program to demonstrate the example of for loop  
//which prints table of 1  
public class ForExample {  
public static void main(String[] args) {  
    //Code of Java for loop  
    for(int i=1;i<=10;i++){  
        System.out.println(i);  
    }  
}  
}  

Output:
1
2
3
4
5
6
7
8
9
10
Question: What is Java Nested for Loop?
Answer: If we have a for loop inside the another loop, it is known as nested for loop. The inner loop executes completely whenever outer loop executes.

Example:
NestedForExample.java
public class NestedForExample {  
public static void main(String[] args) {  
//loop of i  
for(int i=1;i<=3;i++){  
//loop of j  
for(int j=1;j<=3;j++){  
        System.out.println(i+" "+j);  
}//end of i  
}//end of j  
}  
} 

Output:
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

Pyramid Example 1:
PyramidExample.java
public class PyramidExample {  
public static void main(String[] args) {  
for(int i=1;i<=5;i++){  
for(int j=1;j<=i;j++){  
        System.out.print("* ");  
}  
System.out.println();//new line  
}  
}  
} 

Output:
* 
* * 
* * * 
* * * * 
* * * * *

Pyramid Example 2:
PyramidExample2.java
public class PyramidExample2 {  
public static void main(String[] args) {  
int term=6;  
for(int i=1;i<=term;i++){  
for(int j=term;j>=i;j--){  
        System.out.print("* ");  
}  
System.out.println();//new line  
}  
}  
}  

Output:
* * * * * * 
* * * * * 
* * * * 
* * * 
* * 
*
Question: What is Java for-each Loop?

Answer: The for-each loop is used to traverse array or collection in Java. It is easier to use than simple for loop because we don't need to increment value and use subscript notation.

It works on the basis of elements and not the index. It returns element one by one in the defined variable.

Syntax:

for(data_type variable : array_name){    
//code to be executed    
}   

Example:

ForEachExample.java


//Java For-each loop example which prints the  
//elements of the array  
public class ForEachExample {  
public static void main(String[] args) {  
    //Declaring an array  
    int arr[]={12,23,44,56,78};  
    //Printing array using for-each loop  
    for(int i:arr){  
        System.out.println(i);  
    }  
}  
}  

Output:

12
23
44
56
78
Question: What is Java Labeled For Loop?
Answer: We can have a name of each Java for loop. To do so, we use label before the for loop. It is useful while using the nested for loop as we can break/continue specific for loop.

Syntax:

labelname:    
for(initialization; condition; increment/decrement){    
//code to be executed    
}    

Example:
LabeledForExample.java
//A Java program to demonstrate the use of labeled for loop  
public class LabeledForExample {  
public static void main(String[] args) {  
    //Using Label for outer and for loop  
    aa:  
        for(int i=1;i<=3;i++){  
            bb:  
                for(int j=1;j<=3;j++){  
                    if(i==2&&j==2){  
                        break aa;  
                    }  
                    System.out.println(i+" "+j);  
                }  
        }  
}  
}  

Output:
1 1
1 2
1 3
2 1


If you use break bb;, it will break inner loop only which is the default behaviour of any loop.


LabeledForExample2.java

public class LabeledForExample2 {  
public static void main(String[] args) {  
    aa:  
        for(int i=1;i<=3;i++){  
            bb:  
                for(int j=1;j<=3;j++){  
                    if(i==2&&j==2){  
                        break bb;  
                    }  
                    System.out.println(i+" "+j);  
                }  
        }  
}  
}

Output:

1 1
1 2
1 3
2 1
3 1
3 2
3 3
Question: What is Java Infinitive for Loop?
Answer: If you use two semicolons ;; in the for loop, it will be infinitive for loop.

Syntax:

for(;;){  
//code to be executed  
}  


Example:

ForExample.java

//Java program to demonstrate the use of infinite for loop  
//which prints an statement  
public class ForExample {  
public static void main(String[] args) {  
    //Using no condition in for loop  
    for(;;){  
        System.out.println("infinitive loop");  
    }  
}  
}  

Output:

infinitive loop
infinitive loop
infinitive loop
infinitive loop
infinitive loop
ctrl+c
Question: Can you explain the differences between the Java for loop, while loop, and do-while loop?
Answer: Java for Loop vs while Loop vs do-while Loop

For loop
Introduction : The Java for loop is a control flow statement that iterates a part of the programs multiple times.
When to use : If the number of iteration is fixed, it is recommended to use for loop.
Syntax: for(init;condition;incr/decr){
// code to be executed
}
Example : //for loop
for(int i=1;i<=10;i++){
System.out.println(i);
}
Syntax for infinitive loop : for(;;){
//code to be executed
}

while loop
Introduction : The Java while loop is a control flow statement that executes a part of the programs repeatedly on the basis of given boolean condition.
When to use : If the number of iteration is not fixed, it is recommended to use while loop.        
Syntax: while(condition){
//code to be executed
}
Example : //while loop
int i=1;
while(i<=10){
System.out.println(i);
i++;
}
Syntax for infinitive loop : while(true){
//code to be executed
}

do-while loop
Introduction : The Java do while loop is a control flow statement that executes a part of the programs at least once and the further execution depends upon the given boolean condition.
When to use : If the number of iteration is not fixed and you must have to execute the loop at least once, it is recommended to use the do-while loop.
Syntax: do{
//code to be executed
}while(condition);
Example : //do-while loop
int i=1;
do{
System.out.println(i);
i++;
}while(i<=10);
Syntax for infinitive loop : do{
//code to be executed
}while(true);
Question: What is Java While Loop?
Answer: The Java while loop is used to iterate a part of the program repeatedly until the specified Boolean condition is true. As soon as the Boolean condition becomes false, the loop automatically stops.

The while loop is considered as a repeating if statement. If the number of iteration is not fixed, it is recommended to use the while loop.

Syntax:

while (condition){    
//code to be executed   
I ncrement / decrement statement  
}    
The different parts of do-while loop:
1. Condition: It is an expression which is tested. If the condition is true, the loop body is executed and control goes to update expression. When the condition becomes false, we exit the while loop.
Example:
i <=100
2. Update expression: Every time the loop body is executed, this expression increments or decrements loop variable.
Example:
i++;
Question: What is Java Infinitive While Loop?
Answer: If you pass true in the while loop, it will be infinitive while loop.

Syntax:

while(true){  
//code to be executed  
}  
Example:

WhileExample2.java

public class WhileExample2 {    
public static void main(String[] args) {   
 // setting the infinite while loop by passing true to the condition  
    while(true){    
        System.out.println("infinitive while loop");    
    }    
}    
}    
Output:

infinitive while loop
infinitive while loop
infinitive while loop
infinitive while loop
infinitive while loop
ctrl+c
Question: What is Java do-while loop?

Answer: The Java do-while loop is used to iterate a part of the program repeatedly, until the specified condition is true. If the number of iteration is not fixed and you must have to execute the loop at least once, it is recommended to use a do-while loop.

Java do-while loop is called an exit control loop. Therefore, unlike while loop and for loop, the do-while check the condition at the end of loop body. The Java do-while loop is executed at least once because condition is checked after loop body.

Syntax:

do{    
//code to be executed / loop body  
//update statement   
}while (condition);    
The different parts of do-while loop:
1. Condition: It is an expression which is tested. If the condition is true, the loop body is executed and control goes to update expression. As soon as the condition becomes false, loop breaks automatically.
Example:
i <=100
2. Update expression: Every time the loop body is executed, the this expression increments or decrements loop variable.
Example:
i++;
Question: What is Java Infinitive do-while Loop?
Answer: If you pass true in the do-while loop, it will be infinitive do-while loop.

Syntax:

do{  
//code to be executed  
}while(true);  
Example:

DoWhileExample2.java

public class DoWhileExample2 {  
public static void main(String[] args) {  
    do{  
        System.out.println("infinitive do while loop");  
    }while(true);  
}  
}  
Output:

infinitive do while loop
infinitive do while loop
infinitive do while loop
ctrl+c
Question: What is Java Break Statement?
Answer: When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.

The Java break statement is used to break loop or switch statement. It breaks the current flow of the program at specified condition. In case of inner loop, it breaks only inner loop.

We can use Java break statement in all types of loops such as for loop, while loop and do-while loop.

Syntax:

jump-statement;    
break;
Question: Can you provide an example of Java Break Statement with Loop?
Answer: Example:

BreakExample.java

//Java Program to demonstrate the use of break statement    
//inside the for loop.  
public class BreakExample {  
public static void main(String[] args) {  
    //using for loop  
    for(int i=1;i<=10;i++){  
        if(i==5){  
            //breaking the loop  
            break;  
        }  
        System.out.println(i);  
    }  
}  
}  
Output:

1
2
3
4
Question: What is Java Break Statement with Inner Loop?
Answer: It breaks inner loop only if you use break statement inside the inner loop.

Example:
BreakExample2.java

//Java Program to illustrate the use of break statement    
//inside an inner loop   
public class BreakExample2 {  
public static void main(String[] args) {  
            //outer loop   
            for(int i=1;i<=3;i++){    
                    //inner loop  
                    for(int j=1;j<=3;j++){    
                        if(i==2&&j==2){    
                            //using break statement inside the inner loop  
                            break;    
                        }    
                        System.out.println(i+" "+j);    
                    }    
            }    
}  
}  
Output:

1 1
1 2
1 3
2 1
3 1
3 2
3 3
Question: Can you provide an example of Java Break Statement with Labeled For Loop?
Answer: We can use break statement with a label. The feature is introduced since JDK 1.5. So, we can break any loop in Java now whether it is outer or inner loop.

Example:

BreakExample3.java

//Java Program to illustrate the use of continue statement  
//with label inside an inner loop to break outer loop  
public class BreakExample3 {  
public static void main(String[] args) {  
            aa:  
            for(int i=1;i<=3;i++){    
                    bb:  
                    for(int j=1;j<=3;j++){    
                        if(i==2&&j==2){    
                            //using break statement with label  
                            break aa;    
                        }    
                        System.out.println(i+" "+j);    
                    }    
            }    
}  
}  
Output:

1 1
1 2
1 3
2 1
Question: Can you provide an example of Java Break Statement in while loop?
Answer: BreakWhileExample.java

//Java Program to demonstrate the use of break statement  
//inside the while loop.  
public class BreakWhileExample {  
public static void main(String[] args) {  
    //while loop  
    int i=1;  
    while(i<=10){  
        if(i==5){  
            //using break statement  
            i++;  
            break;//it will break the loop  
        }  
        System.out.println(i);  
        i++;  
    }  
}  
}  
Output:

1
2
3
4
Question: Can you provide an example of Java Break Statement in do-while loop?
Answer: BreakDoWhileExample.java

//Java Program to demonstrate the use of break statement  
//inside the Java do-while loop.  
public class BreakDoWhileExample {  
public static void main(String[] args) {  
    //declaring variable  
    int i=1;  
    //do-while loop  
    do{  
        if(i==5){  
           //using break statement  
           i++;  
           break;//it will break the loop  
        }  
        System.out.println(i);  
        i++;  
    }while(i<=10);  
}  
}  
Output:

1
2
3
4
Question: What is Java Continue Statement?
Answer: The continue statement is used in loop control structure when you need to jump to the next iteration of the loop immediately. It can be used with for loop or while loop.

The Java continue statement is used to continue the loop. It continues the current flow of the program and skips the remaining code at the specified condition. In case of an inner loop, it continues the inner loop only.

We can use Java continue statement in all types of loops such as for loop, while loop and do-while loop.

Syntax:
jump-statement;    
continue;
Question: Can you provide an example of Java Continue Statement Example?
Answer: ContinueExample.java

//Java Program to demonstrate the use of continue statement  
//inside the for loop.  
public class ContinueExample {  
public static void main(String[] args) {  
    //for loop  
    for(int i=1;i<=10;i++){  
        if(i==5){  
            //using continue statement  
            continue;//it will skip the rest statement  
        }  
        System.out.println(i);  
    }  
}  
}  
Output:

1
2
3
4
6
7
8
9
10
Question: Can you provide an example of Java Continue Statement with Inner Loop?
Answer: It continues inner loop only if you use the continue statement inside the inner loop.
ContinueExample2.java

//Java Program to illustrate the use of continue statement  
//inside an inner loop  
public class ContinueExample2 {  
public static void main(String[] args) {  
            //outer loop  
            for(int i=1;i<=3;i++){    
                    //inner loop  
                    for(int j=1;j<=3;j++){    
                        if(i==2&&j==2){    
                            //using continue statement inside inner loop  
                            continue;    
                        }    
                        System.out.println(i+" "+j);    
                    }    
            }    
}  
}  
Output:

1 1
1 2
1 3
2 1
2 3
3 1
3 2
3 3
Question: Can you provide an example of Java Continue Statement with Labelled For Loop?
Answer: We can use continue statement with a label. This feature is introduced since JDK 1.5. So, we can continue any loop in Java now whether it is outer loop or inner.

Example:

ContinueExample3.java

//Java Program to illustrate the use of continue statement  
//with label inside an inner loop to continue outer loop  
public class ContinueExample3 {  
public static void main(String[] args) {  
            aa:  
            for(int i=1;i<=3;i++){    
                    bb:  
                    for(int j=1;j<=3;j++){    
                        if(i==2&&j==2){    
                            //using continue statement with label  
                            continue aa;    
                        }    
                        System.out.println(i+" "+j);    
                    }    
            }    
}  
}  
Output:

1 1
1 2
1 3
2 1
3 1
3 2
3 3
Question: Can you provide an example of Java Continue Statement in while loop?
Answer: ContinueWhileExample.java

//Java Program to demonstrate the use of continue statement  
//inside the while loop.  
public class ContinueWhileExample {  
public static void main(String[] args) {  
    //while loop  
    int i=1;  
    while(i<=10){  
        if(i==5){  
            //using continue statement  
            i++;  
            continue;//it will skip the rest statement  
        }  
        System.out.println(i);  
        i++;  
    }  
}  
}  
Output:

1
2
3
4
6
7
8
9
10
Question: Can you provide an example of Java Continue Statement in do-while Loop?
Answer: ContinueDoWhileExample.java

//Java Program to demonstrate the use of continue statement  
//inside the Java do-while loop.  
public class ContinueDoWhileExample {  
public static void main(String[] args) {  
    //declaring variable  
    int i=1;  
    //do-while loop  
    do{  
        if(i==5){  
                //using continue statement  
                 i++;  
            continue;//it will skip the rest statement  
        }  
        System.out.println(i);  
        i++;  
    }while(i<=10);  
}  
}  
Output:

1
2
3
4
6
7
8
9
10
Question: What is Java Comments?
Answer: The Java comments are the statements in a program that are not executed by the compiler and interpreter.
Question: Why do we use comments in a code?
Answer: -Comments are used to make the program more readable by adding the details of the code.
-It makes easy to maintain the code and to find the errors easily.
-The comments can be used to provide information or explanation about the variable, method, class, or any statement.
-It can also be used to prevent the execution of program code while testing the alternative code.
Question: What are the Types of Java Comments?
Answer: There are three types of comments in Java.

1) Single Line Comment
2 ) Multi Line Comment
3) Documentation Comment
Question: What is Java Single Line Comment?
Answer: The single-line comment is used to comment only one line of the code. It is the widely used and easiest way of commenting the statements.

Single line comments starts with two forward slashes (//). Any text in front of // is not executed by Java.

Syntax:

//This is single line comment  

Let's use single line comment in a Java program.

CommentExample1.java
public class CommentExample1 {    
public static void main(String[] args) {    
int i=10; // i is a variable with value 10  
System.out.println(i);  //printing the variable i  
}    
}    

Output:
10
Question: What is Java Multi Line Comment?
Answer: The multi-line comment is used to comment multiple lines of code. It can be used to explain a complex code snippet or to comment multiple lines of code at a time (as it will be difficult to use single-line comments there).

Multi-line comments are placed between /* and */. Any text between /* and */ is not executed by Java.

Syntax:

/*  
This   
is   
multi line   
comment  
*/    

Let's use multi-line comment in a Java program.

CommentExample2.java

public class CommentExample2 {    
public static void main(String[] args) {    
/* Let's declare and  
 print variable in java. */    
  int i=10;    
    System.out.println(i);    
/* float j = 5.9; 
    float k = 4.4; 
    System.out.println( j + k ); */    
}    
}    

Output:
10
Question: What is Java Documentation Comment?
Answer: Documentation comments are usually used to write large programs for a project or software application as it helps to create documentation API. These APIs are needed for reference, i.e., which classes, methods, arguments, etc., are used in the code.

To create documentation API, we need to use the javadoc tool. The documentation comments are placed between /** and */.

Syntax:

/**  
* 
*We can use various tags to depict the parameter 
*or heading or author name 
*We can also use HTML tags   
* 
*/
Question: What is javadoc tags?
Answer: javadoc tags
Some of the commonly used tags in documentation comments:

Tag: {@docRoot}
Syntax: {@docRoot}
Description: to depict relative path to root directory of generated document from any page.

Tag: @author
Syntax: @author name - text
Description: To add the author of the class

Tag: @code
Syntax: {@code text}
Description: To show the text in code font without interpreting it as html markup or nested javadoc tag.

Tag: @version
Syntax: @version version-text
Description: To specify "Version" subheading and version-text when -version option is used.

Tag: @since
Syntax: @since release
Description: To add "Since" heading with since text to generated documentation.

Tag: @param	
Syntax: @param parameter-name description
Description: To add a parameter with given name and description to 'Parameters' section.

Tag: @return
Syntax: @return description
Description: Required for every method that returns something (except void)

Let's use the Javadoc tag in a Java program.

Calculate.java

import java.io.*;  
  
/** 
 * <h2> Calculation of numbers </h2> 
 * This program implements an application 
 * to perform operation such as addition of numbers  
 * and print the result  
 * <p> 
 * <b>Note:</b> Comments make the code readable and  
 * easy to understand. 
 *  
 * @author Anurati  
 * @version 16.0 
 * @since 2021-07-06 
 */  
   
 public class Calculate{  
    /** 
     * This method calculates the summation of two integers. 
     * @param input1 This is the first parameter to sum() method 
     * @param input2 This is the second parameter to the sum() method. 
     * @return int This returns the addition of input1 and input2 
     */  
    public int sum(int input1, int input2){  
        return input1 + input2;  
    }  
    /** 
    * This is the main method uses of sum() method. 
    * @param args Unused 
    * @see IOException  
    */    
    public static void main(String[] args) {  
        Calculate obj = new Calculate();  
        int result = obj.sum(40, 20);  
  
        System.out.println("Addition of numbers: " + result);  
    }    
 }   

Compile it by javac tool:

Create Document
Create documentation API by javadoc tool
Now, the HTML files are created for the Calculate class in the current directory, i.e., abcDemo. Open the HTML files, and we can see the explanation of Calculate class provided through the documentation comment.
Question: Are Java comments executable?
Answer: As we know, Java comments are not executed by the compiler or interpreter, however, before the lexical transformation of code in compiler, contents of the code are encoded into ASCII in order to make the processing easy.

Test.java

public class Test{  
    public static void main(String[] args) {  
        //the below comment will be executed  
// \u000d System.out.println("Java comment is executed!!");  
    }  
}  


The above code generate the output because the compiler parses the Unicode character \u000d as a new line before the lexical transformation, and thus the code is transformed as shown below:

Test.java

public class Test{  
    public static void main(String[] args) {  
        //the below comment will be executed  
//  
System.out.println("Java comment is executed!!");  
    }  
}  
Thus, the Unicode character shifts the print statement to next line and it is executed as a normal Java code.
Question: Can you provide a list of Java Programs | Java Programming Examples?
Answer: Java programs are frequently asked in the interview. These programs can be asked from control statements, array, string, oops etc. Java basic programs like fibonacci series, prime numbers, factorial numbers and palindrome numbers are frequently asked in the interviews and exams. All these programs are given with the maximum examples and output. If you are new to Java programming, we will recommend you to read our Java tutorial first. Let's see the list of Java programs.
-Java Basic Programs
-Java Number Programs
-Java Array Programs
-Java Matrix Programs
-Java String Programs
-Java Searching and Sorting Programs
-Java Conversion Programs
-Pattern programs
-Singly Linked List Programs
-Circular Linked List Programs
-Doubly Linked List Programs
-Tree Programs
Question: Can you provide a list of Java Basic Programs?
Answer: 1) Fibonacci Series in Java
2) Prime Number Program in Java
3) Palindrome Program in Java
4) Factorial Program in Java
5) Armstrong Number in Java
6) How to Generate Random Number in Java
7) How to Print Pattern in Java
8) How to Compare Two Objects in Java
9) How to Create Object in Java
10) How to Print ASCII Value in Java
Question: Can you provide a list of Java Number Programs?
Answer: 1) How to Reverse a Number in Java
2) Java Program to convert Number to Word
3) Automorphic Number Program in Java
4) Peterson Number in Java
5) Sunny Number in Java
6) Tech Number in Java
7) Fascinating Number in Java
8) Keith Number in Java
9) Neon Number in Java
10) Spy Number in Java
11) ATM program Java
12) Autobiographical Number in Java
13) Emirp Number in Java
14) Sphenic Number in Java
15) Buzz Number Java
16) Duck Number Java
17) Evil Number Java
18) ISBN Number Java
19) Krishnamurthy Number Java
20) Bouncy Number in Java
21) Mystery Number in Java
22) Smith Number in Java
23) Strontio Number in Java
24) Xylem and Phloem Number in Java
25) nth Prime Number Java
26) Java Program to Display Alternate Prime Numbers
27) Java Program to Find Square Root of a Number Without sqrt Method
28) Java Program to Swap Two Numbers Using Bitwise Operator
29) Java Program to Find GCD of Two Numbers
30) Java Program to Find Largest of Three Numbers
31) Java Program to Find Smallest of Three Numbers Using Ternary Operator
32) Java Program to Check if a Number is Positive or Negative
33) Java Program to Check if a Given Number is Perfect Square
34) Java Program to Display Even Numbers From 1 to 100
35) Java Program to Display Odd Numbers From 1 to 100
36) Java Program to Find Sum of Natural Numbers
Question: Can you provide a list of Java Array Programs?
Answer: 1) Java Program to copy all elements of one array into another array
2) Java Program to find the frequency of each element in the array
3) Java Program to left rotate the elements of an array
4) Java Program to print the duplicate elements of an array
5) Java Program to print the elements of an array
6) Java Program to print the elements of an array in reverse order
7) Java Program to print the elements of an array present on even position
8) Java Program to print the elements of an array present on odd position
9) Java Program to print the largest element in an array
10) Java Program to print the smallest element in an array
11) Java Program to print the number of elements present in an array
12) Java Program to print the sum of all the items of the array
13) Java Program to right rotate the elements of an array
14) Java Program to sort the elements of an array in ascending order
15) Java Program to sort the elements of an array in descending order
16) Java Program to Find 3rd Largest Number in an array
17) Java Program to Find 2nd Largest Number in an array
18) Java Program to Find Largest Number in an array
19) Java to Program Find 2nd Smallest Number in an array
20) Java Program to Find Smallest Number in an array
21) Java Program to Remove Duplicate Element in an array
22) Java Program to Print Odd and Even Numbers from an array
23) How to Sort an Array in Java
Question: Can you provided a list of Java Matrix Programs?
Answer: 1) Java Matrix Programs
2) Java Program to Add Two Matrices
3) Java Program to Multiply Two Matrices
4) Java Program to subtract the two matrices
5) Java Program to determine whether two matrices are equal
6) Java Program to display the lower triangular matrix
7) Java Program to display the upper triangular matrix
8) Java Program to find the frequency of odd & even numbers in the given matrix
9) Java Program to find the product of two matrices
10) Java Program to find the sum of each row and each column of a matrix
11) Java Program to find the transpose of a given matrix
12) Java Program to determine whether a given matrix is an identity matrix
13) Java Program to determine whether a given matrix is a sparse matrix
14) Java Program to Transpose matrix
Question: Can you provide a list of Java String Programs?
Answer: 1) Java Program to count the total number of characters in a string
2) Java Program to count the total number of characters in a string 2
3) Java Program to count the total number of punctuation characters exists in a String
4) Java Program to count the total number of vowels and consonants in a string
5) Java Program to determine whether two strings are the anagram
6) Java Program to divide a string in 'N' equal parts.
7) Java Program to find all subsets of a string
8) Java Program to find the longest repeating sequence in a string
9) Java Program to find all the permutations of a string
10) Java Program to remove all the white spaces from a string
11) Java Program to replace lower-case characters with upper-case and vice-versa
12) Java Program to replace the spaces of a string with a specific character
13) Java Program to determine whether a given string is palindrome
14) Java Program to determine whether one string is a rotation of another
15) Java Program to find maximum and minimum occurring character in a string
16) Java Program to find Reverse of the string
17) Java program to find the duplicate characters in a string
18) Java program to find the duplicate words in a string
19) Java Program to find the frequency of characters
20) Java Program to find the largest and smallest word in a string
21) Java Program to find the most repeated word in a text file
22) Java Program to find the number of the words in the given text file
23) Java Program to separate the Individual Characters from a String
24) Java Program to swap two string variables without using third or temp variable.
25) Java Program to print smallest and biggest possible palindrome word in a given string
26) Reverse String in Java Word by Word
27) Reserve String without reverse() function
Question: Can you provide a list of Java Searching and Sorting Programs?
Answer: 1) Linear Search in Java
2) Binary Search in Java
3) Bubble Sort in Java
4) Selection Sort in Java
5) Insertion Sort in Java
Question: Can you provide a list of Java Conversion Programs?
Answer: 1) How to convert String to int in Java
2) How to convert int to String in Java
3) How to convert String to long in Java
4) How to convert long to String in Java
5) How to convert String to float in Java
6) How to convert float to String in Java
7) How to convert String to double in Java
8) How to convert double to String in Java
9) How to convert String to Date in Java
10) How to convert Date to String in Java
11) How to convert String to char in Java
12) How to convert char to String in Java
13) How to convert String to Object in Java
14) How to convert Object to String in Java
15) How to convert int to long in Java
16) How to convert long to int in Java
17) How to convert int to double in Java
18) How to convert double to int in Java
19) How to convert char to int in Java
20) How to convert int to char in Java
21) How to convert String to boolean in Java
22) How to convert boolean to String in Java
23) How to convert Date to Timestamp in Java
24) How to convert Timestamp to Date in Java
25) How to convert Binary to Decimal in Java
26) How to convert Decimal to Binary in Java
27) How to convert Hex to Decimal in Java
28) How to convert Decimal to Hex in Java
29) How to convert Octal to Decimal in Java
30) How to convert Decimal to Octal in Java
Question: Can you provide a list of Java Pattern programs?
Answer: 1) Java program to print the following spiral pattern on the console
2) Java program to print the following pattern
3) Java program to print the following pattern 2
4) Java program to print the following pattern 3
5) Java program to print the following pattern 4
6) Java program to print the following pattern 5
7) Java program to print the following pattern on the console
8) Java program to print the following pattern on the console 2
9) Java program to print the following pattern on the console 3
10) Java program to print the following pattern on the console 4
11) Java program to print the following pattern on the console 5
12) Java program to print the following pattern on the console 6
13) Java program to print the following pattern on the console 7
14) Java program to print the following pattern on the console 8
15) Java program to print the following pattern on the console 9
16) Java program to print the following pattern on the console 10
17) Java program to print the following pattern on the console 11
18) Java program to print the following pattern on the console 12
Question: Can you provide a list of Java Singly Linked List Programs?
Answer: 1) Singly linked list Examples in Java
2) Java Program to create and display a singly linked list
3) Java program to create a singly linked list of n nodes and count the number of nodes
4) Java program to create a singly linked list of n nodes and display it in reverse order
5) Java program to delete a node from the beginning of the singly linked list
6) Java program to delete a node from the middle of the singly linked list
7) Java program to delete a node from the end of the singly linked list
8) Java program to determine whether a singly linked list is the palindrome
9) Java program to find the maximum and minimum value node from a linked list
10) Java Program to insert a new node at the middle of the singly linked list
11) Java program to insert a new node at the beginning of the singly linked list
12) Java program to insert a new node at the end of the singly linked list
13) Java program to remove duplicate elements from a singly linked list
14) Java Program to search an element in a singly linked list