oDesk Java Test Answers
·
Question
1 What is the java .net.IDN class in
1.6?
Methods to convert internationalizeddomain names (IDNs) between a normal Unicode representation and an ASCII Compatible
Encoding (ACE) representation
Question 2 What will be the output of the following program?public classTest
{
public static void main (String args[]) throwsException
{
Test o = new Test ();
System.out.println (o.content ());
}public String content () throws Exception
{throw new Exception ("This is an exception on this.content ()");
}private static class B
{public String content ()
{return ''B'';
}
}private static class A extends B
{public String content ()
{return ''A'';
}
}
}
The code will compile but throw an exception at runtime
Question 3 Which of these interfaces are used by implementations of models for JTable?
TableModel
TableColumnModel
Question-4
How many times can classes be nested within a class?
Any number of times
Question-5
One method in your application needs to be synchronized. Which of the following options are correct for synchronization?
public void Process(){ synchronized(this){ } }
public void synchronized Process(){}
Question-6
What could be the replacement of "//ABC" in the following code?public class Jam
{
public void apple(int i, String s)
{}
//ABC
}
public void apple(String s, int i){}
public void Apple(int i, String s) {}
Question-7
What will be the output when the following code is compiled and run?public class Test
{
public static void main (String args[])
{
int i;
i = 3;
System.out.println ((int)i * 2.5 / 3.0);
}
}
The code willprint 2.5
Question-8
What would happen on trying to compile and run the following code?public class MainCls
{
public static void main(String argv)
{
System.out.println("My Text");
}
}
The code will compile. A runtime error will occur because 'main' is not properly defined
Question-9
What will be the output when this code is compiled and run?public class Test
{
static int x = 10;
public Test ()
{
Bar b = new Bar ();
Bar b1 = new Bar ();
update (b);
update (b1);
}private void update (Bar bar)
{
bar.x = ++x;
System.out.println (bar.x);
}public static void main (String args[])
{
File f = new File("/","autoexec.bat"); b.DataInputStream d = new DataInputStream(System.in);c.RandomAccessFile r = new RandomAccessFile("OutFile"); d.OutputStreamWriter o = newOutputStreamWriter(System.out);
}private class Bar
{public int x = 10;
}
}
11 12
Question-10
Which of the following statement will not compile?
RandomAccessFile r = new RandomAccessFile("OutFile");
Question-11
Which of the following are "keywords" in Java?
default
throws
Question-12
Which of the following statements is true of the HashMap class?
It stores information as key/value pairs
Question-13
How does the set collection deal with duplicate elements?
The add method returnsfalse if you attempt to add an element with a duplicate value
Question-14
What is wrong with the following code?class X extends Exception {}
public class Y
{public void foo()
{
try {
b();
}
finally {
ba();
}
catch (MyException e) {}
}
public void b() throws X {
throw new X();
}public void ba() throws RuntimeException {
throw new RuntimeException();
}
}
None of the above
Question-15
Is the following code valid?InetAddress ad = InetAddress.getByName ("195.186.2.111");
Yes
Question-17
Which of the following cannot apply to constructors?
Void return type
Question-18
Choose the correct declarations for the main() method which will allow the class to be run as a standalone program.
public static void main(String str[])
Question-19
For a class defined inside a method, what rule governs access to the variables of the enclosing method?
The class can only access transient variables
Question-20
A method can be defined as native to:
Get to access hardware that Java does not know about
Write optimized code for performance in a language such as C/C++
Question-21
What will be the output of the following line?System.out.println(Math.floor(-2.1));
-3.0
Question-22
For the given variables, which of the following will compile without an error?char c = 'c';
int i = 50;
double d = 80;
long l = 200;
String s = "Goodbye";
s+=i;
1. What’s relationship betweenJavaScript and ECMAScript? -
ECMAScript is yet another name for JavaScript (other names include LiveScript).
The current JavaScript that you see supported in browsers is ECMAScript revision 3.
2. What are JavaScript types? -
Number, String, Boolean, Function, Object, Null, Undefined.
3. How do you convert numbers between different bases in JavaScript? -
Use the parseInt() function, that takes a string as the first parameter, and the base as
a second parameter. So to convert hexadecimal 3F to decimal, use parseInt ("3F", 16);
4. What does isNaN function do? -
Return true if the argument is not a number.
5. What is negative infinity? -
It’s a number in JavaScript, derived by dividing negative number by zero.
6. What boolean operators does JavaScript support? -
&&, || and !
7. What does "1"+2+4 evaluate to? -
Since 1 is a string, everything is a string, so the result is 124.
8. How about 2+5+"8"? -
Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it’s concatenation,
so 78 is the result.
9. What looping structures are there in JavaScript? -
for, while, do-while loops, but no foreach.
10. How do you create a new object in JavaScript? -
var obj = new Object(); or var obj = {};
11. How do you assign object properties? -
obj["age"] = 17 or obj.age = 17.
12. What’s a way to append a value to an array? -
arr[arr.length] = value;
13. What is this keyword? -
It refers to the current object.
Question 1
What is the java.net.IDN class in 1.6?
Methods to resolve integrated domain names (IDNs), such domain names are special embedded names
Methods to swap bytes between network byte order and host byte order
Methods to convert internationalized domain names (IDNs) between a normal Unicode representation and an ASCII Compatible Encoding (ACE) representation
This class does not exist
None of the above
Question 2
What will be the output of the following program?public class Test
{
public static void main (String args[]) throws Exception
{
Test o = new Test ();
System.out.println (o.content ());
}
public String content () throws Exception
{
throw new Exception ("This is an exception on this.content ()");
}
private static class B
{
public String content ()
{
return ''B'';
}
}
private static class A extends B
{
public String content ()
{
return ''A'';
}
}
}
The code will fail to compile
The code will compile but throw an exception at runtime
The code will compile and on running, it will print ''A''
The code will compile and on running, it will print ''B''
Question 3
Which of these interfaces are used by implementations of models for JTable?
TableModel
TableColumnModel
TableSelectionModel
ListModel
Question 4
How many times can classes be nested within a class?
5
8
4
Any number of times
Question 5
One method in your application needs to be synchronized. Which of the following options are correct for synchronization?
public synchronized void Process(void){}
public void Process(){ synchronized(this){ } }
public void synchronized Process(){}
public synchronized void Process(){}
Question 6
What could be the replacement of "//ABC" in the following code?public class Jam
{
public void apple(int i, String s)
{}
//ABC
}
public void apple(String s, int i){}
public int apple(int i, String s){}
public void apple(int i, String mystring){}
public void Apple(int i, String s) {}
Question 7
What will be the output when the following code is compiled and run?public class Test
{
public static void main (String args[])
{
int i;
i = 3;
System.out.println ((int)i * 2.5 / 3.0);
}
}
The code will compile, but it will throw an exception when it is run
The code will compile and it will not produce any output when it is run
The code will fail to compile
The code will print 3
The code will print 2.5
The code will print 2
Question 8
What would happen on trying to compile and run the following code?public class MainCls
{
public static void main(String argv)
{
System.out.println("My Text");
}
}
A compile error will be generated because 'main' is a reserved word and cannot be used for a class
"My Text" will be displayed
The code will compile. A runtime error will occur because 'main' is not properly defined
The code will compile. A runtime error will occur because constructor is not defined
Question 9
What will be the output when this code is compiled and run?public class Test
{
static int x = 10;
public Test ()
{
Bar b = new Bar ();
Bar b1 = new Bar ();
update (b);
update (b1);
}
private void update (Bar bar)
{
bar.x = ++x;
System.out.println (bar.x);
}
public static void main (String args[])
{
File f = new File("/","autoexec.bat"); b.DataInputStream d = new DataInputStream(System.in);c.RandomAccessFile r = new RandomAccessFile("OutFile"); d.OutputStreamWriter o = newOutputStreamWriter(System.out);
}
private class Bar
{
public int x = 10;
}
}
The code will fail to compile
11 12
11 11
12 12
Question 10
Which of the following statement will not compile?
File f = new File("/","autoexec.bat");
DataInputStream d = new DataInputStream(System.in);
RandomAccessFile r = new RandomAccessFile("OutFile");
OutputStreamWriter o = new OutputStreamWriter(System.out);
Question 11
Which of the following are "keywords" in Java?
default
NULL
String
throws
Question 12
Which of the following statements is true of the HashMap class?
It stores information as key/value pairs
Elements are returned in the order they were added
It does not permit null keys
It does not permit null values
Question 13
How does the set collection deal with duplicate elements?
Duplicate values will cause an error at compile time
A set may contain elements that return duplicate values from a call to the equals method
An exception is thrown if you attempt to add an element with a duplicate value
The add method returns false if you attempt to add an element with a duplicate value
Question 14
What is wrong with the following code?class X extends Exception {}
public class Y
{
public void foo()
{
try {
b();
}
finally {
ba();
}
catch (MyException e) {}
}
public void b() throws X {
throw new X();
}
public void ba() throws RuntimeException {
throw new RuntimeException();
}
}
Nothing is wrong with the code
Finally block should come after the catch block
An empty catch block is not allowed
None of the above
Question 15
Is the following code valid?InetAddress ad = InetAddress.getByName ("195.186.2.111");
Yes
No
Question 16
What will be the output of this program?public class Test
{
public static void main (String args[])
{
String a, b, c, d;
a = ''Hello1234'';
b = ''Hello'' + String.valueOf(1234);
c = ''Hello'' + ''1234'';
d = new String (new char[]{'H', 'e', 'l', 'l', 'o', '1', '2', '3', '4'});
System.out.print (a == b);
System.out.print ('' '');
System.out.print (a.equals(b));
System.out.print ('' '');
System.out.print (a == c);
System.out.print ('' '');
System.out.print (a.equals(c));
System.out.print ('' '');
System.out.print (a == d);
System.out.print ('' '');
System.out.print (a.equals(d));
System.out.print ('' '');
}
}
true truetruetrue false true
false true truetrue false false
false true truetrue false true
false false true true false true
Question 17
Which of the following cannot apply to constructors?
Name same as class name
Void return type
Can have parameters
Overloading
Question 18
Choose the correct declarations for the main() method which will allow the class to be run as a standalone program.
public void main(String str[])
static public void main(String str[])
public static int main(String str[])
public static void main(String str[])
Question 19
For a class defined inside a method, what rule governs access to the variables of the enclosing method?
The class can only access transient variables
The class can only access static variables
The class can only access final variables
The class can access any variable
Question 20
A method can be defined as native to:
Overcome the limitation of the private scope of a method
Get to access hardware that Java does not know about
Write optimized code for performance in a language such as C/C++
Define a new data type such as an unsigned integer
Question 21
What will be the output of the following line?System.out.println(Math.floor(-2.1));
-2
2.0
-3
-3.0
Question 22
For the given variables, which of the following will compile without an error?char c = 'c';
int i = 50;
double d = 80;
long l = 200;
String s = "Goodbye";
s+=i;
i+=s;
c+=s;
c=c+i;
Question 1
What is the java.net.IDN class in 1.6?
Methods to resolve integrated domain names (IDNs), such domain names are special embedded names
Methods to swap bytes between network byte order and host byte order
Methods to convert internationalized domain names (IDNs) between a normal Unicode representation and an ASCII Compatible Encoding (ACE) representation
This class does not exist
None of the above
Question 2
What will be the output of the following program?public class Test
{
public static void main (String args[]) throws Exception
{
Test o = new Test ();
System.out.println (o.content ());
}
public String content () throws Exception
{
throw new Exception ("This is an exception on this.content ()");
}
private static class B
{
public String content ()
{
return ''B'';
}
}
private static class A extends B
{
public String content ()
{
return ''A'';
}
}
}
The code will fail to compile
The code will compile but throw an exception at runtime
The code will compile and on running, it will print ''A''
The code will compile and on running, it will print ''B''
Question 3
Which of these interfaces are used by implementations of models for JTable?
TableModel
TableColumnModel
TableSelectionModel
ListModel
Question 4
How many times can classes be nested within a class?
5
8
4
Any number of times
Question 5
One method in your application needs to be synchronized. Which of the following options are correct for synchronization?
public synchronized void Process(void){}
public void Process(){ synchronized(this){ } }
public void synchronized Process(){}
public synchronized void Process(){}
Question 6
What could be the replacement of "//ABC" in the following code?public class Jam
{
public void apple(int i, String s)
{}
//ABC
}
public void apple(String s, int i){}
public int apple(int i, String s){}
public void apple(int i, String mystring){}
public void Apple(int i, String s) {}
Question 7
What will be the output when the following code is compiled and run?public class Test
{
public static void main (String args[])
{
int i;
i = 3;
System.out.println ((int)i * 2.5 / 3.0);
}
}
The code will compile, but it will throw an exception when it is run
The code will compile and it will not produce any output when it is run
The code will fail to compile
The code will print 3
The code will print 2.5
The code will print 2
Question 8
What would happen on trying to compile and run the following code?public class MainCls
{
public static void main(String argv)
{
System.out.println("My Text");
}
}
A compile error will be generated because 'main' is a reserved word and cannot be used for a class
"My Text" will be displayed
The code will compile. A runtime error will occur because 'main' is not properly defined
The code will compile. A runtime error will occur because constructor is not defined
Question 9
What will be the output when this code is compiled and run?public class Test
{
static int x = 10;
public Test ()
{
Bar b = new Bar ();
Bar b1 = new Bar ();
update (b);
update (b1);
}
private void update (Bar bar)
{
bar.x = ++x;
System.out.println (bar.x);
}
public static void main (String args[])
{
File f = new File("/","autoexec.bat"); b.DataInputStream d = new DataInputStream(System.in);c.RandomAccessFile r = new RandomAccessFile("OutFile"); d.OutputStreamWriter o = newOutputStreamWriter(System.out);
}
private class Bar
{
public int x = 10;
}
}
The code will fail to compile
11 12
11 11
12 12
Question 10
Which of the following statement will not compile?
File f = new File("/","autoexec.bat");
DataInputStream d = new DataInputStream(System.in);
RandomAccessFile r = new RandomAccessFile("OutFile");
OutputStreamWriter o = new OutputStreamWriter(System.out);
Question 11
Which of the following are "keywords" in Java?
default
NULL
String
throws
Question 12
Which of the following statements is true of the HashMap class?
It stores information as key/value pairs
Elements are returned in the order they were added
It does not permit null keys
It does not permit null values
Question 13
How does the set collection deal with duplicate elements?
Duplicate values will cause an error at compile time
A set may contain elements that return duplicate values from a call to the equals method
An exception is thrown if you attempt to add an element with a duplicate value
The add method returns false if you attempt to add an element with a duplicate value
Question 14
What is wrong with the following code?class X extends Exception {}
public class Y
{
public void foo()
{
try {
b();
}
finally {
ba();
}
catch (MyException e) {}
}
public void b() throws X {
throw new X();
}
public void ba() throws RuntimeException {
throw new RuntimeException();
}
}
Nothing is wrong with the code
Finally block should come after the catch block
An empty catch block is not allowed
None of the above
Question 15
Is the following code valid?InetAddress ad = InetAddress.getByName ("195.186.2.111");
Yes
No
Question 16
What will be the output of this program?public class Test
{
public static void main (String args[])
{
String a, b, c, d;
a = ''Hello1234'';
b = ''Hello'' + String.valueOf(1234);
c = ''Hello'' + ''1234'';
d = new String (new char[]{'H', 'e', 'l', 'l', 'o', '1', '2', '3', '4'});
System.out.print (a == b);
System.out.print ('' '');
System.out.print (a.equals(b));
System.out.print ('' '');
System.out.print (a == c);
System.out.print ('' '');
System.out.print (a.equals(c));
System.out.print ('' '');
System.out.print (a == d);
System.out.print ('' '');
System.out.print (a.equals(d));
System.out.print ('' '');
}
}
true truetruetrue false true
false true truetrue false false
false true truetrue false true
false false true true false true
Question 17
Which of the following cannot apply to constructors?
Name same as class name
Void return type
Can have parameters
Overloading
Question 18
Choose the correct declarations for the main() method which will allow the class to be run as a standalone program.
public void main(String str[])
static public void main(String str[])
public static int main(String str[])
public static void main(String str[])
Question 19
For a class defined inside a method, what rule governs access to the variables of the enclosing method?
The class can only access transient variables
The class can only access static variables
The class can only access final variables
The class can access any variable
Question 20
A method can be defined as native to:
Overcome the limitation of the private scope of a method
Get to access hardware that Java does not know about
Write optimized code for performance in a language such as C/C++
Define a new data type such as an unsigned integer
Question 21
What will be the output of the following line?System.out.println(Math.floor(-2.1));
-2
2.0
-3
-3.0
Question 22
For the given variables, which of the following will compile without an error?char c = 'c';
int i = 50;
double d = 80;
long l = 200;
String s = "Goodbye";
s+=i;
i+=s;
c+=s;
c=c+i;
Methods to convert internationalized
Question 2 What will be the output of the following program?public class
{
public static void main (String args[]) throws
{
Test o = new Test ();
System.out.println (o.content ());
}public String content () throws Exception
{throw new Exception ("This is an exception on this.content ()");
}private static class B
{public String content ()
{return ''B'';
}
}private static class A extends B
{public String content ()
{return ''A'';
}
}
}
The code will compile but throw an exception at runtime
Question 3 Which of these interfaces are used by implementations of models for JTable?
TableModel
TableColumnModel
Question-4
How many times can classes be nested within a class?
Any number of times
Question-5
One method in your application needs to be synchronized. Which of the following options are correct for synchronization?
public void Process(){ synchronized(this){ } }
public void synchronized Process(){}
Question-6
What could be the replacement of "//ABC" in the following code?public class Jam
{
public void apple(int i, String s)
{}
//ABC
}
public void apple(String s, int i){}
public void Apple(int i, String s) {}
Question-7
What will be the output when the following code is compiled and run?public class Test
{
public static void main (String args[])
{
int i;
i = 3;
System.out.println ((int)i * 2.5 / 3.0);
}
}
The code will
Question-8
What would happen on trying to compile and run the following code?public class MainCls
{
public static void main(String argv)
{
System.out.println("My Text");
}
}
The code will compile. A runtime error will occur because 'main' is not properly defined
Question-9
What will be the output when this code is compiled and run?public class Test
{
static int x = 10;
public Test ()
{
Bar b = new Bar ();
Bar b1 = new Bar ();
update (b);
update (b1);
}private void update (Bar bar)
{
bar.x = ++x;
System.out.println (bar.x);
}public static void main (String args[])
{
File f = new File("/","autoexec.bat"); b.DataInputStream d = new DataInputStream(System.in);c.RandomAccessFile r = new RandomAccessFile("OutFile"); d.OutputStreamWriter o = newOutputStreamWriter(System.out);
}private class Bar
{public int x = 10;
}
}
11 12
Question-10
Which of the following statement will not compile?
RandomAccessFile r = new RandomAccessFile("OutFile");
Question-11
Which of the following are "keywords" in Java?
default
throws
Question-12
Which of the following statements is true of the HashMap class?
It stores information as key/value pairs
Question-13
How does the set collection deal with duplicate elements?
The add method returns
Question-14
What is wrong with the following code?class X extends Exception {}
public class Y
{public void foo()
{
try {
b();
}
finally {
ba();
}
catch (MyException e) {}
}
public void b() throws X {
throw new X();
}public void ba() throws RuntimeException {
throw new RuntimeException();
}
}
None of the above
Question-15
Is the following code valid?InetAddress ad = InetAddress.getByName ("195.186.2.111");
Yes
Question-17
Which of the following cannot apply to constructors?
Void return type
Question-18
Choose the correct declarations for the main() method which will allow the class to be run as a standalone program.
public static void main(String str[])
Question-19
For a class defined inside a method, what rule governs access to the variables of the enclosing method?
The class can only access transient variables
Question-20
A method can be defined as native to:
Get to access hardware that Java does not know about
Write optimized code for performance in a language such as C/C++
Question-21
What will be the output of the following line?System.out.println(Math.floor(-2.1));
-3.0
Question-22
For the given variables, which of the following will compile without an error?char c = 'c';
int i = 50;
double d = 80;
long l = 200;
String s = "Goodbye";
s+=i;
1. What’s relationship between
ECMAScript is yet another name for JavaScript (other names include LiveScript).
The current JavaScript that you see supported in browsers is ECMAScript revision 3.
2. What are JavaScript types? -
Number, String, Boolean, Function, Object, Null, Undefined.
3. How do you convert numbers between different bases in JavaScript? -
Use the parseInt() function, that takes a string as the first parameter, and the base as
a second parameter. So to convert hexadecimal 3F to decimal, use parseInt ("3F", 16);
4. What does isNaN function do? -
Return true if the argument is not a number.
5. What is negative infinity? -
It’s a number in JavaScript, derived by dividing negative number by zero.
6. What boolean operators does JavaScript support? -
&&, || and !
7. What does "1"+2+4 evaluate to? -
Since 1 is a string, everything is a string, so the result is 124.
8. How about 2+5+"8"? -
Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it’s concatenation,
so 78 is the result.
9. What looping structures are there in JavaScript? -
for, while, do-while loops, but no foreach.
10. How do you create a new object in JavaScript? -
var obj = new Object(); or var obj = {};
11. How do you assign object properties? -
obj["age"] = 17 or obj.age = 17.
12. What’s a way to append a value to an array? -
arr[arr.length] = value;
13. What is this keyword? -
It refers to the current object.
Question 1
What is the java.net.IDN class in 1.6?
Methods to resolve integrated domain names (IDNs), such domain names are special embedded names
Methods to swap bytes between network byte order and host byte order
Methods to convert internationalized domain names (IDNs) between a normal Unicode representation and an ASCII Compatible Encoding (ACE) representation
This class does not exist
None of the above
Question 2
What will be the output of the following program?public class Test
{
public static void main (String args[]) throws Exception
{
Test o = new Test ();
System.out.println (o.content ());
}
public String content () throws Exception
{
throw new Exception ("This is an exception on this.content ()");
}
private static class B
{
public String content ()
{
return ''B'';
}
}
private static class A extends B
{
public String content ()
{
return ''A'';
}
}
}
The code will fail to compile
The code will compile but throw an exception at runtime
The code will compile and on running, it will print ''A''
The code will compile and on running, it will print ''B''
Question 3
Which of these interfaces are used by implementations of models for JTable?
TableModel
TableColumnModel
TableSelectionModel
ListModel
Question 4
How many times can classes be nested within a class?
5
8
4
Any number of times
Question 5
One method in your application needs to be synchronized. Which of the following options are correct for synchronization?
public synchronized void Process(void){}
public void Process(){ synchronized(this){ } }
public void synchronized Process(){}
public synchronized void Process(){}
Question 6
What could be the replacement of "//ABC" in the following code?public class Jam
{
public void apple(int i, String s)
{}
//ABC
}
public void apple(String s, int i){}
public int apple(int i, String s){}
public void apple(int i, String mystring){}
public void Apple(int i, String s) {}
Question 7
What will be the output when the following code is compiled and run?public class Test
{
public static void main (String args[])
{
int i;
i = 3;
System.out.println ((int)i * 2.5 / 3.0);
}
}
The code will compile, but it will throw an exception when it is run
The code will compile and it will not produce any output when it is run
The code will fail to compile
The code will print 3
The code will print 2.5
The code will print 2
Question 8
What would happen on trying to compile and run the following code?public class MainCls
{
public static void main(String argv)
{
System.out.println("My Text");
}
}
A compile error will be generated because 'main' is a reserved word and cannot be used for a class
"My Text" will be displayed
The code will compile. A runtime error will occur because 'main' is not properly defined
The code will compile. A runtime error will occur because constructor is not defined
Question 9
What will be the output when this code is compiled and run?public class Test
{
static int x = 10;
public Test ()
{
Bar b = new Bar ();
Bar b1 = new Bar ();
update (b);
update (b1);
}
private void update (Bar bar)
{
bar.x = ++x;
System.out.println (bar.x);
}
public static void main (String args[])
{
File f = new File("/","autoexec.bat"); b.DataInputStream d = new DataInputStream(System.in);c.RandomAccessFile r = new RandomAccessFile("OutFile"); d.OutputStreamWriter o = newOutputStreamWriter(System.out);
}
private class Bar
{
public int x = 10;
}
}
The code will fail to compile
11 12
11 11
12 12
Question 10
Which of the following statement will not compile?
File f = new File("/","autoexec.bat");
DataInputStream d = new DataInputStream(System.in);
RandomAccessFile r = new RandomAccessFile("OutFile");
OutputStreamWriter o = new OutputStreamWriter(System.out);
Question 11
Which of the following are "keywords" in Java?
default
NULL
String
throws
Question 12
Which of the following statements is true of the HashMap class?
It stores information as key/value pairs
Elements are returned in the order they were added
It does not permit null keys
It does not permit null values
Question 13
How does the set collection deal with duplicate elements?
Duplicate values will cause an error at compile time
A set may contain elements that return duplicate values from a call to the equals method
An exception is thrown if you attempt to add an element with a duplicate value
The add method returns false if you attempt to add an element with a duplicate value
Question 14
What is wrong with the following code?class X extends Exception {}
public class Y
{
public void foo()
{
try {
b();
}
finally {
ba();
}
catch (MyException e) {}
}
public void b() throws X {
throw new X();
}
public void ba() throws RuntimeException {
throw new RuntimeException();
}
}
Nothing is wrong with the code
Finally block should come after the catch block
An empty catch block is not allowed
None of the above
Question 15
Is the following code valid?InetAddress ad = InetAddress.getByName ("195.186.2.111");
Yes
No
Question 16
What will be the output of this program?public class Test
{
public static void main (String args[])
{
String a, b, c, d;
a = ''Hello1234'';
b = ''Hello'' + String.valueOf(1234);
c = ''Hello'' + ''1234'';
d = new String (new char[]{'H', 'e', 'l', 'l', 'o', '1', '2', '3', '4'});
System.out.print (a == b);
System.out.print ('' '');
System.out.print (a.equals(b));
System.out.print ('' '');
System.out.print (a == c);
System.out.print ('' '');
System.out.print (a.equals(c));
System.out.print ('' '');
System.out.print (a == d);
System.out.print ('' '');
System.out.print (a.equals(d));
System.out.print ('' '');
}
}
true truetruetrue false true
false true truetrue false false
false true truetrue false true
false false true true false true
Question 17
Which of the following cannot apply to constructors?
Name same as class name
Void return type
Can have parameters
Overloading
Question 18
Choose the correct declarations for the main() method which will allow the class to be run as a standalone program.
public void main(String str[])
static public void main(String str[])
public static int main(String str[])
public static void main(String str[])
Question 19
For a class defined inside a method, what rule governs access to the variables of the enclosing method?
The class can only access transient variables
The class can only access static variables
The class can only access final variables
The class can access any variable
Question 20
A method can be defined as native to:
Overcome the limitation of the private scope of a method
Get to access hardware that Java does not know about
Write optimized code for performance in a language such as C/C++
Define a new data type such as an unsigned integer
Question 21
What will be the output of the following line?System.out.println(Math.floor(-2.1));
-2
2.0
-3
-3.0
Question 22
For the given variables, which of the following will compile without an error?char c = 'c';
int i = 50;
double d = 80;
long l = 200;
String s = "Goodbye";
s+=i;
i+=s;
c+=s;
c=c+i;
Question 1
What is the java.net.IDN class in 1.6?
Methods to resolve integrated domain names (IDNs), such domain names are special embedded names
Methods to swap bytes between network byte order and host byte order
Methods to convert internationalized domain names (IDNs) between a normal Unicode representation and an ASCII Compatible Encoding (ACE) representation
This class does not exist
None of the above
Question 2
What will be the output of the following program?public class Test
{
public static void main (String args[]) throws Exception
{
Test o = new Test ();
System.out.println (o.content ());
}
public String content () throws Exception
{
throw new Exception ("This is an exception on this.content ()");
}
private static class B
{
public String content ()
{
return ''B'';
}
}
private static class A extends B
{
public String content ()
{
return ''A'';
}
}
}
The code will fail to compile
The code will compile but throw an exception at runtime
The code will compile and on running, it will print ''A''
The code will compile and on running, it will print ''B''
Question 3
Which of these interfaces are used by implementations of models for JTable?
TableModel
TableColumnModel
TableSelectionModel
ListModel
Question 4
How many times can classes be nested within a class?
5
8
4
Any number of times
Question 5
One method in your application needs to be synchronized. Which of the following options are correct for synchronization?
public synchronized void Process(void){}
public void Process(){ synchronized(this){ } }
public void synchronized Process(){}
public synchronized void Process(){}
Question 6
What could be the replacement of "//ABC" in the following code?public class Jam
{
public void apple(int i, String s)
{}
//ABC
}
public void apple(String s, int i){}
public int apple(int i, String s){}
public void apple(int i, String mystring){}
public void Apple(int i, String s) {}
Question 7
What will be the output when the following code is compiled and run?public class Test
{
public static void main (String args[])
{
int i;
i = 3;
System.out.println ((int)i * 2.5 / 3.0);
}
}
The code will compile, but it will throw an exception when it is run
The code will compile and it will not produce any output when it is run
The code will fail to compile
The code will print 3
The code will print 2.5
The code will print 2
Question 8
What would happen on trying to compile and run the following code?public class MainCls
{
public static void main(String argv)
{
System.out.println("My Text");
}
}
A compile error will be generated because 'main' is a reserved word and cannot be used for a class
"My Text" will be displayed
The code will compile. A runtime error will occur because 'main' is not properly defined
The code will compile. A runtime error will occur because constructor is not defined
Question 9
What will be the output when this code is compiled and run?public class Test
{
static int x = 10;
public Test ()
{
Bar b = new Bar ();
Bar b1 = new Bar ();
update (b);
update (b1);
}
private void update (Bar bar)
{
bar.x = ++x;
System.out.println (bar.x);
}
public static void main (String args[])
{
File f = new File("/","autoexec.bat"); b.DataInputStream d = new DataInputStream(System.in);c.RandomAccessFile r = new RandomAccessFile("OutFile"); d.OutputStreamWriter o = newOutputStreamWriter(System.out);
}
private class Bar
{
public int x = 10;
}
}
The code will fail to compile
11 12
11 11
12 12
Question 10
Which of the following statement will not compile?
File f = new File("/","autoexec.bat");
DataInputStream d = new DataInputStream(System.in);
RandomAccessFile r = new RandomAccessFile("OutFile");
OutputStreamWriter o = new OutputStreamWriter(System.out);
Question 11
Which of the following are "keywords" in Java?
default
NULL
String
throws
Question 12
Which of the following statements is true of the HashMap class?
It stores information as key/value pairs
Elements are returned in the order they were added
It does not permit null keys
It does not permit null values
Question 13
How does the set collection deal with duplicate elements?
Duplicate values will cause an error at compile time
A set may contain elements that return duplicate values from a call to the equals method
An exception is thrown if you attempt to add an element with a duplicate value
The add method returns false if you attempt to add an element with a duplicate value
Question 14
What is wrong with the following code?class X extends Exception {}
public class Y
{
public void foo()
{
try {
b();
}
finally {
ba();
}
catch (MyException e) {}
}
public void b() throws X {
throw new X();
}
public void ba() throws RuntimeException {
throw new RuntimeException();
}
}
Nothing is wrong with the code
Finally block should come after the catch block
An empty catch block is not allowed
None of the above
Question 15
Is the following code valid?InetAddress ad = InetAddress.getByName ("195.186.2.111");
Yes
No
Question 16
What will be the output of this program?public class Test
{
public static void main (String args[])
{
String a, b, c, d;
a = ''Hello1234'';
b = ''Hello'' + String.valueOf(1234);
c = ''Hello'' + ''1234'';
d = new String (new char[]{'H', 'e', 'l', 'l', 'o', '1', '2', '3', '4'});
System.out.print (a == b);
System.out.print ('' '');
System.out.print (a.equals(b));
System.out.print ('' '');
System.out.print (a == c);
System.out.print ('' '');
System.out.print (a.equals(c));
System.out.print ('' '');
System.out.print (a == d);
System.out.print ('' '');
System.out.print (a.equals(d));
System.out.print ('' '');
}
}
true truetruetrue false true
false true truetrue false false
false true truetrue false true
false false true true false true
Question 17
Which of the following cannot apply to constructors?
Name same as class name
Void return type
Can have parameters
Overloading
Question 18
Choose the correct declarations for the main() method which will allow the class to be run as a standalone program.
public void main(String str[])
static public void main(String str[])
public static int main(String str[])
public static void main(String str[])
Question 19
For a class defined inside a method, what rule governs access to the variables of the enclosing method?
The class can only access transient variables
The class can only access static variables
The class can only access final variables
The class can access any variable
Question 20
A method can be defined as native to:
Overcome the limitation of the private scope of a method
Get to access hardware that Java does not know about
Write optimized code for performance in a language such as C/C++
Define a new data type such as an unsigned integer
Question 21
What will be the output of the following line?System.out.println(Math.floor(-2.1));
-2
2.0
-3
-3.0
Question 22
For the given variables, which of the following will compile without an error?char c = 'c';
int i = 50;
double d = 80;
long l = 200;
String s = "Goodbye";
s+=i;
i+=s;
c+=s;
c=c+i;