Java java core 1 quiz

Java fundamental quiz collection that covers the syntax, data types and flow control of Java langage

This quiz is in Java quiz collection.

Start quiz
  • 1.

    What is the outcome?

    int value = (int) 2.0 / 3.0;
    System.out.println(value);
  • 2.

    What is wrong with this code?

    public String readLine() {
        try {
          BufferedReader br = 
             new BufferedReader(new FileReader("file.txt"));
          String line = br.readLine();
          br.close();
          return line;
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
    }
  • 3.

    What will be printed?

    int i = 255;
    byte b = (byte) i;
    System.out.println(b);
  • 4.

    What will be printed?

    double value = -0.0;
    System.out.println(value);
  • 5.

    What will be printed?

    boolean value = -0.0 == 0.0;
    System.out.println(value);
  • 6.

    What will be printed?

    boolean value = Double.NaN == Double.NaN;
    System.out.println(value);
  • 7.

    What will be printed?

    boolean value = 
      Double.POSITIVE_INFINITY == Double.POSITIVE_INFINITY;
    System.out.println(value);
  • 8.

    What will be printed?

    int a = -1;
    a = a >> 1;
    System.out.println(a);
  • 9.

    What will be printed?

    int a = -1;
    a = a >>> 1;
    System.out.println(a);
  • 10.

    What will be printed?

    byte b = (byte) 128;
    b >>>= 1;
    System.out.println(b);
  • 11.

    What will be the result of executing this code?

    String s = null;
    if ((s != null) || (!s.isEmpty())) {
      System.out.println(s);
    } else {
      System.out.println("the string is null");
    }
  • 12.

    What will be printed?

    String s1 = new String("a");
    String s2 = new String("a");
    System.out.println(s1 == s2);
  • 13.

    What will be the result of running this code?

    public class Test {
      static boolean printAndReturn(boolean value) {
        System.out.println(value);
        return value;
      }
      public static void main(String[] args) {
        if (printAndReturn(false) && printAndReturn(true)) {
          System.out.println(true);
        } else {
          System.out.println(false);
        }
      }
    }
  • 14.

    What will be printed?

    int a = 1;
    a += ++a * a;
    System.out.println(a);
  • 15.

    What will be printed?

    String s1 = "a";
    String s2 = "a";
    System.out.println(s1 == s2);
  • 16.

    What will be printed?

    String s1 = "a";
    String s2 = s1;
    s1 += "b";
    System.out.println(s2);
  • 17.

    What will be printed?

    int a = 10;
    System.out.println(a + ~a);
  • 18.

    What will be the output of the program?

    String a = "newspaper";
    a = a.substring(5,7);
    char b = a.charAt(1);
    a = a + b;
    System.out.println(a);
  • 19.

    What will be the output of the program?

    String a = "ABCD"; 
    String b = a.toLowerCase(); 
    b.replace('a','d'); 
    b.replace('b','c'); 
    System.out.println(b);
  • 20.

    Which of the following is true?

    public final class Main {
      static final String s = "hello";
      public void main(String[] args) {
        System.out.println(s);
      }
    }

© 2017 QuizBucket.org