- * Is size of a keyword?
- * What is the immediate super class of the Dialog class?
- * What is the SimpleTimeZone class?
- * What is the difference between a Vector and an Array? Discuss the advantages and disadvantages of both?
- * How are this () and super () used with constructors?
- * What restrictions are placed on method overloading?
- * How many methods in the Serializable interface?
- * Is there a separate stack for each thread in Java?
- * How are memory leaks possible in Java?
- * Why multiple inheritance using classes is disadvantage in java
- * How can we write our own array list without using collections?
- * can we write return statement in try catch or finally block. Suppose we write return in try catch or finally. Can we do?
- * What synchronization constructs does Java provide? How do they work?
- * Have you ever used Hash Table and Dictionary?
- * What is the Dictionary Class?
- * What is the immediate super class of the Dialog class?
Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts
March 6, 2008
JAVA Interview Questions - 5
JAVA Interview Questions - 4
- * What is the advantage if a person has Java + LDAP SKILLS?
- * Where exactly we make use of Clone objects in a real time?
- * Which containers use a border Layout as their default layout?
- * Why do threads block on I/O?
- * What is synchronization and why is it important?
- * What is the difference between yielding and sleeping?
- * Can a for statement loop indefinitely?
- * Which containers may have a Menu Bar?
- * What is the Map interface?
- * What is the difference between paint () and repaint () methods?
- * What is abstract method?
- * What is garbage collection?
- * What is the difference between Iterator and Enumeration?
- * What is the difference between InputStream/Outputstream classes?
- * What is the order of method invocation in an Applet?
- * What is serialization?
- * What is the use of Interface?
- * Why does not support multiple Inheritance?
- * What method is used to specify a container's layout?
- * What state does a thread enter when it terminates its processing?
JAVA Interview Questions - 3
- * What is the web server used for running the Servlets?
- * What is the Vector class?
- * What is the difference between yielding and sleeping?
- * How does a try statement determine which catch clause should be used to handle an exception?
- * What are the problems faced by Java programmers who don't use layout managers?
- * What do you mean by virtual methods?
- *what are the other ways to create an object other than creating as new object?
- * What is the difference between C++ & Java?
- * What is the purpose of the wait(), notify(), and notify All() methods?
- * What is the difference between a static and a non-static inner class?
- * If a variable is declared as private, where may the variable be accessed?
- * What is the % operator?
- * When can an object reference be cast to an interface reference?
- * What are the problems faced by Java programmers who don't use layout managers?
- * What are wrapper classes?
- * Is null a keyword?
- * What is the difference between preemptive scheduling and time slicing?
- * What value does read () return when it has reached the end of a file?
- * What is the relationship between clipping and repainting?
- * How many methods in the Externalizable interface?
JAVA Interview Questions - 2
- * Can a lock be acquired on a class?
- * What happens when you invoke a thread's interrupt method while it is sleeping or waiting?
- * What is static variable?
- * What is Singleton class?
- * What is the middleware? What is the functionality of Web server?
- * What is the difference in between C++ and Java? Can u explain in detail?
- * What value does readLine() return when it has reached the end of a file?
- * What is the command pattern? Where it is used?
- * Can a Byte object be cast to a double value?
- * What happens when a thread cannot acquire a lock on an object?
- * What is typecasting?
- * What is JVM?
- * What is JNI?
- * Can a for statement loop indefinitely?
- * What is the difference between a Window and a Frame?
- * Are true and false keywords?
- * What is final method?
- * What is JAR file?
- * What is the difference between Hash map and Hash table?
JAVA Interview Questions - 1
- * Why do you create interfaces, and when MUST you use one?
- * How to make application thread-safe?
- * Are constructors inherited? Can a subclass call the parent's class constructor? When?
- * Why Java is not fully object oriented?
- * Can an exception be re thrown?
- * What are wrapped classes?
- * Can a lock be acquired on a class?
- * Difference between Array List and Vector?
- * What is synchronization and why is it important?
- * Can a double value be cast to a byte?
- * Name four Container classes?
- * What are wrapped classes?
- * What is the difference between Serializalble and Externalizable interface?
- * How Linked list can be implemented in java with out using collection framework?
- * How many different types of JDBC drivers are present? Discuss them.
- * Which class is extended by all other classes?
- * A local inner class may be final or abstract?
- * What is transient variable?
- * Can the abstract class be final?
- * How will you pass values from HTML page to the Servlet?
- * Explain tier and -tier Architecture?
September 11, 2007
Java Objective Questions - 6
51. what is the value of 111%13?
a. 11
b. 5
c. 6
d. 7(*)
52. which of the following are methods of the graphics class?
a. drawrect() (*)
b. drawimage() (*)
c. drawpoint()
d. drawstring() (*)
53. if you run the following program, which lines would be included in its output?
class question {
public static void main(string[] args) {
int i=1;
int j=2;
outer: while(i
++i;
inner: do {
++j;
if (j%3==0) continue outer;
if (i%3==0) break inner;
if (i%3==1) break outer;
system.out.println(i*j);
} while (j <>
system.out.println(i+j);
}
}
}
a. 5
b. 6
c. 7(*)
d. the program does not display any output.
54. what is the output of the following program?
class s1{
public static void main(string[] args) {
new s2();
}
s1() {
system.out.pritn("s1");
}
}
class s2 extends s1 {
s2() {
system.out.print("s2");
}
}
a. s1
b. s2
c. s1s2(*)
d. s2s1
55. what is the range of char type?
a. 0 to 2^16
b. 0 to 2^16-1(*)
c. 0 to 2^15
d. 0 to 2^15-1
56. which of the following methods are methods of math class?
a. absolute()
b. cosine()
c. sine()
d. log() (*)
57. which of the following are true about local inner classes?
a. they are not associated with any instance of an outer class.(*)
b. they may access final initialized variables and parameters that are in the scope of the statement block in which the class is declared(*)
c. they may be declared public, protected or private
d. they may not implement an interface
58. when a thread blocks on I/O, which of the following are true?
a. the thread enters the ready state.
b. the thread enters the dead state
c. no other thread may perform I/O
d. the thread enters the waiting state(*)
59. what is the output of the following program when it is invoked using the command line java Test this is a test?
class Test {
public static void main(String arg[]) {
system.out.println(arg[1]);
}
}
a. this
b. is(*)
c. a
d. test?
60. a frame's background color is set to color.yellow and button's background color is set to colr.blue. suppose the button is added to a panel, which is added to the frame. what background color will be used wth the panel?
a. color.yellow(*)
b. color.blue
c. color.green
d. color.white
a. 11
b. 5
c. 6
d. 7(*)
52. which of the following are methods of the graphics class?
a. drawrect() (*)
b. drawimage() (*)
c. drawpoint()
d. drawstring() (*)
53. if you run the following program, which lines would be included in its output?
class question {
public static void main(string[] args) {
int i=1;
int j=2;
outer: while(i
++i;
inner: do {
++j;
if (j%3==0) continue outer;
if (i%3==0) break inner;
if (i%3==1) break outer;
system.out.println(i*j);
} while (j <>
system.out.println(i+j);
}
}
}
a. 5
b. 6
c. 7(*)
d. the program does not display any output.
54. what is the output of the following program?
class s1{
public static void main(string[] args) {
new s2();
}
s1() {
system.out.pritn("s1");
}
}
class s2 extends s1 {
s2() {
system.out.print("s2");
}
}
a. s1
b. s2
c. s1s2(*)
d. s2s1
55. what is the range of char type?
a. 0 to 2^16
b. 0 to 2^16-1(*)
c. 0 to 2^15
d. 0 to 2^15-1
56. which of the following methods are methods of math class?
a. absolute()
b. cosine()
c. sine()
d. log() (*)
57. which of the following are true about local inner classes?
a. they are not associated with any instance of an outer class.(*)
b. they may access final initialized variables and parameters that are in the scope of the statement block in which the class is declared(*)
c. they may be declared public, protected or private
d. they may not implement an interface
58. when a thread blocks on I/O, which of the following are true?
a. the thread enters the ready state.
b. the thread enters the dead state
c. no other thread may perform I/O
d. the thread enters the waiting state(*)
59. what is the output of the following program when it is invoked using the command line java Test this is a test?
class Test {
public static void main(String arg[]) {
system.out.println(arg[1]);
}
}
a. this
b. is(*)
c. a
d. test?
60. a frame's background color is set to color.yellow and button's background color is set to colr.blue. suppose the button is added to a panel, which is added to the frame. what background color will be used wth the panel?
a. color.yellow(*)
b. color.blue
c. color.green
d. color.white
Java Objective Questions - 5
41. which layout is the defauld layout of a panel object?
a. gridlayout
b. flowlayout(*)
c. gridlinelayout
d. linelayout
43. which of the following are true?
a. java only supports preemptive scheduling.
b. java only supports time slicing.
c. the jvm has been implemented on os that use time slicing(*)
d. the jvm has been implemented on os that use preemptive scheduling.(*)
44. what should you use to position a button within an application frame so that the size of the button is not affected by the frame size?
a. flowlayout(*)
b. gridlayout
c. the center area of a borderlayout
d. the east or west area of a borderlayout
e. the north or south area of a borderlayout
45. a catch clause may catch exceptions of which types?
a. thowable type(*)
b. error type(*)
c. exception(*)
d. string
46. what is the value displayed by the following program?
class question{
public static void main(string[] args) {
int x=0;
boolean b1,b2,b3,b4;
b1= b2= b3= b4= true;
x = (b1|b2&b3^b4)?x++:--x;
system.out.println(x)
}
}
a. 0(*)
b. -1
c. 1
d. none of the above
47. which method is used to set the text of a label object?
a. settext() (*)
b. setlabel()
c. settextlabel()
d. setlabeltext()
48. which of the following methods cause the string object referenced by s to be changed?
a. s.concat()
b. s.touppercase(0
c. s.replace()
d. none of the above(*)
49. in order for teh myprogram proram to be compiled and run, which of the followin must be true?
a. the myprogram class must be defined in myprogram.java
b. myprogram must be declared as public
c. myprogram must have correctly formed main() method(*)
d. myprogram must import java.lang
50. which of the followin are true?
a. textcomponent extends textarea
b. textarea extends textfield
c. textfield extends textcomponent(*)
d. textcomponent extends textfield
d. textarea extends textcomponent(*)
a. gridlayout
b. flowlayout(*)
c. gridlinelayout
d. linelayout
43. which of the following are true?
a. java only supports preemptive scheduling.
b. java only supports time slicing.
c. the jvm has been implemented on os that use time slicing(*)
d. the jvm has been implemented on os that use preemptive scheduling.(*)
44. what should you use to position a button within an application frame so that the size of the button is not affected by the frame size?
a. flowlayout(*)
b. gridlayout
c. the center area of a borderlayout
d. the east or west area of a borderlayout
e. the north or south area of a borderlayout
45. a catch clause may catch exceptions of which types?
a. thowable type(*)
b. error type(*)
c. exception(*)
d. string
46. what is the value displayed by the following program?
class question{
public static void main(string[] args) {
int x=0;
boolean b1,b2,b3,b4;
b1= b2= b3= b4= true;
x = (b1|b2&b3^b4)?x++:--x;
system.out.println(x)
}
}
a. 0(*)
b. -1
c. 1
d. none of the above
47. which method is used to set the text of a label object?
a. settext() (*)
b. setlabel()
c. settextlabel()
d. setlabeltext()
48. which of the following methods cause the string object referenced by s to be changed?
a. s.concat()
b. s.touppercase(0
c. s.replace()
d. none of the above(*)
49. in order for teh myprogram proram to be compiled and run, which of the followin must be true?
a. the myprogram class must be defined in myprogram.java
b. myprogram must be declared as public
c. myprogram must have correctly formed main() method(*)
d. myprogram must import java.lang
50. which of the followin are true?
a. textcomponent extends textarea
b. textarea extends textfield
c. textfield extends textcomponent(*)
d. textcomponent extends textfield
d. textarea extends textcomponent(*)
Java Objective Questions - 4
31. when two or more objects are added as listners for the same event, which listener is first invoked to handle the event?
a. the first object that was added as a listener
b. the last object that was added as a listener
c. there is no way to determine which listener will be invoked first.(*)
it is impossible to have more than one listener for a given event.
32. which of the following are true?
a. a reference to an array can be cast to a reference to an object(*)
b. a reference to an array can be cast to a reference to a cloneable(*)
c. a reference to an array can be cast to a reference to a string
d. none of the above
33. which layout is used to layout the components of a container in a grid where each row and column are the same size?
a. gridlayout
b. null layout
c. gridbaglayout
d. gridbagconstraintlayout
34. what is the output of the following program?
class outer {
string s = "outer";
public static void main(string args[]) {
new outer().new Inner();
}
outer() {
system.out.prints(s);
}
class inner {
string s = "inner";
inner() {
system.out.print(s);
}
}
}
a. outer
b. inner
c. outerinner(*)
d. innerouter
35. what is the result of the expression 5.4 + "3.2" ?
a. the double 8.6
b. the string 8.6
c. the long value 8
d. the string 5.43.2(*)
36. which are true about the container class?
a. the validate() method is used to cause a container to be laid out and redisplayed (*)
b. the add() method is used to add a component to a container (*)
c. the getborder() method returns information about a containers insets
d. the getcomponent() method is used to access a component that is contained in a container (*)
37. which of the following are true about this method declaration?
void mymethod(string s) { }
a. mymethod() is static
b. mymethod does not return a value(*)
c. mymethod is abstract
d. mymethod may not be accessed outside of a package in which it is declared(*)
38. which lines of output are displayed by the following program?
class question{
public static void main(string[] args) {
for(int i=0;i<10;i++)>
try {
try {
if (i%3==0) throw new Exception("E0");
system.out.println(i);
}
catch(exception inner) {
i *=2;
if(i%3==0) throw new exception("E1");
} finally {
++i;
}
}
catch(exception outer) {
i+=3;
} finally {
--i;
}
}
}
}
a. 4(*)
b. 5(*)
c. 6
d. 7
e. 8
f. 9
39. if you run the following program, what lines would be included in its output?
class question{
public static void main(string args[]) {
int i,j;
for(i=0,j=0;i+j<20;++i,j+=i--)>
system.out.println(i+j);
}
}
}
a. 5(*)
b. 8(*)
c. 13(*)
d. the program cannot be compiled because the for statement's syntax is incorrect.
40. which of the following are direct or indirect subclasses of component?
a. button(*)
b. label(*)
c. checkboxmenuitem
d. toolbar
e. frame(*)
a. the first object that was added as a listener
b. the last object that was added as a listener
c. there is no way to determine which listener will be invoked first.(*)
it is impossible to have more than one listener for a given event.
32. which of the following are true?
a. a reference to an array can be cast to a reference to an object(*)
b. a reference to an array can be cast to a reference to a cloneable(*)
c. a reference to an array can be cast to a reference to a string
d. none of the above
33. which layout is used to layout the components of a container in a grid where each row and column are the same size?
a. gridlayout
b. null layout
c. gridbaglayout
d. gridbagconstraintlayout
34. what is the output of the following program?
class outer {
string s = "outer";
public static void main(string args[]) {
new outer().new Inner();
}
outer() {
system.out.prints(s);
}
class inner {
string s = "inner";
inner() {
system.out.print(s);
}
}
}
a. outer
b. inner
c. outerinner(*)
d. innerouter
35. what is the result of the expression 5.4 + "3.2" ?
a. the double 8.6
b. the string 8.6
c. the long value 8
d. the string 5.43.2(*)
36. which are true about the container class?
a. the validate() method is used to cause a container to be laid out and redisplayed (*)
b. the add() method is used to add a component to a container (*)
c. the getborder() method returns information about a containers insets
d. the getcomponent() method is used to access a component that is contained in a container (*)
37. which of the following are true about this method declaration?
void mymethod(string s) { }
a. mymethod() is static
b. mymethod does not return a value(*)
c. mymethod is abstract
d. mymethod may not be accessed outside of a package in which it is declared(*)
38. which lines of output are displayed by the following program?
class question{
public static void main(string[] args) {
for(int i=0;i<10;i++)>
try {
try {
if (i%3==0) throw new Exception("E0");
system.out.println(i);
}
catch(exception inner) {
i *=2;
if(i%3==0) throw new exception("E1");
} finally {
++i;
}
}
catch(exception outer) {
i+=3;
} finally {
--i;
}
}
}
}
a. 4(*)
b. 5(*)
c. 6
d. 7
e. 8
f. 9
39. if you run the following program, what lines would be included in its output?
class question{
public static void main(string args[]) {
int i,j;
for(i=0,j=0;i+j<20;++i,j+=i--)>
system.out.println(i+j);
}
}
}
a. 5(*)
b. 8(*)
c. 13(*)
d. the program cannot be compiled because the for statement's syntax is incorrect.
40. which of the following are direct or indirect subclasses of component?
a. button(*)
b. label(*)
c. checkboxmenuitem
d. toolbar
e. frame(*)
Java Objective Questions - 3
21. which of the following are characteristic of a fully encapsulated class?
a. all variables are private(*)
b. all methods are private
c. methods are provided to access the class's properties(*)
d. the class's design may be changed with minimal impact on its implementation
22. which of the following are true about the finally clause of a try-catch-finally statement?
a. it is only executed after a catch clause has executed
b. it is only executed if a catch clause has not executed
c. it is always executed unless its thread terminates(*)
it is only executed if an exception is thrown
23. which layout stacks components on tope of each other?
a. cardlayout(*)
b. null layout
c. borderlayout
d. setlayout
24. which of the following components generate action events?
a. buttons(*)
b. labels
c. checkboxes
d. windows
25. which methods will cause a frame to be displayed?
a. show() (*)
b. setVisible() (*)
c. display()
d. displayFrame()
26. what is the range of the short type?
a. 0 to 2^16
b. -(2^16) to 2^16
c. -(2^15) to 2^15
d. -(2^15) to 2^15-1 (*)
27. what is the value of a[3] as the result of the following array declaration?
int[] a={1,2,3,4,5};
a.1
b.2
c.3
d.4(*)
28. what is the output of the following program?
public class question {
public static void main(String args[]) {
boolean[] b = new boolean[2];
double[] d = new double[2];
System.out.print(b[0]);
System.out.println(d[1]);
a. true0.0
b. true0
c. false0.0 (*)
d. false0
29. what is the output of the following program?
class question {
static int i=1,j=2;
static {
display(i);
}
public static void main(String args[]) {
display(j);
static void display(int n) {
system.out.print(n);
}
}
a. 1
b. 2
c. 12(*)
d. 21
30. which of the following are true?
a. a top-level class may be declared as private
b. a method may be declared as transient
c. a constructor may be declared as volatile
d. a local variable may be declared as final(*)
a. all variables are private(*)
b. all methods are private
c. methods are provided to access the class's properties(*)
d. the class's design may be changed with minimal impact on its implementation
22. which of the following are true about the finally clause of a try-catch-finally statement?
a. it is only executed after a catch clause has executed
b. it is only executed if a catch clause has not executed
c. it is always executed unless its thread terminates(*)
it is only executed if an exception is thrown
23. which layout stacks components on tope of each other?
a. cardlayout(*)
b. null layout
c. borderlayout
d. setlayout
24. which of the following components generate action events?
a. buttons(*)
b. labels
c. checkboxes
d. windows
25. which methods will cause a frame to be displayed?
a. show() (*)
b. setVisible() (*)
c. display()
d. displayFrame()
26. what is the range of the short type?
a. 0 to 2^16
b. -(2^16) to 2^16
c. -(2^15) to 2^15
d. -(2^15) to 2^15-1 (*)
27. what is the value of a[3] as the result of the following array declaration?
int[] a={1,2,3,4,5};
a.1
b.2
c.3
d.4(*)
28. what is the output of the following program?
public class question {
public static void main(String args[]) {
boolean[] b = new boolean[2];
double[] d = new double[2];
System.out.print(b[0]);
System.out.println(d[1]);
a. true0.0
b. true0
c. false0.0 (*)
d. false0
29. what is the output of the following program?
class question {
static int i=1,j=2;
static {
display(i);
}
public static void main(String args[]) {
display(j);
static void display(int n) {
system.out.print(n);
}
}
a. 1
b. 2
c. 12(*)
d. 21
30. which of the following are true?
a. a top-level class may be declared as private
b. a method may be declared as transient
c. a constructor may be declared as volatile
d. a local variable may be declared as final(*)
Java Objective Questions - 2
11. which font attributes are available through the FontMetrics class?
a. ascent(*)
b. leading(*)
c. case
d. height(*)
12.which of the following are true?
a. component extends container
b. menuitem extends component
c. container extends component(*)
d. menucomponent extends component
13. what is the ovtal equivalent of the decimal value 123?
a. 0173(*)
b. 123
c. 0x123
d. 0x173
14. in order for the public class Myclass to successfully compile, which of the following are true?
a. myclasss must have a correctly formed main method
b. myclass must be defined in the file myclass.java(*)
c. myclass must be defined in the myclas package.
d. myclass must be imported
15. which of the following are true?
a. any unicode character is represented using 16 bits
b. seven bits are needed to represent any ASCII character
c. UTf-8 characters are represented using only eight bits.
d. UTF-16 characters are represented using only 16 bits.
16. which of the following are true about a dead thread?
a. the thread's object is discarded.
b. the thread must wait until all other threads execute before it is restarted
c. the thread cannot be restarted(*)
d. the thread is synchornized
17. what is the output displayed by the following program?
class question {
public static void main(String args[]) {
int n=7;
n<<=3;
n=n&n+1|n+2^n+3;
n>>=2;
System.out.println(n);
}
}
a. 0
b. -1
c. 14(*)
d. 64
18. which of the following are true?
a. a component may handle its own events by adding itself as an even listener(*)
b. a component may handle its own events by overriding its event-dispatching method.(*)
c. a component may not handle its own events
d. a component may handle its own events only if it implements the handleEvent() method
19. what can contain objects that have a unique key field of string type, if it is required to retrieve the objects using that key field as an inded?
a. map(*)
b. set
c. list
d. collection
e. enumeration
20. what output is displayed by the following program?
import java.io.*;
public class TestIOApp {
public static void main(String args[]) throws IOException{
StringReader stringin = new StringReader("test")
LineNumberReader in = new LineNumberReader(stringin);
PrintWriter out = new PrintWriter(System.out);
out.println(in.readLine());
out.flush();
}
}
a. test(*)
b. 1. test
c. 1: test
d. 1 test
a. ascent(*)
b. leading(*)
c. case
d. height(*)
12.which of the following are true?
a. component extends container
b. menuitem extends component
c. container extends component(*)
d. menucomponent extends component
13. what is the ovtal equivalent of the decimal value 123?
a. 0173(*)
b. 123
c. 0x123
d. 0x173
14. in order for the public class Myclass to successfully compile, which of the following are true?
a. myclasss must have a correctly formed main method
b. myclass must be defined in the file myclass.java(*)
c. myclass must be defined in the myclas package.
d. myclass must be imported
15. which of the following are true?
a. any unicode character is represented using 16 bits
b. seven bits are needed to represent any ASCII character
c. UTf-8 characters are represented using only eight bits.
d. UTF-16 characters are represented using only 16 bits.
16. which of the following are true about a dead thread?
a. the thread's object is discarded.
b. the thread must wait until all other threads execute before it is restarted
c. the thread cannot be restarted(*)
d. the thread is synchornized
17. what is the output displayed by the following program?
class question {
public static void main(String args[]) {
int n=7;
n<<=3;
n=n&n+1|n+2^n+3;
n>>=2;
System.out.println(n);
}
}
a. 0
b. -1
c. 14(*)
d. 64
18. which of the following are true?
a. a component may handle its own events by adding itself as an even listener(*)
b. a component may handle its own events by overriding its event-dispatching method.(*)
c. a component may not handle its own events
d. a component may handle its own events only if it implements the handleEvent() method
19. what can contain objects that have a unique key field of string type, if it is required to retrieve the objects using that key field as an inded?
a. map(*)
b. set
c. list
d. collection
e. enumeration
20. what output is displayed by the following program?
import java.io.*;
public class TestIOApp {
public static void main(String args[]) throws IOException{
StringReader stringin = new StringReader("test")
LineNumberReader in = new LineNumberReader(stringin);
PrintWriter out = new PrintWriter(System.out);
out.println(in.readLine());
out.flush();
}
}
a. test(*)
b. 1. test
c. 1: test
d. 1 test
Java Objective Questions -1
1. How do you create a Reader object from an inputstream object?
a. use the static createReader() method of the inputstream class.
b. use the static createReader() method of the reader class
c. create an inputstreamreader object, passing the inputstream object as an argument to the inputstreamreader constructor(*)
d. create an outputstreamreader object, passing the inputstream object as an argument to the outputstreamreader constructor.
2. which of the following are valid identifiers?
a. _id(*)
b. $id(*)
c. #id
d. -id
3. which of the following are true?
a. the sleep() method puts a thread in the ready state.
b. the yield() method puts a thread in the waiting state.
c. the suspend() method is the preferred method for stopping a thread's execution.
d. a thread's interrupt() method results in the throwing of the interruptedexception.(*)
4. which of the following classes have a paint() method?
a. canvas(*)
b. image
c. frame(*)
d. graphics
5. which statement creates textarea with 10 rows and 20 columns?
a. new TextArea(10,20)(*)
b. new TextArea(20,10)
c. new TextArea(Rows(10),Cols(20))
d. new TextArea(Row(10),Col(20))
6. which of the following are true?
a. the AWT automatically causes a window to be repainted when a portion of a window has been minimized and then maximized.(*)
b. the AWT automatically causes a window to be repainted when a portion of a window has been covered and then uncovered.(*)
c. the AWT automatically causes a window to be repainted when application data is changed.
d. the AWT does not support repainting operations.
7. which of the following are java keywords?
a. null
b. NULL
c. extends(*)
d. main
8. which of the following thread state transitions are valid?
a. from ready to running(*)
b. from running to ready(*)
c. from running to waiting(*)
d. from waiting to running
e. from waiting to ready(*)
f. from ready to waiting
9. which of the following is not a wrapper class?
a. string(*)
b. integer
c. boolean
d. character
10. which is the advantage of encapsulation?
a. only public methods are needed
b. no exceptions need to be thrown from any method
c. making the class final causes no cnsequential changes to other code.
d. it changes the implementation without changing the interface and causes no consequential changes to other code.(*)
e. it changes the interface without changing the implementatino and causes no consequential changes to other code.
a. use the static createReader() method of the inputstream class.
b. use the static createReader() method of the reader class
c. create an inputstreamreader object, passing the inputstream object as an argument to the inputstreamreader constructor(*)
d. create an outputstreamreader object, passing the inputstream object as an argument to the outputstreamreader constructor.
2. which of the following are valid identifiers?
a. _id(*)
b. $id(*)
c. #id
d. -id
3. which of the following are true?
a. the sleep() method puts a thread in the ready state.
b. the yield() method puts a thread in the waiting state.
c. the suspend() method is the preferred method for stopping a thread's execution.
d. a thread's interrupt() method results in the throwing of the interruptedexception.(*)
4. which of the following classes have a paint() method?
a. canvas(*)
b. image
c. frame(*)
d. graphics
5. which statement creates textarea with 10 rows and 20 columns?
a. new TextArea(10,20)(*)
b. new TextArea(20,10)
c. new TextArea(Rows(10),Cols(20))
d. new TextArea(Row(10),Col(20))
6. which of the following are true?
a. the AWT automatically causes a window to be repainted when a portion of a window has been minimized and then maximized.(*)
b. the AWT automatically causes a window to be repainted when a portion of a window has been covered and then uncovered.(*)
c. the AWT automatically causes a window to be repainted when application data is changed.
d. the AWT does not support repainting operations.
7. which of the following are java keywords?
a. null
b. NULL
c. extends(*)
d. main
8. which of the following thread state transitions are valid?
a. from ready to running(*)
b. from running to ready(*)
c. from running to waiting(*)
d. from waiting to running
e. from waiting to ready(*)
f. from ready to waiting
9. which of the following is not a wrapper class?
a. string(*)
b. integer
c. boolean
d. character
10. which is the advantage of encapsulation?
a. only public methods are needed
b. no exceptions need to be thrown from any method
c. making the class final causes no cnsequential changes to other code.
d. it changes the implementation without changing the interface and causes no consequential changes to other code.(*)
e. it changes the interface without changing the implementatino and causes no consequential changes to other code.
August 28, 2007
Java Question - 4
Q 31- Using the symbols 1 and 0 construct a truth table showing the four possible combinations of 1 and 0. Using a 1 or a 0, show the result of the bitwise inclusive or operation on these four
combinations on these four combinations of 1 and 0.
A - The answer for the inclusive or is:
1 or 1 produces 1
1 or 0 produces 1
0 or 1 produces 1
0 or 0 produces 0
combinations on these four combinations of 1 and 0.
A - The answer for the inclusive or is:
1 or 1 produces 1
1 or 0 produces 1
0 or 1 produces 1
0 or 0 produces 0
combinations on these four combinations of 1 and 0.
A - The answer for the exclusive or is:
1 xor 1 produces 0
1 xor 0 produces 1
0 xor 1 produces 1
0 xor 0 produces 0
A - True.
A - The assignment operator is a binary operator.
A - True.
A - Java supports the following list of shortcut assignment operators. These operators allow you to perform an assignment and another operation with a single operator. += -= *= /= %= &= |= ^= <<= >>= >>>=
For example, the two statements which follow perform the same operation.
x += y; x = x + y;
The behavior of all the shortcut assignment operators follows this same pattern.
class prog3{
static public void main(String[] args){
int x = 3;
int y = 3;
int z = 10;
System.out.println("Prefix version gives " + (z + ++x));
System.out.println("Postfix version gives " + (z + y++));
}//end main
}//end class
class Prog4 { //define the controlling class
public static void main(String[] args){ //define main method
System.out.println("The relational 6<5 is " + (6<5 ) );
System.out.println("The relational 6>5 is " + (6>5 ) );
System.out.println("The relational 5>=5 is " + (5>=5 ) );
System.out.println("The relational 5<=5 is " + (5<=5 ) );
System.out.println("The relational 6==5 is " + (6==5 ) );
System.out.println("The relational 6!=5 is " + (6!=5 ) );
}//end main
}//End prog4 class. Note no semicolon required
class prg5 { //define the controlling class
public static void main(String[] args){ //define main method
System.out.println("true and true is " + (true && true) );
System.out.println("true and false is " + (true && false) );
System.out.println("true or true is " + (true || true) );
System.out.println("true or false is " + (true || false) );
System.out.println("false or false is " + (false || false) );
System.out.println("not true is " + (! true) );
System.out.println("not false is " + (! false) );
}//end main
}
A - Java does not support a constant type. However, in Java, it is possible to achieve the same result by declaring and initializing a variable and making it final.
A - The syntax for creating a named constant in Java is as follows: final float PI = 3.14159;
A - you can control the order of evaluation by the use of parentheses.
A - The operation of a loop normally involves the following three actions in addition to executing the code in the body of the loop:
Initialize a control variable.
Test the control variable in a conditional expression.
Update the control variable.
Java Questions - 3
Q 21- Show and describe six different relational operators supported by Java.
A - Java supports the following set of relational operators:
Operator Returns true if > Left operand is greater than right operand
>= Left operand is greater than or equal to right operand
< Left operand is less than right operand
<= Left operand is less than or equal to right operand
== Left operand is equal to right operand
!= Left operand is not equal to right operand
A - Java supports the following set of relational operators:
Operator Returns true if > Left operand is greater than right operand
>= Left operand is greater than or equal to right operand
< Left operand is less than right operand
<= Left operand is less than or equal to right operand
== Left operand is equal to right operand
!= Left operand is not equal to right operand
class prg2 { //define the controlling class
public static void main(String[] args){ //define main method
System.out.println("The relational 6<5>
System.out.println("The relational 6>5 is " + (6>5 ) );
}//end main
}//End class. Note no semicolon required
//End Java application
A - This program produces the following output:
The relational 6<5 is false
The relational 6>5 is true
A - The following three logical or conditional operators are supported by Java.
Operator Typical Use Returns true if
&& Left && Right Left and Right are both true
|| Left || Right Either Left or Right is true
! ! Right Right is false
A - An important characteristic of the behavior of the && and || operators in Java is that the expressions are evaluated from left to right, and the evaluation of the expression is terminated as soon as the result of evaluating the expression can be determined. For example, in the above expression, if the variable a is less than the variable b , there is no need to evaluate the right operand of the || to determine the value of the entire expression. Thus, evaluation will terminate as soon as it is determined that a is less than b.
A - The & operator in Java is a bitwise and and the | operator is a bitwise or.
A - The bitwise and operator is represented by the & symbol in Java.
A - The following table shows the seven bitwise operators supported by Java.
Operator Typical Use Operation >> OpLeft >> Dist Shift bits of OpLeft right by Dist bits (signed)
<< OpLeft << style=""> Shift bits of OpLeft left by Dist bits
>>> OpLeft >>> Dist Shift bits of OpLeft right by Dist bits (unsigned)
& OpLeft & OpRight Bitwise and of the two operands | OpLeft | OpRight Bitwise inclusive or of the two operands ^ OpLeft ^ OpRight Bitwise exclusive or (xor) of the two operands
~ ~ OpRight Bitwise complement of the right operand (unary)
A - False: In Java, the signed right shift operation populates the vacated bits with the sign bit, while the left shift and the unsigned right shift populate the vacated bits with zeros.
A - True: For both Java and C++, bits shifted off the right end are lost.
A - The answer is:
1 and 1 produces 1
1 and 0 produces 0
0 and 1 produces 0
0 and 0 produces 0
Java Questions - 2
Q11 - Show the symbol for the increment operator.
A - The symbol for the increment operator is two plus signs with nothing between them (++).
A - The symbol for the increment operator is two plus signs with nothing between them (++).
postfix notation. Show example, possibly incomplete, code fragments illustrating both notational
forms.
A - The increment operator may be used with both prefix and postfix notation. Basically, the increment operator causes the value of the variable to which it is applied to be increased by one. With prefix notation, the operand appears to the right of the operator ( ++X), while with postfix notation, the operand appears to the left of the operator (X++).
The difference in behavior has to do with the point in time that the increment actually occurs if the operator and its operand appear as part of a larger overall expression. With the prefix version, the variable is incremented before it is used to evaluate the larger overall expression. With the postfix version, the variable is used to evaluate the larger overall expression and then it is incremented.
class prg1 { //define the controlling class
public static void main(String[] args){ //define main method
int x = 5, X = 5, y = 5, Y = 5;
System.out.println("x = " + x );
System.out.println("x + X++ = " + (x + X++) );
System.out.println("X = " + X );
System.out.println();
System.out.println("y = " + y );
System.out.println("Y = " + Y );
System.out.println("y + ++Y = " + (y + ++Y) );
System.out.println("Y = " + Y );
}//end main
}//End class. Note no semicolon required
//End Java application
A - The output from this Java application follows:
x = 5
X = 5
x + X++ = 10
X = 6
y = 5
Y = 5
y + ++Y = 11
Y = 6
A - False: Binary operators use infix notation, which means that the operator appears between its operands.
A - As a result of performing the specified action, an operator can be said to return a value (or evaluate to a value) of a given type. The type depends on the operator and the type of the operands. To evaluate to a value means that after the action is performed, the operator and its operands are effectively replaced in the expression by the value that is returned.
A - Some authors divide Java's operators into the following categories:
arithmetic
relational and conditional (typically called relational and logical in C++)
bitwise and logical
assignment
(Clarification: binary operators does not mean bitwise operators).
A - Java support various arithmetic operators on floating point and integer numbers. The following table lists five of the binary arithmetic operators supported by Java.
Operator Description + Adds its operands - Subtracts the right operand from the left operand
* Multiplies the operands / Divides the left operand by the right operand
% Remainder of dividing the left operand by the right operand
example code fragment to illustrate your answer. The code fragment need not be a complete
statement.
A - The plus operator (+) is also used to concatenate strings : "IMR " + " global Ltd."
behavior if its right operand is not of type String? If the right operand is a variable that is not of typeString, what is the impact of this behavior on that variable.
A - In this case, the operator also coerces the value of the right operand to a string representation for use in the expression only. If the right operand is a variable, the value stored in the variable is not modified in any way.
A - Java supports the following four unary arithmetic operators.
Operator Description + Indicates a positive value - Negates, or changes algebraic sign ++ Adds one to the operand, both prefix and postfix
-- Subtracts one from operand, prefix and postfix
Java Question -1
Q 1What do we call an operator that operates on only one operand?
A - An operator that operates on only one operand is called a unary operator.
A - An operator that operates on only one operand is called a unary operator.
A - An operator that operates on two operands is called a binary operator.
A - Both. As a binary operator, the minus sign causes its right operand to be subtracted from its left operand. As a unary operator, the minus sign causes the algebraic sign of the right operand to be changed.
A - For those languages that support it (such as C++) operator overloading means that the programmer can redefine the behavior of an operator with respect to objects of a new type defined by that program.
A 5- False: Unfortunately, Java does not support operator overloading.
A - The above listed operators in order are: = != + (type)
A - The plus sign (+) is automatically overloaded in Java. The plus sign can be used to perform arithmetic addition. It can also be used to concatenate strings. However, the plus sign does more than concatenate strings. It also performs a conversion to String type. When the plus sign is used to concatenate strings, the operand on the right is automatically converted to a character string before being concatenated with the operand on the left. This assumes that the compiler knows enough about the operand on the right to be able to successfully perform the conversion. It has that knowledge for all of the primitive types and most or all of the built-in reference types.
A - The cast operator is used to purposely convert from one type to another.
A - False: The increment operator is a unary operator.
Subscribe to:
Posts (Atom)