24) Garbage collector thread belongs to which priority?
Ans : low-priority
25) What is meant by timeslicing or time sharing?
Ans : Timeslicing is the method of allocating CPU time to individual threads in a priority schedule.
26) What is meant by daemon thread? In java runtime, what is it's role?
Ans : Daemon thread is a low priority thread which runs intermittently in the background doing the garbage collection operation for the java runtime system.
Top
--------------------------------------------------------------------------------
Inheritance
1) What is the difference between superclass & subclass?
Ans : A super class is a class that is inherited whereas subclass is a class that does the inheriting.
2) Which keyword is used to inherit a class?
Ans : extends
3) Subclasses methods can access superclass members/ attributes at all times?
True/False
Ans : False
4) When can subclasses not access superclass members?
Ans : When superclass is declared as private.
5) Which class does begin Java class hierarchy?
Ans : Object class
6) Object class is a superclass of all other classes?
True/False
Ans : True
7) Java supports multiple inheritance?
True/False
Ans : False
8) What is inheritance?
Ans : Deriving an object from an existing class. In the other words, Inheritance is the process of inheriting all the features from a class
9) What are the advantages of inheritance?
Ans : Reusability of code and accessibility of variables and methods of the superclass by subclasses.
10) Which method is used to call the constructors of the superclass from the subclass?
Ans : super(argument)
11) Which is used to execute any method of the superclass from the subclass?
Ans : super.method-name(arguments)
12) Which methods are used to destroy the objects created by the constructor methods?
Ans : finalize()
13) What are abstract classes?
Ans : Abstract classes are those for which instances can’t be created.
14) What must a class do to implement an interface?
Ans: It must provide all of the methods in the interface and identify the interface in its implements clause.
15) Which methods in the Object class are declared as final?
Ans : getClass(), notify(), notifyAll(), and wait()
16) Final methods can be overridden.
True/False
Ans : False
17) Declaration of methods as final results in faster execution of the program?
True/False
Ans: True
18) Final variables should be declared in the beginning?
True/False
Ans : True
19) Can we declare variable inside a method as final variables? Why?
Ans : Cannot because, local variable cannot be declared as final variables.
20) Can an abstract class may be final?
Ans : An abstract class may not be declared as final.
21) Does a class inherit the constructors of it's super class?
Ans: A class does not inherit constructors from any of it's super classes.
22) What restrictions are placed on method overloading?
Ans: Two methods may not have the same name and argument list but different return types.
23) What restrictions are placed on method overriding?
Ans : Overridden methods must have the same name , argument list , and return type. The overriding method may not limit the access of the method it overridees.The overriding method may not throw any exceptions that may not be thrown by the overridden method.
24) What modifiers may be used with an inner class that is a member of an outer class?
Ans : a (non-local) inner class may be declared as public, protected, private, static, final or abstract.
25) How this() is used with constructors?
Ans: this() is used to invoke a constructor of the same class
26) How super() used with constructors?
Ans : super() is used to invoke a super class constructor
27) Which of the following statements correctly describes an interface?
a)It's a concrete class
b)It's a superclass
c)It's a type of abstract class
Ans: c
28) An interface contains __ methods
a)Non-abstract
b)Implemented
c)unimplemented
Ans:c
Top
--------------------------------------------------------------------------------
String Handling
1) Which package does define String and StringBuffer classes?
Ans : java.lang package.
2) Which method can be used to obtain the length of the String?
Ans : length( ) method.
3) How do you concatenate Strings?
Ans : By using " + " operator.
4) Which method can be used to compare two strings for equality?
Ans : equals( ) method.
5) Which method can be used to perform a comparison between strings that ignores case differences?
Ans : equalsIgnoreCase( ) method.
6) What is the use of valueOf( ) method?
Ans : valueOf( ) method converts data from its internal format into a human-readable form.
7) What are the uses of toLowerCase( ) and toUpperCase( ) methods?
Ans : The method toLowerCase( ) converts all the characters in a string from uppercase to
lowercase.
The method toUpperCase( ) converts all the characters in a string from lowercase to
uppercase.
8) Which method can be used to find out the total allocated capacity of a StrinBuffer?
Ans : capacity( ) method.
9) Which method can be used to set the length of the buffer within a StringBuffer object?
Ans : setLength( ).
10) What is the difference between String and StringBuffer?
Ans : String objects are constants, whereas StringBuffer objects are not.
String class supports constant strings, whereas StringBuffer class supports growable, modifiable strings.
11) What are wrapper classes?
Ans : Wrapper classes are classes that allow primitive types to be accessed as objects.
12) Which of the following is not a wrapper class?
String
Integer
Boolean
Character
Ans : a.
13) What is the output of the following program?
public class Question {
public static void main(String args[]) {
String s1 = "abc";
String s2 = "def";
String s3 = s1.concat(s2.toUpperCase( ) );
System.out.println(s1+s2+s3);
}
}
abcdefabcdef
abcabcDEFDEF
abcdefabcDEF
None of the above
ANS : c.
14) Which of the following methods are methods of the String class?
delete( )
append( )
reverse( )
replace( )
Ans : d.
15) Which of the following methods cause the String object referenced by s to be changed?
s.concat( )
s.toUpperCase( )
s.replace( )
s.valueOf( )
Ans : a and b.
16) String is a wrapper class?
True
False
Ans : b.
17) If you run the code below, what gets printed out?
String s=new String("Bicycle");
int iBegin=1;
char iEnd=3;
System.out.println(s.substring(iBegin,iEnd));
Bic
ic
icy
error: no method matching substring(int,char)
Ans : b.
18) Given the following declarations
String s1=new String("Hello")
String s2=new String("there");
String s3=new String();
Which of the following are legal operations?
s3=s1 + s2;
s3=s1 - s2;
s3=s1 & s2
s3=s1 && s2
Ans : a.
19) Which of the following statements are true?
a)The String class is implemented as a char array, elements are addressed using the stringname[] convention
b) Strings are a primitive type in Java that overloads the + operator for concatenation
c) Strings are a primitive type in Java and the StringBuffer is used as the matching wrapper type
d) The size of a string can be retrieved using the length property.
Ans : b.
Top
--------------------------------------------------------------------------------
Exploring Java.lang
1) java.lang package is automatically imported into all programs.
True
False
Ans : a
2) What are the interfaces defined by java.lang?
Ans : Cloneable, Comparable and Runnable.
3) What are the constants defined by both Flaot and Double classes?
Ans : MAX_VALUE,
MIN_VALUE,
NaN ,
POSITIVE_INFINITY,
NEGATIVE_INFINITY and
TYPE.
4) What are the constants defined by Byte, Short, Integer and Long?
Ans : MAX_VALUE,
MIN_VALUE and
TYPE.
5) What are the constants defined by both Float and Double classes?
Ans : MAX_RADIX,
MIN_RADIX,
MAX_VALUE,
MIN_VALUE and
TYPE.
6) What is the purpose of the Runtime class?
Ans : The purpose of the Runtime class is to provide access to the Java runtime system.
7) What is the purpose of the System class?
Ans : The purpose of the System class is to provide access to system resources.
8) Which class is extended by all other classes?
Ans : Object class is extended by all other classes.
9) Which class can be used to obtain design information about an object?
Ans : The Class class can be used to obtain information about an object’s design.
10) Which method is used to calculate the absolute value of a number?
Ans : abs( ) method.
11) What are E and PI?
Ans : E is the base of the natural logarithm and PI is the mathematical value pi.
12) Which of the following classes is used to perform basic console I/O?
System
SecurityManager
Math
Runtime
Ans : a.
13) Which of the following are true?
The Class class is the superclass of the Object class.
The Object class is final.
The Class class can be used to load other classes.
The ClassLoader class can be used to load other classes.
Ans : c and d.
14) Which of the following methods are methods of the Math class?
absolute( )
log( )
cosine( )
sine( )
Ans : b.
15) Which of the following are true about the Error and Exception classes?
Both classes extend Throwable.
The Error class is final and the Exception class is not.
The Exception class is final and the Error is not.
Both classes implement Throwable.
Ans : a.
16) Which of the following are true?
The Void class extends the Class class.
The Float class extends the Double class.
The System class extends the Runtime class.
The Integer class extends the Number class.
Ans : d.
17) Which of the following will output -4.0
System.out.println(Math.floor(-4.7));
System.out.println(Math.round(-4.7));
System.out.println(Math.ceil(-4.7));
System.out.println(Math.Min(-4.7));
Ans : c.
18) Which of the following are valid statements
a) public class MyCalc extends Math
b) Math.max(s);
c) Math.round(9.99,1);
d) Math.mod(4,10);
e) None of the above.
Ans : e.
19) What will happen if you attempt to compile and run the following code?
Integer ten=new Integer(10);
Long nine=new Long (9);
System.out.println(ten + nine);
int i=1;
System.out.println(i + ten);
19 followed by 20
19 followed by 11
Error: Can't convert java lang Integer
d) 10 followed by 1
Ans : c.
Top
--------------------------------------------------------------------------------
Input/Output: Exploring Java.io
1) What is meant by Stream and what are the types of Streams and classes of the Streams?
Ans : A Stream is an abstraction that either produces or consumes information.
There are two types of Streams. They are:
Byte Streams : Byte Streams provide a convenient means for handling input and output of bytes.
Character Streams : Character Streams provide a convenient means for handling input and output of characters.
Byte Stream classes : Byte Streams are defined by using two abstract classes. They are:InputStream and OutputStream.
Character Stream classes : Character Streams are defined by using two abstract classes. They are : Reader and Writer.
2) Which of the following statements are true?
UTF characters are all 8-bits.
UTF characters are all 16-bits.
UTF characters are all 24-bits.
Unicode characters are all 16-bits.
Bytecode characters are all 16-bits.
Ans : d.
3) Which of the following statements are true?
When you construct an instance of File, if you do not use the filenaming semantics of the local machine, the constructor will throw an IOException.
When you construct an instance of File, if the corresponding file does not exist on the local file system, one will be created.
When an instance of File is garbage collected, the corresponding file on the local file system is deleted.
None of the above.
Ans : a,b and c.
4) The File class contains a method that changes the current working directory.
True
False
Ans : b.
5) It is possible to use the File class to list the contents of the current working directory.
True
False
Ans : a.
6) Readers have methods that can read and return floats and doubles.
True
False
Ans : b.
7) You execute the code below in an empty directory. What is the result?
File f1 = new File("dirname");
File f2 = new File(f1, "filename");
A new directory called dirname is created in the current working directory.
A new directory called dirname is created in the current working directory. A new file called filename is created in directory dirname.
A new directory called dirname and a new file called filename are created, both in the current working directory.
A new file called filename is created in the current working directory.
No directory is created, and no file is created.
Ans : e.
8) What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
Ans : The Reader/Writer class hierarchy is character-oriented and the InputStream/OutputStream class hierarchy is byte-oriented.
9) What is an I/O filter?
Ans : An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.
10) What is the purpose of the File class?
Ans : The File class is used to create objects that provide access to the files and directories of a local file system.
11) What interface must an object implement before it can be written to a stream as an object?
Ans : An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object.
12) What is the difference between the File and RandomAccessFile classes?
Ans : The File class encapsulates the files and directories of the local file system. The RandomAccessFile class provides the methods needed to directly access data contained in any part of a file.
13) What class allows you to read objects directly from a stream?
Ans : The ObjectInputStream class supports the reading of objects from input streams.
14) What value does read( ) return when it has reached the end of a file?
Ans : The read( ) method returns – 1 when it has reached the end of a file.
15) What value does readLine( ) return when it has reached the end of a file?
Ans : The readLine( ) method returns null when it has reached the end of a file.
16) How many bits are used to represent Unicode, ASCII, UTF-16 and UTF-8 characters?
Ans : Unicode requires 16-bits and ASCII requires 8-bits. Although the ASCII character set uses only 1-bits, it is usually represented as 8-bits. UTF-8 represents characters using 8, 16 and 18-bit patterns. UTF-16 uses 16-bit and larger bit patterns.
17) Which of the following are true?
The InputStream and OutputStream classes are byte-oriented.
The ObjectInputStream and ObjectOutputStream do not support serialized object input and output.
The Reader and Writer classes are character-oriented.
The Reader and Writer classes are the preferred solution to serialized object output.
Ans : a and c.
18) Which of the following are true about I/O filters?
Filters are supported on input, but not on output.
Filters are supported by the InputStream/OutputStream class hierarchy, but not by the Reader/Writer class hierarchy.
Filters read from one stream and write to another.
A filter may alter data that is read from one stream and written to another.
Ans : c and d.
19) Which of the following are true?
Any Unicode character is represented using 16-bits.
7-bits are needed to represent any ASCII character.
UTF-8 characters are represented using only 8-bits.
UTF-16 characters are represented using only 16-bits.
Ans : a and b.
20) Which of the following are true?
The Serializable interface is used to identify objects that may be written to an output stream.
The Externalizable interface is implemented by classes that control the way in which their objects are serialized.
The Serializable interface extends the Externalizable interface.
The Externalizable interface extends the Serializable interface.
Ans : a, b and d.
21) Which of the following are true about the File class?
A File object can be used to change the current working directory.
A File object can be used to access the files in the current directory.
When a File object is created, a corresponding directory or file is created in the local file system.
File objects are used to access files and directories on the local file system.
File objects can be garbage collected.
When a File object is garbage collected, the corresponding file or directory is deleted.
Ans : b, d and e.
22) How do you create a Reader object from an InputStream object?
Use the static createReader( ) method of InputStream class.
Use the static createReader( ) method of Reader class.
Create an InputStreamReader object, passing the InputStream object as an argument to the InputStreamReader constructor.
Create an OutputStreamReader object, passing the InputStream object as an argument to the OutputStreamReader constructor.
Ans : c.
23) Which of the following are true?
Writer classes can be used to write characters to output streams using different character encodings.
Writer classes can be used to write Unicode characters to output streams.
Writer classes have methods that support the writing of the values of any Java primitive type to output streams.
Writer classes have methods that support the writing of objects to output streams.
Ans : a and b.
24) The isFile( ) method returns a boolean value depending on whether the file object is a file or a directory.
True.
False.
Ans : a.
25) Reading or writing can be done even after closing the input/output source.
True.
False.
Ans : b.
26) The ________ method helps in clearing the buffer.
Ans : flush( ).
27) The System.err method is used to print error message.
True.
False.
Ans : a.
28) What is meant by StreamTokenizer?
Ans : StreamTokenizer breaks up InputStream into tokens that are delimited by sets of characters.
It has the constructor : StreamTokenizer(Reader inStream).
Here inStream must be some form of Reader.
29) What is Serialization and deserialization?
Ans : Serialization is the process of writing the state of an object to a byte stream.
Deserialization is the process of restoring these objects.
30) Which of the following can you perform using the File class?
a) Change the current directory
b) Return the name of the parent directory
c) Delete a file
d) Find if a file contains text or binary information
Ans : b and c.
31) How can you change the current working directory using an instance of the File class called FileName?
FileName.chdir("DirName").
FileName.cd("DirName").
FileName.cwd("DirName").
The File class does not support directly changing the current directory.
Ans : d.
Monday, April 14, 2008
Subscribe to:
Post Comments (Atom)
Archives
-
▼
2008
(201)
-
▼
April
(137)
- Q & A on Teoretical ANalysis of Router Systems
- Q & A on Application Level Gateways,
- Q & A on Ethernet Transceivers and "10BaseT",
- Q & A on 100BaseT and 10BaseT Cabling,
- Q & A on One LAN or Many LANs on a Campus,
- Q & A on ICMP and UDP "ping",
- Q & A on Netweork Analyzer Software,
- Q & A on Writing a Network Analyzer,
- Q & A on Interpreting IP Addresses in Octal,
- Q & A on New Top-Level Domains for DNS,
- Q & A on WAP and TCP.
- Q & A on TCP Segment Lengths.
- Q & A on TCP/IP Between Hosts on a Single Network.
- Q & A on "Internetworking with TCP/IP, Volume 1".
- Q & A on TPC/IP Layering Model,
- Q & A on IP Address Prefixes and Suffixes
- Q & A on "Net 0" IP Addresses.
- Q & A on Network Standard Byte Order and User Data.
- Q & A on Network Topologies,
- Q & A on Code for Internetworking with TCP/IP, Vol...
- Q & A on Attenuation in Ethernet Network Design
- Q & A on Hardware Technologies
- Computer Network Questions and Answers Part 1
- Computer Network Questions and Answers Part 2.
- Computer Network Questions and Answers Part 3.
- Computer Network Questions and Answers Part 4.
- Computer Network Questions and Answers Part 5,
- Computer Network Questions and Answers Part 6.
- Computer Network Questions and Answers Part 7.
- Computer Network Questions and Answers Part 8.
- Computer Network Questions and Answers Part 9,
- networking 146
- Basic Networkin Questions - 2, 142
- Basic Networkin Questions - 1 140
- Networking, Socket Programming, Inter-Process Comm...
- Networking Interview questions 134
- Networking Interview questions 130
- Computer Networking Interview Questions 128
- Networking Interview Questions 126
- JAVA QUESTIONS 125
- JAVA INTERVIEW QUESTIONS 120
- Core Java Test Paper1 116
- Java Interview Questions And Answers 112
- Java Interview Questions And Answers 108
- Advanced enterprise Java interview questions 106
- Advanced JAVA questions 104
- (FAQ) Advanced Java Interview Questions 100
- TrainJava Blog interviews 98
- Java Exceptions Questions 94
- Java technical interview guide - part 1 90
- Advanced Java Interview Questions And Answers 88
- Java J2EE Interview Questions and Answers 84
- Java Architect Interview Questions 82
- Advanced enterprise Java Interview Questions 80
- java script interview questions 78
- importent java interviews and answers
- importent study interview questions in java 74
- java total interview questions 68
- java interviews 66
- importent java interview questions 64
- java importent studying questions
- core java importent interviews 62
- corejava 60
- interviews of corejava 58
- corejava interviews 54
- core java more interviews 52
- core java inerviews 51
- core java interview questions 50
- corejava 50
- Core Java Interview Questions and Answers 48
- Core Java Interview Questions and Answers 46
- 300 Core java interview questions And Answer 44
- Java Interview Questions and Answers 40
- Java Interview Questions and Answers 34
- Java Interview Questions and Answers 32
- Java Interview Questions and Answers 30
- Java Interview Questions and Answers 28
- java interview questions 26
- java importent interview questions 24
- Java and Perl Web programming interview questions 23
- java interview questions 22
- Basic Java interview question 16
- Some Java Job Interview Questions 15
- Java Technical Questions with Answers 14
- Table of Contents:
- Visual Basic Interview Questions 13
- Java Interview Questions... 12
- Advanced enterprise Java Interview Questions
- Advanced Java Programming Interview Questions 10
- java questions 9
- Advanced Java Interview Questions 8
- Java interview questions 7
- JAVA INTERVIEW QUESTIONS (5)
- JAVA INTERVIEW QUESTIONS (4)
- JAVA INTERVIEW QUESTIONS (3)
- JAVA INTERVIEW QUESTIONS (2)
- JAVA INTERVIEW QUESTIONS 1
- Core Java Interview Questions books
- core java importent questions
- 30 simple Java questions
-
▼
April
(137)
No comments:
Post a Comment