Sei sulla pagina 1di 23

Q: What do you know about Java?

A: Java is a high-level programming language originally developed by Sun Microsystems and released in 1995. Java runs on a variety of platforms, such as Windo s, Mac !S, and the various versions of "#$%. Q: What are the supported platform by Java Programming Language? A: Java runs on a variety of platforms, such as Windo s, Mac !S, and the various versions of "#$%&'inu( li)e *+-"ni(, Sun Solaris, ,edhat 'inu(, "buntu, -ent!S etc. Q: List any five features of Java? A: Some features include !b.ect !riented, +latform $ndependent, ,obust, $nterpreted, Multithreaded Q: Why is Java Architectural eutral? A: $t/s compiler generates an architecture-neutral ob.ect file format hich ma)es the compiled code to be e(ecutable on many processors, ith the presence Java runtime system. Q: !ow Java enabled !igh Performance? A: Java uses Just-$n-0ime compiler to enable high performance. Just-$n-0ime compiler is a program that turns Java bytecode hich is a program that contains instructions that must be interpreted into instructions that can be sent directly to the processor. Q: Why Java is considered dynamic? A: $t is designed to adapt to an evolving environment. Java programs can carry e(tensive amount of run-time information that can be used to verify and resolve accesses to ob.ects on run-time. Q: What is Java "irtual #achine and how it is considered in conte$t of Java%s platform independent feature? A: When Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. 0his byte code is distributed over the eb and interpreted by virtual Machine 1J2M3 on hichever platform it is being run. Q: List two Java &'(%s? A: #etbeans, 4clipse etc Q: List some Java keywords)unlike *+ *,, keywords-? A: Some Java )ey ords are import, super, finally etc

Q: What do you mean by .b/ect? A: !b.ect is a runtime entity and it/s state is stored in fields and behavior is sho n via methods. Methods operate on an ob.ect5s internal state and serve as the primary mechanism for ob.ect-toob.ect communication. Q: 'efine class? A: 6 class is a blue print from hich individual ob.ects are created. 6 class can contain fields and methods to describe the behavior of an ob.ect. Q: What kind of variables a class can consist of? A: 6 class consist of 'ocal variable, instance variables and class variables. Q: What is a Local "ariable A: 2ariables defined inside methods, constructors or bloc)s are called local variables. 0he variable ill be declared and initiali7ed ithin the method and it ill be destroyed hen the method has completed. Q: What is a &nstance "ariable A: $nstance variables are variables ithin a class but outside any method. 0hese variables are instantiated hen the class is loaded. Q: What is a *lass "ariable A: 0hese are variables declared ith in a class, outside any method, ith the static )ey ord. Q: What is 0ingleton class? A: Singleton class control ob.ect creation, limiting the number to one but allo ing the fle(ibility to create more ob.ects if the situation changes. Q: What do you mean by *onstructor? A: -onstructor gets invo)ed hen a ne ob.ect is created. 4very class has a constructor. $f e do not e(plicitly rite a constructor for a class the .ava compiler builds a default constructor for that class. Q: List the three steps for creating an .b/ect for a class? A: 6n !b.ect is first declared, then instantiated and then it is initiali7ed. Q: What is the default value of byte datatype in Java?

A: 8efault value of byte datatype is 9. Q: What is the default value of float and double datatype in Java? A: 8efault value of float and double datatype in different as compared to -&-::. ;or float its 9.9f and for double it/s 9.9d Q: When a byte datatype is used? A: 0his data type is used to save space in large arrays, mainly in place of integers, since a byte is four times smaller than an int. Q: What is a static variable? A: -lass variables also )no n as static variables are declared ith the static )ey ord in a class, but outside a method, constructor or a bloc). Q: What do you mean by Access #odifier? A: Java provides access modifiers to set access levels for classes, variables, methods and constructors. 6 member has pac)age or default accessibility hen no accessibility modifier is specified. Q: What is protected access modifier? A: 2ariables, methods and constructors hich are declared protected in a superclass can be accessed only by the subclasses in other pac)age or any class ithin the pac)age of the protected members5 class. Q: What do you mean by synchroni1ed on Access #odifier? A: Java provides these modifiers for providing functionalities other than 6ccess Modifiers, synchroni7ed used to indicate that a method can be accessed by only one thread at a time. Q: According to Java .perator precedence+ which operator is considered to be with highest precedence? A: +ostfi( operators i.e 13 <= . is at the highest precedence. Q: "ariables used in a switch statement can be used with which datatypes? A: 2ariables used in a s itch statement can only be a byte, short, int, or char. Q: When parse&nt)- method can be used? A: 0his method is used to get the primitive data type of a certain String.

Q: Why is 0tring class considered immutable? A: 0he String class is immutable, so that once it is created a String ob.ect cannot be changed. Since String is immutable it can safely be shared bet een many threads , hich is considered very important for multithreaded programming. Q: Why is 0tring2uffer called mutable? A: 0he String class is considered as immutable, so that once it is created a String ob.ect cannot be changed. $f there is a necessity to ma)e alot of modifications to Strings of characters then String>uffer should be used. Q: What is the difference between 0tring2uffer and 0tring2uilder class? A: "se String>uilder henever possible because it is faster than String>uffer. >ut, if thread safety is necessary then use String>uffer ob.ects. Q: Which package is used for pattern matching with regular e$pressions? A: .ava.util.rege( pac)age is used for this purpose. Q: /ava3util3rege$ consists of which classes? A: .ava.util.rege( consists of three classes? +attern class, Matcher class and +atternSynta(4(ception class. Q: What is finali1e)- method? A: $t is possible to define a method that ill be called .ust before an ob.ect5s final destruction by the garbage collector. 0his method is called finali7e1 3, and it can be used to ensure that an ob.ect terminates cleanly. Q: What is an ($ception? A: 6n e(ception is a problem that arises during the e(ecution of a program. 4(ceptions are caught by handlers positioned along the thread5s method invocation stac). Q: What do you mean by *hecked ($ceptions? A: $t is an e(ception that is typically a user error or a problem that cannot be foreseen by the programmer. ;or e(ample, if a file is to be opened, but the file cannot be found, an e(ception occurs. 0hese e(ceptions cannot simply be ignored at the time of compilation. Q: ($plain 4untime ($ceptions?

A: $t is an e(ception that occurs that probably could have been avoided by the programmer. 6s opposed to chec)ed e(ceptions, runtime e(ceptions are ignored at the time of compliation. Q: Which are the two subclasses under ($ception class? A: 0he 4(ception class has t o main subclasses ? $!4(ception class and ,untime4(ception -lass. Q: When throws keyword is used? A: $f a method does not handle a chec)ed e(ception, the method must declare it using the thro s)ey ord. 0he thro s )ey ord appears at the end of a method5s signature. Q: When throw keyword is used? A: 6n e(ception can be thro n, either a ne ly instantiated one or an e(ception that you .ust caught, by using thro )ey ord. Q: !ow finally used under ($ception !andling? A: 0he finally )ey ord is used to create a bloc) of code that follo s a try bloc). 6 finally bloc) of code al ays e(ecutes, hether or not an e(ception has occurred. Q: What things should be kept in mind while creating your own e$ceptions in Java? A: While creating your o n e(ception?

6ll e(ceptions must be a child of 0hro able. $f you ant to rite a chec)ed e(ception that is automatically enforced by the *andle or 8eclare ,ule, you need to e(tend the 4(ception class. @ou ant to rite a runtime e(ception, you need to e(tend the ,untime4(ception class.

Q: 'efine &nheritance? A: $t is the process here one ob.ect acAuires the properties of another. With the use of inheritance the information is made manageable in a hierarchical order. Q: When super keyword is used? A: $f the method overrides one of its superclass5s methods, overridden method can be invo)ed through the use of the )ey ord super. $t can be also used to refer to a hidden field Q: What is Polymorphism?

A: +olymorphism is the ability of an ob.ect to ta)e on many forms. 0he most common use of polymorphism in !!+ occurs hen a parent class reference is used to refer to a child class ob.ect. Q: What is Abstraction? A: $t refers to the ability to ma)e a class abstract in !!+. $t helps to reduce the comple(ity and also improves the maintainability of the system. Q: What is Abstract class A: 0hese classes cannot be instantiated and are either partially implemented or not at all implemented. 0his class contains one or more abstract methods hich are simply method declarations ithout a body. Q: When Abstract methods are used? A: $f you ant a class to contain a particular method but you ant the actual implementation of that method to be determined by child classes, you can declare the method in the parent class as abstract. Q: What is (ncapsulation? A: $t is the techniAue of ma)ing the fields in a class private and providing access to the fields via public methods. $f a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields ithin the class. 0herefore encapsulation is also referred to as data hiding. Q: What is the primary benefit of (ncapsulation? A: 0he main benefit of encapsulation is the ability to modify our implemented code ithout brea)ing the code of others ho use our code. With this 4ncapsulation gives maintainability, fle(ibility and e(tensibility to our code. Q: What is an &nterface? A: 6n interface is a collection of abstract methods. 6 class implements an interface, thereby inheriting the abstract methods of the interface. Q: 5ive some features of &nterface? A: $t includes?

$nterface cannot be instantiated 6n interface does not contain any constructors. 6ll of the methods in an interface are abstract.

Q: 'efine Packages in Java? A: 6 +ac)age can be defined as a grouping of related types1classes, interfaces, enumerations and annotations 3 providing access protection and name space management. Q: Why Packages are used? A: +ac)ages are used in Java in-order to prevent naming conflicts, to control access, to ma)e searching&locating and usage of classes, interfaces, enumerations and annotations easier etc. Q: What do you mean by #ultithreaded program? A: 6 multithreaded program contains t o or more parts that can run concurrently. 4ach part of such a program is called a thread, and each thread defines a separate path of e(ecution. Q: What are the two ways in which 6hread can be created? A: 0hread can be created by? implementing ,unnable interface, e(tending the 0hread class. Q: What is an applet? A: 6n applet is a Java program that runs in a Web bro ser. 6n applet can be a fully functional Java application because it has the entire Java 6+$ at its disposal. Q: An applet e$tend which class? A: 6n applet e(tends .ava.applet.6pplet class. Q: ($plain garbage collection in Java? A: $t uses garbage collection to free the memory. >y cleaning those ob.ects that is no longer reference by any of the program. Q: 'efine immutable ob/ect? A: 6n immutable ob.ect can/t be changed once it is created. Q: ($plain the usage of this)- with constructors? A: $t is used ith variables or methods and used to call constructer of same class. Q: ($plain 0et &nterface? A: $t is a collection of element hich cannot contain duplicate elements. 0he Set interface contains only methods inherited from -ollection and adds the restriction that duplicate elements are prohibited.

Q: ($plain 6ree0et? A: $t is a Set implemented hen e ant elements in a sorted order. Q: What is *omparable &nterface? A: $t is used to sort collections and arrays of ob.ects using the collections.sort13 and .ava.utils. 0he ob.ects of the class implementing the -omparable interface can be ordered. Q: 'ifference between throw and throws? A: $t includes?

0hro is used to trigger an e(ception here as thro s is used in declaration of e(ception. Without thro s, -hec)ed e(ception cannot be handled here as chec)ed e(ception can be propagated ith thro s.

Q: ($plain the following line used under Java Program: public static void main 1String args< =3 A: 0he follo ing sho s the e(planation individually?

public? it is the access specifier. static? it allo s main13 to be called ithout instantiating a particular instance of a class. void? it affirns the compiler that no value is returned by main13. main13? this method is called at the beginning of a Java program. String args< =? args parameter is an instance array of class String

Q: 'efine J4( i3e3 Java 4untime (nvironment? A: Java ,untime 4nvironment is an implementation of the Java 2irtual Machine hich e(ecutes Java programs. $t provides the minimum reAuirements for e(ecuting a Java applicationB Q: What is JA4 file? A: J6, files is Java 6rchive fles and it aggregates many files into one. $t holds Java classes in a library. J6, files are built on C$+ file format and have ..ar file e(tension. Q: What is a WA4 file? A: 0his is Web 6rchive ;ile and used to store %M', .ava classes, and JavaServer pages. hich is used to distribute a collection of JavaServer +ages, Java Servlets, Java classes, %M' files, static Web pages etc.

Q: 'efine J&6 compiler? A: $t improves the runtime performance of computer programs based on bytecode. Q: What is the difference between ob/ect oriented programming language and ob/ect based programming language? A: !b.ect based programming languages follo all the features of !!+s e(cept $nheritance. JavaScript is an e(ample of ob.ect based programming languages Q: What is the purpose of default constructor? A: 0he .ava compiler creates a default constructor only if there is no constructor in the class. Q: *an a constructor be made final? A: #o, this is not possible. Q: What is static block? A: $t is used to initiali7e the static data member, $t is e(cuted before main method at the time of classloading. Q: 'efine composition? A: *olding the reference of the other class ithin some other class is )no n as composition. Q: What is function overloading? A: $f a class has multiple functions by same name but different parameters, it is )no n as Method !verloading. Q: What is function overriding? A: $f a subclass provides a specific implementation of a method that is already provided by its parent class, it is )no n as Method !verriding. Q: 'ifference between .verloading and .verriding? A: Method overloading increases the readability of the program. Method overriding provides the specific implementation of the method that is already provided by its super class parameter must be different in case of overloading, parameter must be same in case of overriding. Q: What is final class?

A: ;inal classes are created so the methods implemented by that class cannot be overridden. $t can/t be inherited. Q: What is ullPointer($ception? A: 6 #ull+ointer4(ception is thro n hen calling the instance method of a null ob.ect, accessing or modifying the field of a null ob.ect etc. Q: What are the ways in which a thread can enter the waiting state? A: 6 thread can enter the aiting state by invo)ing its sleep13 method, by bloc)ing on $!, by unsuccessfully attempting to acAuire an ob.ect5s loc), or by invo)ing an ob.ect5s ait13 method. $t can also enter the aiting state by invo)ing its 1deprecated3 suspend13 method. Q: !ow does multi7threading take place on a computer with a single *P8? A: 0he operating system5s tas) scheduler allocates e(ecution time to multiple tas)s. >y Auic)ly s itching bet een e(ecuting tas)s, it creates the impression that tas)s e(ecute seAuentially. Q: What invokes a thread9s run)- method? A: 6fter a thread is started, via its start13 method of the 0hread class, the J2M invo)es the thread5s run13 method hen the thread is initially e(ecuted. Q: 'oes it matter in what order catch statements for :ile ot:ound($ception and &.($ception are written? A: @es, it does. 0he ;ile#o;ound4(ception is inherited from the $!4(ception. 4(ception5s subclasses have to be caught first. Q: What is the difference between yielding and sleeping? A: When a tas) invo)es its yield13 method, it returns to the ready state. When a tas) invo)es its sleep13 method, it returns to the aiting state. Q: Why "ector class is used? A: 0he 2ector class provides the capability to implement a gro able array of ob.ects. 2ector proves to be very useful if you don5t )no the si7e of the array in advance, or you .ust need one that can change si7es over the lifetime of a program. Q: !ow many bits are used to represent 8nicode+ A0*&&+ 86:7;<+ and 86:7= characters? A: "nicode reAuires 1D bits and 6S-$$ reAuire E bits. 6lthough the 6S-$$ character set uses only E bits, it is usually represented as F bits. "0;-F represents characters using F, 1D, and 1F bit patterns. "0;-1D uses 1D-bit and larger bit patterns.

Q: What are Wrapper classes? A: 0hese are classes that allo primitive types to be accessed as ob.ects. 4(ample? $nteger, -haracter, 8ouble, >oolean etc. Q: What is the difference between a Window and a :rame? A: 0he ;rame class e(tends Windo to define a main application indo that can have a menu bar. Q: Which package has light weight components? A: .ava(.S ing pac)age. 6ll components in S ing, e(cept J6pplet, J8ialog, J;rame and JWindo are light eight components. Q: What is the difference between the paint)- and repaint)- methods? A: 0he paint13 method supports painting via a Graphics ob.ect. 0he repaint13 method is used to cause paint13 to be invo)ed by the 6W0 painting thread. Q: What is the purpose of :ile class? A: $t is used to create ob.ects that provide access to the files and directories of a local file system. Q: What is the difference between the 4eader>Writer class hierarchy and the &nput0tream>.utput0tream class hierarchy? A: 0he ,eader&Writer class hierarchy is character-oriented, and the $nputStream&!utputStream class hierarchy is byte-oriented. Q: Which class should you use to obtain design information about an ob/ect? A: 0he -lass class is used to obtain information about an ob.ect5s design and .ava.lang.-lass class instance represent classes, interfaces in a running Java application. Q: What is the difference between static and non7static variables? A: 6 static variable is associated ith the class as a hole rather than ith specific instances of a class. #on-static variables ta)e on uniAue values ith each ob.ect instance. Q: What is 0eriali1ation and deseriali1ation? A: Seriali7ation is the process of riting the state of an ob.ect to a byte stream. 8eseriali7ation is the process of restoring these ob.ects. Q: What are use cases?

A: $t is part of the analysis of a program and describes a situation that a program might encounter and hat behavior the program should e(hibit in that circumstance. Q: ($plain the use of sublass in a Java program? A: Sub class inherits all the public and protected methods and the implementation. $t also inherits all the default modifier methods and their implementation. Q: !ow to add menushortcut to menu item? A: $f there is a button instance called b1, you may add menu short cut by calling b1.setMnemonic15;53, so the user may be able to use 6lt:; to clic) the button. Q: *an you write a Java class that could be used both as an applet as well as an application? A: @es, .ust add a main13 method to the applet. Q: What is the difference between 0wing and AW6 components? A: 6W0 components are heavy- eight, hereas S ing components are light eight. *eavy eight components depend on the local indo ing tool)it. ;or e(ample, .ava.a t.>utton is a heavy eight component, hen it is running on the Java platform for "ni( platform, it maps to a real Motif button. Q: What9s the difference between constructors and other methods? A: -onstructors must have the same name as the class and can not return a value. 0hey are only called once hile regular methods could be called many times. Q: &s there any limitation of using &nheritance? A: @es, since inheritance inherits everything from the super class and interface, it may ma)e the subclass too clustering and sometimes error-prone hen dynamic overriding or dynamic overloading in some situation. Q: When is the Array0tore($ception thrown? A: When copying elements bet een different arrays, if the source or destination arguments are not arrays or their types are not compatible, an 6rrayStore4(ception ill be thro n. Q: *an you call one constructor from another if a class has multiple constructors? A: @es, use this13 synta(. Q: What9s the difference between the methods sleep)- and wait)-?

A: 0he code sleep1H9993B puts thread aside for e(actly t o seconds. 0he code ait1H9993, causes a ait of up to t o second. 6 thread could stop aiting earlier if it receives the notify13 or notify6ll13 call. 0he method ait13 is defined in the class !b.ect and the method sleep13 is defined in the class 0hread. Q: When Arithmetic($ception is thrown? A: 0he 6rithmetic4(ception is thro n hen integer is divided by 7ero or ta)ing the remainder of a number by 7ero. $t is never thro n in floating-point operations. Q: What is a transient variable? A: 6 transient variable is a variable that may not be seriali7ed during Seriali7ation and hich is initiali7ed by its default value during de-seriali7ation, Q: What is synchroni1ation? A: Synchroni7ation is the capability to control the access of multiple threads to shared resources. synchroni7ed )ey ord in .ava provides loc)ing hich ensures mutual e(clusive access of shared resource and prevent data race. Q: What is the *ollections AP&? A: 0he -ollections 6+$ is a set of classes and interfaces that support operations on collections of ob.ects. Q: 'oes garbage collection guarantee that a program will not run out of memory? A: Garbage collection does not guarantee that a program ill not run out of memory. $t is possible for programs to use up memory resources faster than they are garbage collected. $t is also possible for programs to create ob.ects that are not sub.ect to garbage collection. Q: 6he immediate superclass of the Applet class? A: +anel is the immediate superclass. 6 panel provides space in hich an application can attach any other component, including other panels. Q: Which Java operator is right associative? A: 0he I operator is right associative. Q: What is the difference between a break statement and a continue statement? A: 6 brea) statement results in the termination of the statement to hich it applies 1s itch, for, do, or hile3. 6 continue statement is used to end the current loop iteration and return control to the loop statement.

Q: &f a variable is declared as private+ where may the variable be accessed? A: 6 private variable may only be accessed ithin the class in hich it is declared. Q: What is the purpose of the 0ystem class? A: 0he purpose of the System class is to provide access to system resources. Q: List primitive Java types? A: 0he eight primitive types are byte, char, short, int, long, float, double, and boolean. Q: What is the relationship between clipping and repainting under AW6? A: When a indo is repainted by the 6W0 painting thread, it sets the clipping regions to the area of the indo that reAuires repainting. Q: Which class is the immediate superclass of the *ontainer class? A: -omponent class is the immediate super class. Q: What class of e$ceptions are generated by the Java run7time system? A: 0he Java runtime system generates ,untime4(ception and 4rror e(ceptions. Q: 8nder what conditions is an ob/ect9s finali1e)- method invoked by the garbage collector? A: 0he garbage collector invo)es an ob.ect5s finali7e13 method hen it detects that the ob.ect has become unreachable. Q: !ow can a dead thread be restarted? A: 6 dead thread cannot be restarted. Q: Which arithmetic operations can result in the throwing of an Arithmetic($ception? A: $nteger & and J can result in the thro ing of an 6rithmetic4(ception. Q: "ariable of the boolean type is automatically initiali1ed as? A: 0he default value of the boolean type is false. Q: *an try statements be nested? A: @es

Q: What are *lassLoaders? A: 6 class loader is an ob.ect that is responsible for loading classes. 0he class -lass'oader is an abstract class. Q: What is the difference between an &nterface and an Abstract class? A: 6n abstract class can have instance methods that implement a default behavior. 6n $nterface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. 6n interface has all public members and no implementation. Q: What will happen if static modifier is removed from the signature of the main method? A: +rogram thro s K#oSuchMethod4rrorK error at runtime . Q: What is the default value of an ob/ect reference declared as an instance variable? A: #ull, unless it is defined e(plicitly. Q: *an a top level class be private or protected? A: #o, a top level class can not be private or protected. $t can have either KpublicK or no modifier. Q: Why do we need wrapper classes? A: We can pass them around as method parameters here a method e(pects an ob.ect. $t also provides utility methods. Q: What is the difference between error and an e$ception? A: 6n error is an irrecoverable condition occurring at runtime. Such as !ut!fMemory error. 4(ceptions are conditions that occur because of bad input etc. e.g. ;ile#ot;ound4(ception ill be thro n if the specified file does not e(ist. Q: &s it necessary that each try block must be followed by a catch block? A: $t is not necessary that each try bloc) must be follo ed by a catch bloc). $t should be follo ed by either a catch bloc) or a finally bloc). Q: When a thread is created and started+ what is its initial state? A: 6 thread is in the ready state as initial state after it has been created and started. Q: What is the Locale class?

A: 0he 'ocale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region. Q: What are synchroni1ed methods and synchroni1ed statements? A: Synchroni7ed methods are methods that are used to control access to an ob.ect. 6 synchroni7ed statement can only be e(ecuted after a thread has acAuired the loc) for the ob.ect or class referenced in the synchroni7ed statement. Q: What is runtime polymorphism or dynamic method dispatch? A: ,untime polymorphism or dynamic method dispatch is a process in hich a call to an overridden method is resolved at runtime rather than at compile-time. $n this process, an overridden method is called through the reference variable of a superclass. Q: What is 'ynamic 2inding)late binding-? A: >inding refers to the lin)ing of a procedure call to the code to be e(ecuted in response to the call. 8ynamic binding means that the code associated ith a given procedure call is not )no n until the time of the call at run-time. Q: *an constructor be inherited? A: #o, constructor cannot be inherited. Q: What are the advantages of ArrayList over arrays? A: 6rray'ist can gro dynamically and provides more po erful insertion and search mechanisms than arrays. Q: Why deletion in LinkedList is fast than ArrayList? A: 8eletion in lin)ed list is fast because it involves only updating the ne(t pointer in the node before the deleted node and updating the previous pointer in the node after the deleted node. Q: !ow do you decide when to use ArrayList and LinkedList? A: $f you need to freAuently add and remove elements from the middle of the list and only access the list elements seAuentially, then 'in)ed'ist should be used. $f you need to support random access, ithout inserting or removing elements from any place other than the end, then 6rray'ist should be used. Q: What is a "alues *ollection "iew ? A: $t is a collection returned by the values13 method of the Map $nterface, $t contains all the ob.ects present as values in the map.

Q: What is dot operator? A: 0he dot operator1.3 is used to access the instance variables and methods of class ob.ects.$t is also used to access classes and sub-pac)ages from a pac)age. Q: Where and how can you use a private constructor? A: +rivate constructor is used if you do not ant other classes to instantiate the ob.ect and to prevent subclassing.0 Q: What is type casting? A: 0ype casting means treating a variable of one type as though it is another type. Q: 'escribe life cycle of thread? A: 6 thread is a e(ecution in a program. 0he life cycle of a thread include?

#e born state ,unnable state ,unning state >loc)ed state 8ead state

Q: What is the difference between the ?? and ??? operators? A: 0he LL operator carries the sign bit hen shifting right. 0he LLL 7ero-fills bits that have been shifted out. Q: Which method of the *omponent class is used to set the position and si1e of a component? A: set>ounds13 method is used for this purpose. Q: What is the range of the short type? A: 0he range of the short type is -1HM153 to HM15 - 1. Q: What is the immediate superclass of #enu? A: Menu$tem class Q: 'oes Java allow 'efault Arguments?

A: #o, Java does not allo 8efault 6rguments. Q: Which number is denoted by leading 1ero in /ava? A: !ctal #umbers are denoted by leading 7ero in .ava, e(ample? 9D Q: Which number is denoted by leading @$ or @A in /ava? A: *e(adecimal #umbers are denoted by leading 9( or 9% in .ava, e(ample? 9%; Q: 2reak statement can be used as labels in Java? A: @es, an e(ample can be break one; Q: Where import statement is used in a Java program? A: $mport statement is allo ed at the beginning of the program file after pac)age statement. Q: ($plain suspend)- method under 6hread class? A: $t is used to pause or temporarily stop the e(ecution of the thread. Q: ($plain isAlive)- method under 6hread class? A: $t is used to find out hether a thread is still running or not. Q: What is current6hread)-? A: $t is a public static method used to obtain a reference to the current thread. Q: ($plain main thread under 6hread class e$ecution? A: 0he main thread is created automatically and it begins to e(ecute immediately hen a program starts. $t ia thread from hich all other child threads originate. Q: Life cycle of an applet includes which steps? A: 'ife cycle involves the follo ing steps?

$nitiali7ation Starting Stopping 8estroying +ainting

Q: Why is the role of init)- method under applets? A: $t initiali7es the applet and is the first method to be called. Q: Which method is called by Applet class to load an image? A: get$mage1",' ob.ect, filename3 is used for this purpose. Q: 'efine code as an attribute of Applet? A: $t is used to specify the name of the applet class. Q: 'efine canvas? A: $t is a simple dra ing surface hich are used for painting images or to perform other graphical operations. Q: 'efine etwork Programming? A: $t refers to riting programs that e(ecute across multiple devices 1computers3, in hich the devices are all connected to each other using a net or). Q: What is a 0ocket? A: Soc)ets provide the communication mechanism bet een t o computers using 0-+. 6 client program creates a soc)et on its end of the communication and attempts to connect that soc)et to a server. Q: Advantages of Java 0ockets? A: Soc)ets are fle(ible and sufficient. 4fficient soc)et based programming can be easily implemented for general communications. $t cause lo net or) traffic. Q: 'isadvantages of Java 0ockets? A: Soc)et based communications allo s only to send pac)ets of ra data bet een applications. >oth the client-side and server-side have to provide mechanisms to ma)e the data useful in any ay. Q: Which class is used by server applications to obtain a port and listen for client reBuests? A: .ava.net.ServerSoc)et class is used by server applications to obtain a port and listen for client reAuests Q: Which class represents the socket that both the client and server use to communicate with each other?

A: .ava.net.Soc)et class represents the soc)et that both the client and server use to communicate ith each other. Q: Why 5enerics are used in Java? A: Generics provide compile-time type safety that allo s programmers to catch invalid types at compile time. Java Generic methods and generic classes enable programmers to specify, ith a single method declaration, a set of related methods or, ith a single class declaration, a set of related types. Q: What environment variables do & need to set on my machine in order to be able to run Java programs? A: -'6SS+60* and +60* are the t o variables. Q: &s there any need to import /ava3lang package? A: #o, there is no need to import this pac)age. $t is by default loaded internally by the J2M. Q: What is ested top7level class? A: $f a class is declared ithin a class and specify the static modifier, the compiler treats the class .ust li)e any other top-level class. #ested top-level class is an $nner class. Q: What is ($ternali1able interface? A: 4(ternali7able is an interface hich contains t o methods read4(ternal and rite4(ternal. 0hese methods give you a control over the seriali7ation mechanism. Q: &f 0ystem3e$it )@-C is written at the end of the try block+ will the finally block still e$ecute? A: #o in this case the finally bloc) ill not e(ecute because hen you say System.e(it 193B the control immediately goes out of the program, and thus finally never e(ecutes. Q: What is daemon thread? A: 8aemon thread is a lo priority thread hich runs intermittently in the bac) ground doing the garbage collection operation for the .ava runtime system. Q: Which method is used to create the daemon thread? A: set8aemon method is used to create a daemon thread. Q: Which method must be implemented by all threads?

A: 6ll tas)s must implement the run13 method Q: What is the 5regorian*alendar class? A: 0he Gregorian-alendar provides support for traditional Western calendars Q: What is the 0imple6imeDone class? A: 0he Simple0imeCone class provides support for a Gregorian calendar . Q: What is the difference between the si1e and capacity of a "ector? A: 0he si7e is the number of elements actually stored in the vector, hile capacity is the ma(imum number of elements it can store at a given instance of time. Q: *an a vector contain heterogenous ob/ects? A: @es a 2ector can contain heterogenous ob.ects. >ecause a 2ector stores everything in terms of !b.ect. Q: What is an enumeration? A: 6n enumeration is an interface containing methods for accessing the underlying data structure from hich the enumeration is obtained. $t allo s seAuential access to all the elements stored in the collection. Q: What is difference between Path and *lasspath? A: +ath and -lasspath are operating system level environment variales. +ath is defines here the system can find the e(ecutables1.e(e3 files and classpath is used to specify the location of .class files. Q: *an a class declared as private be accessed outside it9s package? A: #o, it5s not possible to accessed outside it5s pac)age. Q: What are the restriction imposed on a static method or a static block of code? A: 6 static method should not refer to instance variables ithout creating an instance and cannot use KthisK operator to refer the instance. Q: *an an &nterface e$tend another &nterface? A: @es an $nterface can inherit another $nterface, for that matter an $nterface can e(tend more than one $nterface.

Q: Which ob/ect oriented *oncept is achieved by using overloading and overriding? A: +olymorphism Q: What is an ob/ect9s lock and which ob/ect9s have locks? A: 6n ob.ect5s loc) is a mechanism that is used by multiple threads to obtain synchroni7ed access to the ob.ect. 6 thread may e(ecute a synchroni7ed method of an ob.ect only after it has acAuired the ob.ect5s loc). Q: What is 'owncasting? A: $t is the casting from a general to a more specific type, i.e. casting do n the hierarchy. Q: What are order of precedence and associativity and how are they used? A: !rder of precedence determines the order in hich operators are evaluated in e(pressions. 6ssociatity determines hether an e(pression is evaluated left-to-right or right-to-left. Q: &f a method is declared as protected+ where may the method be accessed? A: 6 protected method may only be accessed by classes or interfaces of the same pac)age or by subclasses of the class in hich it is declared. Q: What is the difference between inner class and nested class? A: When a class is defined ithin a scope of another class, then it becomes inner class. $f the access modifier of the inner class is static, then it becomes nested class. Q: What restrictions are placed on method overriding? A: !verridden methods must have the same name, argument list, and return type. 0he overriding method may not limit the access of the method it overrides. Q: What is constructor chaining and how is it achieved in Java? A: 6 child ob.ect constructor al ays first needs to construct its parent. $n Java it is done via an implicit call to the no-args constructor as the first statement. Q: *an a double value be cast to a byte? A: @es, a double value can be cast to a byte. Q: !ow does a try statement determine which catch clause should be used to handle an e$ception?

A: When an e(ception is thro n ithin the body of a try statement, the catch clauses of the try statement are e(amined in the order in hich they appear. 0he first catch clause that is capable of handling the e(ception is e(ecuted. 0he remaining catch clauses are ignored. Q: What will be the default values of all the elements of an array defined as an instance variable? A: $f the array is an array of primitive types, then all the elements of the array ill be initiali7ed to the default value corresponding to that primitive type.

Potrebbero piacerti anche