WorksheetsOracle Java Certification Test-1
Total questions: 200
Worksheet time: 3hrs 46mins
What would the new value of A be?
A=1;
a++;
1
2
3
4
What's the value of below?
int i=5;
System.out.println(i++);
System.out.println(i);
System.out.println(++i);
5
6
7
6
6
7
6
7
8
5
5
6
Which statement(s) are equivalent to i = i + 1?
i += 1
i++
i -= 1
i--
Which are the types of operators seen? Select as many you think
bitwise operator
subtraction operator
equality operator
arithmetic operator
what is modulo operation used for ?
performs division
performs division and gives no remainder
performs division and gives remainder
does not perform division
arithmetic operators return a value. True or false?
true
false
conditional operators does not return a value
true
false
which data types work on bitwise operators?
byte
double
char
int
which type of operator it is? i + =5
addition assignment operator
conditional operator
arithmetic operator
equality operator
Find the output for the following.
public class IncDec
{
public static void main(String s[])
{
int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
System.out.println("a = " + a);
System.out.print("b = " + b);
System.out.println("c = " + c);
System.out.print("d = " + d);
}
}
a = 2 b = 3 c = 4 d = 1
a = 2 b = 3 c = 4 d = 1
Program does not compile.
a = 1 b = 2 c = 4 d = 2
What will be the output of the program?
class Test
{
public static void main(String [] args)
{
int x=20;
String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";
System.out.println(sup);
}
}
small
tiny
huge
Compilation fails
Find the output of the following snippet.
class Numbers
{
public static void main(String args[])
{
int a=20, b=10;
if((a<b)&&(b++ <25))
{
System.out.println("this is any language logic");
}
System.out.println(b);
}
}
10
12
11
Compilation Error
Please write correct output in following space-
10
20
No Output
Error
1. Which of this method is given parameter via command line arguments?
a) main()
b) recursive() method
c) Any method
d) System defined methods
What are the Type Conversions available in Java language?
A) Narrowing Type Conversion
B) Widening Type Conversion
A and B
D) None of the above
What is the output of the below Java code snippet?
char ch = 'A';//ASCII 65
int a = ch + 1;
ch = (char)a;
System.out.println(ch);
A) 66
B) A
C) B
D) 65
Which type of loop is best known for its boolean condition that controls entry to the loop?
A. do-while loop
B. for (traditional)
C. for-each
D. while
What will be the Output of the below code:
public class Demo{
public static void main(String[] arr){
}
public static void main(String arr){
}
}
a) Nothing
b) Error
C) Finite
d) Hii
char is 2 byte in storage?
True
False
Name the data type: '3'
int
char
String
None of the above
What data type would you use for storing the number of students in a class?
boolean
String
double
int
What is the output of the below Java code snippet?
char ch = 'A';//ASCII 65
int a = ch + 1;
ch = (char)a;
System.out.println(ch);
A) 66
B) A
C) B
D) 65
What is the output of the following code snippet?
int i = 0; for(i = 0 ; i < 5; i++)
{ }
System.out.println(i);
A. 5
B. 0
C. 4
D. Compilation Error
Function of the Scanner class to accept a float literal from the user is
nextInt( )
hasNext( )
next( )
nextFloat( )
Predict the value of k,
int k =10;
k=k+k++;
11
20
21
22
Which of the following key word is optional in Exception handling program
try
catch
finally
throw
What is an exception
Error occurred during the execution of a program
Bug occurred during the compile time of a program
Simply an Error
It is related to input values
Exception classes belongs to following package
import java.io.*
import java.lang.*
import java.util.*
import java.lang.Exception.*
Choose an exception if attempt to divide number by zero
int number = 89 / 0;
System.out.println("The answer is " + number);
ArithmeticException
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundException
class exception_handling
{ public static void main(String args[])
{ try
{ int a, b;
b = 0;
a = 5 / b;
System.out.print("A");
} catch(ArithmeticException e)
{ System.out.print("B");
}
finally
{ System.out.print("C");
}
}
}
A
B
AC
BC
Find the output for the following.
public class IncDec
{
public static void main(String s[])
{
int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
System.out.println("a = " + a);
System.out.print("b = " + b);
System.out.println("c = " + c);
System.out.print("d = " + d);
}
}
a = 2 b = 3 c = 4 d = 1
a = 2 b = 3 c = 4 d = 1
Program does not compile.
a = 1 b = 2 c = 4 d = 2
ar, given the following declaration:int[] ar = {2, 4, 6, 8 }0, 1, 2, 31, 2, 3, 40, 2, 4, 6What is the first index of an array?
1
0
2
3
For the array:
int stats[3];
What is the range of the index?
0 to 3
0 to 2
1 to 3
0 to 4
int [] nums = {2, 3, 5, 8, 9, 11};
How would you access the fourth element in nums?
nums[4]
nums[3]
nums(4)
nums(3)
a = {0, 2, 3, 4} and v = 1?
Find the output
class Test {
public static void main(String args[]) {
int arr[2];
System.out.println(arr[0]);
System.out.println(arr[1]);
}
}
Compile error
Exception
Garbage Value
Garbage Value
0
0
Is String a primitive data type?
Yes
No
Both
Java is a
Procedure Oriented Language
Structure Oriented Language
Object_Oriented Language
Machine Language
The name of the following should be the file name in Java
Object Name
Variable Nam
Class Name
Array Name
Java program is
Interpreted
Compiled
Java program does not run without below function
user()
system()
main()
void()
A ___________ file is created after successful compilation of a Java program.
Object file
Array file
Class file
String file
Command to compile Java program
javax
javay
javac
Java
Command to run a Java program
javaa
java
jaava
jaavaa
JDK stands for
Java Developer Kit
Java Development Kit
Java Design Kit
Java Debugging Kit
JRE stands for
Java Run Environment
Java Run Execution
Java Runtime Environment
Java Ready Execution
Java is
Machine dependent language
Machine independent language
Is String a primitive data type?
Yes
No
Both
Which method to use to find length of a string?
length()
size()
long()
count()
Which data type gets returned from length() method in String class?
double
String
int
number
String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
What is the correct way to find the length of "txt" string?
int len = length(txt);
float len = txt.length();
int len = txt.length();
double len = length(txt);
Which is correct method to convert String into uppercase
changeUpperCase()
convertUpperCase()
toUpper()
toUpperCase()
String txt = "Hello World";
System.out.println(txt.toUpperCase());
Choose the correct output.
"HELLO WORLD"
HELLO WORLD
Hello world
Hello World
Choose correct purpose of indexOf() in String class.
returns the index (the position) of the last occurrence of a specified text in a string
returns the character of the first occurrence of a specified character in a string
returns the index (the position) of the first occurrence of a specified text in a string (excluding whitespace)
returns the index (the position) of the first occurrence of a specified text in a string (including whitespace)
String x = "10";
String y = "20";
String z = x + y;
System.out.println(z);
Guess the output.
1020
10 20
30
"10 20"
What will be the output of below code?
String statement = "Outfit of the day";
System.out.println(statement.Substring(3,6));
it of
tfit
fit
FIT
Choose most appropriate purpose of trim() method in String?
to remove white spaces
to get a substring of the string
to cut String at desired index
to remove extra white spaces from start and end of String
What is the return type of equalsIgnorecase() method?
int
String
char
boolean
What is the most appropriate way to check if two Strings are identical?
string1 == string2
string1.equals(string2)
string1.same(string2)
string1.equalsIgnorecase(string2)
(Multiple answer question)
Pick all NON-primitive datatypes from below :
String
int
primitive
Array
What is the correct relation between length and last-index of array?
last-index is always 1 more than the length
last-index is 1 less than the length (but not always)
last-index is always 1 less than the length
last-index is always equal to the length
What is word.length()?
What is word.charAt(7) ?
What is word.startsWith("A few") ?
What is word.endsWith("man") ?
String word = "A few good men";
What is word.indexOf(“f”)?
2
0
1
3
What is word.substring(3, 7) ?
What is word.length()?
What is word.charAt(7) ?
What is word.indexOf(“f”)?
What is word.indexOf(“f”)?
What is word.indexOf(“bad”)?
What is word.substring(3, 7) ?
Which of the following is NOT a primitive data type?
double
float
boolean
String
What would be output by the following program segment?
String n1 = "Samuel";
String n2 = "Samantha";
System.out.print(n1.compareTo(n2);
false
true
a positive number, 20
a negative number, -20
String txt = "Hello World";
System.out.println(txt.toUpperCase());
Choose the correct output.
"HELLO WORLD"
HELLO WORLD
Hello world
Hello World
String firstName = "John ";
String lastName = "Doe";
System.out.println(firstName.concat(lastName));
Guess the output.
John.concat(Doe)
John Doe
JohnDoe
"John Doe"
String x = "10";
String y = "20";
String z = x + y;
Guess the output.
1020
10 20
30
"10 20"
Which of these class is superclass of String and StringBuffer class?
java.util
java.lang
ArrayList
None of the mentioned
Which of these is an incorrect statement?
String objects are immutable, they cannot be changed
String object can point to some other reference of String variable
StringBuffer class is used to store string in a buffer for later use
None of the mentioned
What is the output of this program?
class String_demo{
public static void main(String args[])
{
char chars[] = {'a', 'b', 'c'};
String s = new String(chars);
System.out.println(s);
}
}
a
b
c
abc
What is the output of following program?
class string_class{
public static void main(String args[]){
String obj = "hello";
String obj1 = "world";
String obj2 = obj;
obj2 = " world";
System.out.println(obj + " " + obj2);
}
}
hello hello
world world
hello world
world hello
The String method compareTo() returns
true
false
an int value
1
What is the output of the following code?
String a = "19";
String b = "75";
System.out.println(a+" "+b);
19 75
94
Compilation Error
1975
What method of class String is used to remove white spaces at the beginning and end of String objects?
remove()
trim()
concat()
Substring()
What is the return type of equalsIgnorecase() method?
int
String
char
boolean
What is the output of the following?
String a = "I will pass the exams.";
String b = " I will pass the exams. ";
if (a.equals(b))
System.out.println("fail");
else
System.out.println(b.substring(9,12));
pass
fail
Compilation Error
I will pass the exams.
Which of these class is superclass of String and StringBuffer class?
java.util
java.lang
ArrayList
None of the mentioned
String name = "Mark Hayes";
String team = "Yankees";
String enemy = "Red Sox";
String funny = "Yankees will win the World Series!";
String yearsWon = "2009 2000 1999 1998 1996";
System.out.println( team.substring(2, 7) );
(a)
static int mystery(String p1)
String target = "millisecond";
for (int i=0; i<target.length(); i++)
{
if (target.charAt(i) == 'l')
break;
else
System.out.print(target.charAt(i));
}
What does the following print?
String str = "And yet, it moves!"
System.out.println( str.charAt( str.length() ) );
A
n
!
The statment is incorrect.
Examine the following fragment:
String world = "World!";
StringBuffer buf = new StringBuffer( "Hello" );
buf.append(' ');
buf.append( world );
How many StringBuffer objects are constructed?
0
1
2
3
After a StringBuffer has been constructed, how many characters may be added to it?
No more after it has been constructed.
Only as many as the original capacity.
As many as needed; it will grow in size if necessary.
A new StringBuffer must be constructed each time characters are added.
You wish to compare the contents of two StringBuffer objects. How should this be done?
Use the == operator.
Use the equals() method of StringBuffer.
Construct a String object from each StringBuffer and use their equals() method.
Do a character-by-character comparison using charAt() and ==.
Examine the following fragment:
String cat = "Hello"
cat += " ";
cat += "World" ;
How many objects are constructed?
0
1
2
3
What is the advantage of Exception Handling
To avoid abnormal termination of a program
To find out errors
To Debug program
None of these
What is the parent class of All Exceptions in JAVA
Throw
Exception
Error
Bug
Which of the following key word is optional in Exception handling program
try
catch
finally
throw
try block may or may not contains catch blocks
True
False
What is the purpose of 'throw' keyword
To Raise an exception explicityly
To Raise an exception implicityly
To create user defined exceptions
To create custom exceptions
What is an exception
Error occurred during the execution of a program
Bug occurred during the compile time of a program
Simply an Error
It is related to input values
How to create our own exception
using 'throw' keyword
using 'throws' keyword
using 'finally' keyword
using 'throwable' keyword
Exception classes belongs to following package
import java.io.*
import java.lang.*
import java.util.*
import java.lang.Exception.*
Which of these keywords is not a part of exception handling?
try
finally
thrown
catch
java.lang.NullPointerException is a
Error
runtime exception
Compile time exception
None
Which of these class is highest in hierarchy in java
java.lang.Exception
java.lang.Error
java.lang.Throwable
java.lang.Object
Choose the CORRECT exception
String department="JTMK";
Integer no=Integer.parseInt(department);
ArithmeticException
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundsException
Choose an exception if attempt to divide number by zero
int number = 89 / 0;
System.out.println("The answer is " + number);
ArithmeticException
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundException
What will it print?
1
2
3
30
1
2
30
1
2
3
11
1
2
11
Which line or lines should we get inside a try block to avoid errors?
3
4
6
2
What will this print?
There was an error
1
9
0
What will this program print?
Nothing, there is an error
There was a ValueError, please try again
num1num2
num2num1
public class Foo
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally" );
}
}
}
Finally
Compilation fails.
The code runs with no output
An exception is thrown at runtime.
What will be the output of the program?
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
System.out.println(" Arithmetic Exception");
}
System.out.println("finished");
finished
runtime error.
Compilation fails
Exception.
public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod()
{
throw new Error(); /* Line 22 */
}
}
ABCD
Compilation fails.
C is printed before exiting with an error message.
BC is printed before exiting with an error message
public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (RuntimeException ex) /* Line 10 */
{
System.out.print("B");
}
catch (Exception ex1)
{
System.out.print("C");
}
finally
{
System.out.print("D");
}
System.out.print("E");
}
public static void badMethod()
{
throw new RuntimeException();
}
}
BD
BDE
BD
DE
FileNotFoundException
Is a subclass/extends IOException
Is a Compile time exception
Found in java.io package
All
class Main {
public static void main(String args[]) {
try {
throw 10;
}
catch(int e) {
System.out.println("Got the Exception " + e);
}
}
}
Got the Exception 10
Got the Exception 0
Compiler Error
none
class exception_handling
{ public static void main(String args[])
{ try
{ int a, b;
b = 0;
a = 5 / b;
System.out.print("A");
} catch(ArithmeticException e)
{ System.out.print("B");
}
finally
{ System.out.print("C");
}
}
}
A
B
AC
BC
class IT
{
static public void main(String...args)
{
int k=Integer.parseInt(args[0]);
System.out.println(k);
}
}
if args[0]="gec" then what type of exception is thrown by the above program.
NumberFormatException
NullPointerException
ArrayIndexOutOfBoundsException
InvalidStringException
class IT
{
static public void main(String...args)
{
String s=null;
System.out.println("length is:"+s.length());
}
}
It throws NullPointerException
it throws IOException
It throws StringExeption
output is 0
peep
bark
meow
Compilation fails
An exception is thrown at runtime.
Cat is-a Animal
Cat is-a Jumper
Dog is-a Animal
Beagle has-a Tail
Beagle has-a Jumper
public int blipvert(int x) { return 0; }
private int blipvert(int x) { return 0; }
private int blipvert(long x) { return 0; }
protected long blipvert(int x) { return 0; }
protected int blipvert(long x) { return 0; }
test
null
An exception is thrown at runtime.
Compilation fails because of an error in line 1.
Compilation fails because of an error in line 4.
Compilation fails.
An exception is thrown at runtime.
The attribute id in the Item object remains unchanged.
The attribute id in the Item object is modified to the new value.
A new Item object is created with the preferred value in the id attribute.
int foo() { /* more code here */ }
void foo() { /* more code here */ }
public void foo() { /* more code here */ }
private void foo() { /* more code here */ }
protected void foo() { /* more code here */ }
p0 = p1;
p1 = p2;
p2 = (ClassC)p4;
p2 = (ClassC)p1;
p1 = (ClassB)p3;
Value: 3
Value: 8
Value: 13
Compilation fails.
The code runs with no output.
Which Man class properly represents the relationship "Man has a best friend who is a Dog"?
class Man extends Dog { }
class Man implements Dog { }
class Man { private BestFriend dog; }
class Man { private Dog bestFriend; }
class Man { private Dog<bestFriend>; }
An exception is thrown at runtime.
Compilation fails because of an error in line 7.
Compilation fails because of an error in line 4.
Compilation succeeds and no runtime errors with class A occur.
Properties of an OOPS are also known __________________ of JAVA Programming
methods
Characteristics
classes
functions
Which of the following concepts of OOPs means exposing only necessary information and hiding the background details?
Encapsulation
Abstraction
Data hiding
Data binding
As blueprint is a design for a house, a class is a design for a(n):
object
variable
constant
statement
Which one is NOT the principle of OOP?
Class
Abstraction
BlueJ
Abstraction
Encapsulation
In OOP the main importance is given to the
methods
procdures
data
objects
Java uses both compiler and interpreter
true
false
The system of using the existing class in another class is called
encapsulation
abstraction
Inheritance
abstraction
Java was developed by
James gosling
John gosling
James frank
John frank
A
B
C
D
E
A
B
C
D
A
B
C
D
A
B
C
D
A
B
C
D
A
B
C
D
A
B
C
D
A
B
C
D
E
A
B
C
D
A
B
C
D
A
B
C
D
A
B
C
D
A
B
C
D
A
B
C
D
A
B
C
D
A
B
C
D
A
B
C
D
E
A
B
C
D
F
A
B
C
D
E
A
B
C
D
A
B
C
D
A
B
C
D
A
B
C
D
A
B
C
D
A
B
C
D
Which of the following is a type of polymorphism in Java?
Compile time polymorphism
Execution time polymorphism
Multiple polymorphism
Multilevel polymorphism
Which component is used to compile, debug and execute java program?
JVM
JDK
JIT
JRE
Syntax to compile java program from command prompt
java Filename.java
javac Filename
javac Filename.java
java Filename
Which component is responsible for converting bytecode into machine specific code?
JVM
JDK
JIT
JRE
Which of the following is not a valid Java comment?
/** Comment 1 */
*/ Comment 2 /*
// Comment 3
/* Comment 4 */
When saving a Java source file, save it with an extension of
.java.
.javac.
.src.
.class.
Which of the following is not a rule that must be followed when naming identifiers?
After the first character, you may use the letters a-z, A-Z, an underscore, a dollar sign, or digits 0-9.
Identifiers can contain spaces.
Uppercase and lowercase characters are distinct.
The first character must be one of the letters a-z, A-Z, an underscore or a dollar sign.
To print "Hello, world" on the monitor, use the following Java statement:
System.out.println("Hello, world");
System Print = "Hello, world";
SystemOutPrintln('Hello, world');
system.out.println{Hello, world};
Which company owns Java?
Oracle
Microsoft
Apple
Intel
Who invented Java?
James Gosling
Sergey Brin
Steve Jobs
Bill Gates
Tim Berners-Lee
Java was originally named:
Coffee
Oak
New C++
Duke
Which of this keyword must be used to inherit a class?
super
this
extend
extends
Which of these statement is incorrect?
Every class must contain a main() method
Applets do not require a main() method at all
There can be only one main() method in a program
main() method must be made public
What is the extension of compiled java classes?
.java
.class
.txt
.js
Where does a java program start executing instructions from:
class
source file
main method
object
Which of these keywords is used to make a class?
class
struct
int
none of the mentioned
Which of the following is a type of polymorphism in Java?
Compile time polymorphism
Execution time polymorphism
Multiple polymorphism
Multilevel polymorphism
Which of the following is not OOPS concept in Java?
Inheritance
Encapsulation
Polymorphism
Compilation
