Sunteți pe pagina 1din 8

| 




  
ë The thought process that one should use to arrive at an
answer is purposely illustrated above. Without knowing the
exact answer beforehand, you can arrive at an approximate
one by applying some basic knowledge of Java. Most
interviewers wouldn't expect you to know how
System.out.println() works off the top of your head, but
would rather see you use your basic Java knowledge to
arrive at an answer that's close to exact.
ë The more exact answer is this: inside the System class is the
declaration of 'out' that looks like: 'public static final
PrintStream out', and inside the Prinstream class is a
declaration of 'println()' that has a method signature that
looks like: 'public void println()'.



  

  !
  !
"# 
 !$
 
 !!

ë 0iven the previous information, it should be
easier to deduce an answer to the question. Since
the JVM must translate the bytecode into
machine language, and since the machine
language depends on the operating system being
used, it is clear that the JVM is platform
(operating system) dependent. This fact can be
verified by trying to download the JVM - you will
be given a list of JVM's corresponding to different
operating systems, and you will obviously pick
whichever JVM is targeted for the operating
system that you are running.
$



 
  ! 

 
  !
ë the differences between overloading and
overriding. When overloading, one must
change either the type or the number of
parameters for a method that belongs to the
same class. But, à  a method means
that a method inherited from a base class is
what's being changed.
' 
  !

( (
ë Java always provides a default, no-argument,
public constructor if no programmer-defined
constructor exists. Creating a private no-
argument constructor essentially prevents the
usage of that default constructor, thereby
preventing a caller from creating an instance
of the class. Note that the private constructor
may even be empty.
| ' 
 

(

$


 $)
( ( 
ë The term 'class' refers to the actual written piece of
code in which the class is defined. The properties of a
class do not change before, during, or after the
execution of a program.

ë The term 'object' however refers to an


actual i   of a class. Every object must belong to
a class.
ë we can say that whereas a class is a general concept
(like an Animal), an object is a very specific
embodiment of that class, with a limited lifespan (like a
lion, cat, or a zebra).
|  

' ' 


 


 
(     (
$

ë When applied to a method definition the final modifier
indicates that the method may not be overridden in a
derived class.
ë When applied to a class, the final modifier indicates
that the class can not be used as a base class to derive
any class from it. It's also good to point out in an
interview that the final modifier, when applied to
either a class or a method, turns off late binding, and
thus prevents polymorphism.
ë And, when applied to an instance variable, the final
modifier simply means that the instance variable can't
be changed.
|  

 (  

*$
   

$

ë A class is serializable when it implements the Serializable interface, which
is an interface residing in the java.io package. If a class is serializable, it
means that any object of that class can be converted into a sequence of
bits so that it can be written to some storage medium (like a file), or even
transmitted across a network. Here's what a serializable class looks like:
ë public class SomeClass implements java.io.Serializable { // this class is
serializable ... }
ë Suppose that there's a particular object data member (like a password)
that we may not want to get saved when an object is serialized. Then,
what we can do is declare that data member to be "transient". A transient
variable is not a part of the persistent state of a serialized object. Here's
what a transient variable looks like:
ë public class SomeClass implements java.io.Serializable { // this variable will
not persist private transient String password; ... }
ë So, if we were to write a serializable object to a file, any transient variable
that was part of that object will à be saved to the file.

S-ar putea să vă placă și