Java Programming Fundamentals

Covers core Java concepts including String manipulation, collections, exceptions, AWT/Swing components, events, and graphics programming

25 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which of the following methods cannot be used with the object of String class?

  1. replace(char, char)
  2. replaceAll(String, String)
  3. append(String)
  4. Both the options 1 and 2
  5. All of these
Question 2 Multiple Choice (Single Answer)

What will be result of the given code?

String s1 = “abc”; String s2= “abg”; S1.compareTo(s2);

  1. - 4
  2. 4
  3. - 1
  4. 1
  5. 0
Question 3 Multiple Choice (Single Answer)

What will be returned by the function capacity()?

StringBuffer s = new StringBuffer(“Hello”); s.capacity();

  1. 16
  2. 4
  3. 18
  4. 3
  5. 15
Question 4 Multiple Choice (Single Answer)

What will be the output of the given code segment?
StringBuffer s = new StringBuffer(�Welcome To Java�);

s.delete(8,12);

  1. Welcome ava
  2. Welcome va
  3. Welcomeava
  4. Compiler error : delete cannot be used with StrinBuffer
  5. Run time error
Question 5 Multiple Choice (Single Answer)

Which of the following methods are provided by the Character class?

  1. isDigit()
  2. isLetter()
  3. isLetterOrDigit()
  4. All of these
  5. None of these
Question 6 Multiple Choice (Single Answer)

Which of the following functions are valid in Java for Strings?

  1. valueOf()
  2. toCharArray()
  3. toIntArray()
  4. Both the options 1 and 2
  5. Both the options 1 and 3
Question 7 Multiple Choice (Single Answer)

Which of the following data types can be passed, as the first parameter to the lastIndexOf() method in String class?

  1. Char
  2. String
  3. Int
  4. Both the options 1 and 2
  5. All of above
Question 8 Multiple Choice (Single Answer)

What will be the output of given code?

String s = “Welcome To Java”; s.length(); s.charAt(9);

  1. s.length() = 14s.charAt(9) = T
  2. s.length() = 15s.charAt(9) = o
  3. s.length() = 15s.charAt(9) = T
  4. s.length() = 14s.charAt(9) = o
  5. Compiler Error
Question 9 Multiple Choice (Single Answer)

What will be the answer of the given code?

String s = “Welcome To Java” s.substring(4 , 4 );

  1. 0
  2. c
  3. Empty string
  4. Compile time error
  5. Run time error
Question 10 Multiple Choice (Single Answer)

Which of the following are not the methods of the scanner class object in java?

  1. Next()
  2. nextLine()
  3. nextInt()
  4. nextChar()
  5. nextLong()
Question 11 Multiple Choice (Single Answer)

Which of the following methods is/are used by web browser to control the applet?

  1. Wait()
  2. Destroy()
  3. Dead()
  4. Both the options 1 and 3
  5. Both the options 1 and 2
Question 12 Multiple Choice (Single Answer)

Which of the following are the Subclasses of RuntimeException?

  1. IllegalArgumentException
  2. NullPointerException
  3. IOException
  4. IndexOutOfBoundException
  5. ArithmeticException
Question 13 Multiple Choice (Single Answer)

Which of the following event types are invalid in JAVA?

  1. FocusEvent
  2. ComponentEvent
  3. AdjustmentEvent
  4. Both the option 2 and 3
  5. None of these
Question 14 Multiple Choice (Single Answer)

What is the result of the given statements?

String s = “Welcome To Java” s.lastIndexOf(“Java”,5);

  1. - 1
  2. 11
  3. 6
  4. Compiler error : method lastIndexOf() not declared.
  5. Compiler error : parameters to method not sufficient.
Question 15 Multiple Choice (Single Answer)

Which of following layout managers are present in java awt?

  1. Gridlayout
  2. Flowlayout
  3. Cardlayout
  4. Both the options 1 and 2
  5. All of these
Question 16 Multiple Choice (Single Answer)

How many primitive data types are available in Java?

  1. 9
  2. 6
  3. 8
  4. 7
  5. 5
Question 17 Multiple Choice (Single Answer)

How many constructors are there for Layout manager FlowLayout?

  1. 5
  2. 4
  3. 3
  4. 2
  5. 1
Question 18 Multiple Choice (Single Answer)

Which of the following methods cannot be invoked from the instance of Frame class in AWT?

  1. setLocation(int, int)
  2. setVisible(Boolean)
  3. setSize(int, int)
  4. setSize(int, int)
  5. Pack()
Question 19 Multiple Choice (Single Answer)

Which of the following methods is valid in Java for handling Events?

  1. mouseEnetered()
  2. keyReleased()
  3. mouseDragged()
  4. Both the options 1 and 2
  5. All of these
Question 20 Multiple Choice (Single Answer)

Which of the following methods is/are not necessary to define for a class if it implement the windowListener Interface?

  1. windowMoved()
  2. windowClosing()
  3. windowIconified()
  4. windowActivated()
  5. windowDeiconified()
Question 21 Multiple Choice (Single Answer)

How many constructors are present of BorderLayout in Java?

  1. 5
  2. 4
  3. 3
  4. 2
  5. 1
Question 22 Multiple Choice (Single Answer)

Which of the following statements is/are correct?

Color c1 = new Color(284,60,189);

  1. A new colour will be created.
  2. runtime Exception
  3. Parameters are not enough
  4. Compile time error; cannot find method colour.
  5. Compile time error; colour is Abstract cannot create an object.
Question 23 Multiple Choice (Single Answer)

How many parameters are passed to the constructor of the Font class in java?

  1. 4
  2. 3
  3. 2
  4. 1
  5. None of these
Question 24 Multiple Choice (Single Answer)

Which of the following sources object do not generate the ActionEvent?

  1. JRadioButton
  2. JCheckBox
  3. JComboBox
  4. JList
  5. JTextField
Question 25 Multiple Choice (Single Answer)

Which of the following methods is not defined in the Graphics Class in java?

  1. fillRect()
  2. fillCircle()
  3. fillOval()
  4. fillArc()
  5. None of these