Java Basics Interview Questions

    Question 1JAVA - Variable Declaration Basics

    Which of the following is a valid variable declaration in Java?

    Question 2JAVA - Data Types

    Which of the following is a primitive data type in Java?

    Question 3JAVA - Type Casting

    What will happen in the following code?

    double d = 9.7; int x = (int) d; System.out.println(x);

    Question 4JAVA - if-else Statement

    What will be the output of the code?

    int a = 5; if(a > 10) { System.out.println("Big"); } else { System.out.println("Small"); }

    Question 5JAVA - Switch Statement

    What will this code print?

    int day = 2; switch(day) { case 1: System.out.println("Mon"); break; case 2: System.out.println("Tue"); break; default: System.out.println("Other"); }

    Question 6JAVA - While Loop

    How many times will this loop run?

    int i = 1; while(i < 4) { System.out.println(i); i++; }

    Question 7JAVA - For Loop Example

    What will be the output?

    for(int i = 0; i < 5; i += 2) { System.out.print(i + " "); }

    Question 8JAVA - Do While Loop

    What will be the output?

    int n = 5; do { System.out.println(n); n++; } while(n < 5);

    Question 9JAVA - Break Statement

    What will be the output?

    for(int i = 1; i <= 5; i++) { if(i == 3) break; System.out.print(i + " "); }

    Question 10JAVA - Continue Statement

    What will be printed?

    for(int i = 1; i <= 4; i++) { if(i == 2) continue; System.out.print(i + " "); }