Beruflich Dokumente
Kultur Dokumente
Answer Yes
How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8
Question
characters?
Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII
character set uses only 7 bits, it is usually represented as 8 bits. UTF-8
Answer
represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit
and larger bit patterns.
Question What is the difference between preemptive scheduling and time slicing?
Under preemptive scheduling, the highest priority task executes until it
enters the waiting or dead states or a higher priority task comes into
Answer existence. Under time slicing, a task executes for a predefined slice of time
and then reenters the pool of ready tasks. The scheduler then determines
which task should execute next, based on priority and other factors.
Question What are order of precedence and associativity, and how are they used?
Order of precedence determines the order in which operators are
Answer evaluated in expressions. Associatity determines whether an expression is
evaluated left-to-right or right-to-left
What is the difference between the Boolean & operator and the &&
Question
operator?
Answer If an expression involving the Boolean & operator is evaluated, both
operands are evaluated. Then the & operator is applied to the operand.
When an expression involving the && operator is evaluated, the first
operand is evaluated. If the first operand returns a value of true then the
second operand is evaluated. The && operator is then applied to the first
and second operands. If the first operand evaluates to false, the evaluation
of the second operand is skipped.
How are commas used in the intialization and iteration parts of a for
Question
statement?
Commas are used to separate multiple statements within the initialization
Answer
and iteration parts of a for statement.
Question What value does read() return when it has reached the end of a file?
Answer The read() method returns -1 when it has reached the end of a file.
Question What is the difference between a static and a non-static inner class?
A non-static inner class may have object instances that are associated
Answer with instances of the class's outer class. A static inner class does not have
any object instances.
Question When does the compiler supply a default constructor for a class?
The compiler supplies a default constructor for a class if no other
Answer
constructors are provided.
Question What class of exceptions are generated by the Java run-time system?
The Java runtime system generates RuntimeException and Error
Answer
exceptions.
Question What class allows you to read objects directly from a stream?
The ObjectInputStream class supports the reading of objects from input
Answer
streams.
Question What is the difference between a field variable and a local variable?
A field variable is a variable that is declared as a member of a class. A
Answer
local variable is a variable that is declared local to a method.
Question What is the difference between the File and RandomAccessFile classes?
The File class encapsulates the files and directories of the local file
Answer system. The RandomAccessFile class provides the methods needed to
directly access data contained in any part of a file.
Question Why can't I say just abs() or sin() instead of Math.abs() and Math.sin()?
The import statement does not bring methods into your local name
space. It lets you abbreviate class names, but not get rid of them
altogether. That's just the way it works, you'll get used to it. It's really a lot
safer this way. <br> However, there is actually a little trick you can use in
some cases that gets you what you want. If your top-level class doesn't
Answer
need to inherit from anything else, make it inherit from java.lang.Math.
That *does* bring all the methods into your local name space. But you
can't use this trick in an applet, because you have to inherit from
java.awt.Applet. And actually, you can't use it on java.lang.Math at all,
because Math is a "final" class which means it can't be extended.
Question What state does a thread enter when it terminates its processing?
Answer When a thread terminates its processing, it enters the dead state.
Question What is the difference between the >> and >>> operators?
The >> operator carries the sign bit when shifting right. The >>> zero-
Answer
fills bits that have been shifted out.
Does garbage collection guarantee that a program will not run out of
Question
memory?
Garbage collection does not guarantee that a program will not run out of
memory. It is possible for programs to use up memory resources faster
Answer
than they are garbage collected. It is also possible for programs to create
objects that are not subject to garbage collection
Question What value does readLine() return when it has reached the end of a file?
Answer The readLine() method returns null when it has reached the end of a file.
Question What happens to a static var that is defined within a method of a class?
Answer Can't do it. You'll get a compilation error
Question What is the diffrence between inner class and nested class?
When a class is defined within a scope od another class, then it becomes
inner class.
Answer
If the access modifier of the inner class is static, then it becomes nested
class.
Question How the private constructor is called in the main java programme?
Answer Have a look at this demo. public class Test2
{
private Test2()
{
System.out.println("Test2class");
}
What is the difference between the prefix and postfix forms of the ++
Question
operator?
The prefix form performs the increment operation and returns the value
of the increment operation. The postfix form returns the current value all
Answer
of the expression and then performs the increment operation on that
value.
How does a try statement determine which catch clause should be used
Question
to handle an exception?
When an exception is thrown within the body of a try statement, the
catch clauses of the try statement are examined in the order in which they
Answer
appear. The first catch clause that is capable of handling the exception is
executed. The remaining catch clauses are ignored.
Question What gives java it's "write once and run anywhere" nature?
Java is compiled to be a byte code which is the intermediate language
between source code and machine code. This byte code is not platorm
Answer specific and hence can be fed to any platform. After being fed to the JVM,
which is specific to a particular operating system, the code platform
specific machine code is generated thus making java platform independent.
You can create a String object as String str = "abc"; Why cant a button
Question
object be created as Button bt = "abc";? Explain
The main reason you cannot create a button by Button bt1= "abc"; is
because "abc" is a literal string (something slightly different than a String
object, by-the-way) and bt1 is a Button object. The only object in Java that
Answer
can be assigned a literal String is java.lang.String. Important to note that
you are NOT calling a java.lang.String constuctor when you type String s =
"abc";
Question What does the "abstract" keyword mean in front of a method? A class?
Abstract keyword declares either a method or a class. If a method has a
abstract keyword in front of it,it is called abstract method.Abstract method
has no body.It has only arguments and return type.Abstract methods act
Answer as placeholder methods that are implemented in the subclasses.
Abstract classes can't be instantiated.If a class is declared as abstract,no
objects of that class can be created.If a class contains any abstract method
it must be declared as abstract
Question What are the practical benefits, if any, of importing a specific class rather
than an entire package (e.g. import java.net.* versus import
java.net.Socket)?
It makes no difference in the generated class files since only the classes
that are actually used are referenced by the generated class file. There is
another practical benefit to importing single classes, and this arises when
two (or more) packages have classes with the same name. Take
java.util.Timer and javax.swing.Timer, for example. If I import java.util.*
and javax.swing.* and then try to use "Timer", I get an error while
Answer compiling (the class name is ambiguous between both packages). Let's say
what you really wanted was the javax.swing.Timer class, and the only
classes you plan on using in java.util are Collection and HashMap. In this
case, some people will prefer to import java.util.Collection and import
java.util.HashMap instead of importing java.util.*. This will now allow them
to use Timer, Collection, HashMap, and other javax.swing classes without
using fully qualified class names in.
Question What is the exact difference between Abstract classes and Interfaces?
Interfaces provide a form of multiple inheritance -- any number of
interfaces can be implemented A class can extend only one other class.
Answer Interfaces are limited to public methods and constants with no
implementation. Abstract classes can have a partial implementation,
protected parts, static methods, etc.
Question Can you throw (and re-throw) an exception inside a catch{} clause?
Yes, It will cause the exception to be passed to the handlers at the next-
Answer
higher level. All further catch clauses are ignored in the current try block.
Does the code in finally block get executed if there is an exception and a
Question
return statement in a catch block?
If an exception occurs and there is a return statement in catch block, the
finally block is still executed. The finally block will not be executed when
Answer the System.exit(1) statement is executed earlier or the system shut down
earlier or the memory is used up earlier before the thread goes to finally
block.
Question What are the Object and Class classes used for?
The Object class is the highest-level class in the Java class hierarchy. The
Answer Class class is used to represent the classes and interfaces that are loaded
by a Java program.
Question What class allows you to read objects directly from a stream?
The ObjectInputStream class supports the reading of objects from input
Answer
streams.
If a class is declared without any access modifiers, where may the class
Question
be accessed?
A class that is declared without any access modifiers is said to have
Answer package or friendly access. This means that the class can only be accessed
by other classes and interfaces that are defined within the same package.
You can use the ByteArray I/O streams as an intermediate place to write
and read bytes to/from the random access file and create Object I/O
streams from the byte streams to write/read the objects. You just have to
make sure that you have the entire object in the byte stream or
Answer
reading/writing the object will fail.
The code that uses a connection obtained from the connection pool is
another matter. If all it does is do a getData() type operation, there is no
harm in having more than one of them.
String s1 = "psn";
String s2 = s1.concat("prasad");
System.out.println(s1); // will remain same . no change. it prints "psn"
only
System.out.println(s2); // as you have assigned the newly created object
to s2
Question What is the difference between the File and RandomAccessFile classes?
The File class encapsulates the files and directories of the local file
Answer system. The RandomAccessFile class provides the methods needed to
directly access data contained in any part of a file.
Question What is the difference between Shallow Copy and Deep Copy?
Answer Shallow Copy:
If a shallow copy is performed on an object, then it gets copied but its
contained objects are not copied. Also any changes made in the cloned
object is automatically reflected in the shallowed copy object as well. An
example
When you execute the programme, the output will be "new name", this
shows that both st1 and st2 instances are the same, changing one changes
other too.
Deep Copy:
A deep copy occurs when an object is copied along with the objects to
which it refers to are also copied. This occurs only when every object in the
tree is serializable. An example
import java.io.*;
Question What are the different ways in which polymorphism can be achieved in
java?
Polymorphism can be acheived two ways
overloading - static binding/early binding
overriding - dynamic binding/late binding
e.g.
What would you use to compare two String variables - the operator == or
Question
the method equals()?
I'd use the method equals() to compare the values of the Strings and the
Answer == to check if two variables point at the
same instance of a String object.
What will the output of the following programme be? Look at the
programme carefully, we have an instance method and
static method (class method) defined in both Animal class and Cat class.
For class methods, the runtime system invokes the method defined in the
compile-time type of the reference on which the
method is called. In the example, the compile-time type of myAnimal is
Animal. Thus, the runtime system invokes the hide
method defined in Animal. For instance methods, the runtime system
invokes the method defined in the runtime type of the
reference on which the method is called. In the example, the runtime type
of myAnimal is Cat. Thus, the runtime system
invokes the override method defined in Cat.
An instance method cannot override a static method, and a static method
cannot hide an instance method.
class A {
void c() {
System.out.println("In A class");
}
}
Question
public class B extends A {
void d() {
System.out.println("In B class");
}