Short Interview Questions and Answers from Core Java

Interview questions from core java

java is an Object  Oriented Programming Language. Which is mostly used to develop Windows based Software  as well as Web Based Project. It is good to have good knowledge about a programming language and practical knowledge for developing program in that particular language. In the technical interview for the post of  Java Developer some basic questions are asked. In this post I am telling about questions at basic level. These questions are related to use of this and super Keyword operators, JVM and Jdk, Interface and access specifier, methods , class, java collections, seriazable in java , hastable , jsp servlet etc.

Q             Name Component subclasses that support painting.
A             The Canvas, Frame, Panel, and Applet classes support painting.

Q             What is a native method?
A             A native method is a method that is implemented in a language other than Java.

Q             How can you write a loop indefinitely?
A             for(;;)--for loop; while(true)--always true, etc.

Q             Can an anonymous class be declared as implementing an interface and extending a class?
A             An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.

Q         &nbsbsp;What is the purpose of finalization?
A             The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.

Q             Which class is the superclass for every class.
A             Object

Q             What is the difference between the Boolean & operator and the && operator?
A             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.
Operator & has no chance to skip both sides evaluation and && operator does. If asked why, give details as above.

Q             What is the GregorianCalendar class?
A             The GregorianCalendar provides support for traditional Western calendars.

Q             What is the SimpleTimeZone class?
A             The SimpleTimeZone class provides support for a Gregorian calendar.

Q             Which Container method is used to cause a container to be laid out and redisplayed?
A             validate()

Q             What is the Properties class?
A             The properties class is a subclass of Hashtable that can be read from or written to a stream. It also provides the capability to specify a set of default values to be used.

Q             What is the purpose of the Runtime class?
A             The purpose of the Runtime class is to provide access to the Java runtime system.

Q             What is the purpose of the System class?
A             The purpose of the System class is to provide access to system resources.

Q             What is the purpose of the finally clause of a try-catch-finally statement?
A             The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.

Q             What is the Locale class?
A             The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.

Q             What must a class do to implement an interface?
A             It must provide all of the methods in the interface and identify the interface in its implements clause.

Q             What is an abstract method?
A             An abstract method is a method whose implementation is deferred to a subclass. Or, a method that has no implementation (an interface of a method).

Q             What is a static method?
A             A static method is a method that belongs to the class rather than any object of the class and doesn't apply to an object or even require that any objects of the class have been instantiated.

Q             What is a protected method?
A             A protected method is a method that can be accessed by any method in its package and inherited by any subclass of its class.

Q             What is the difference between a static and a non-static inner class?
A             A non-static inner class may have object instances that are associated with instances of the class's outer class. A static inner class does not have any object instances.

Q             What is an object's lock and which object's have locks?
A             An object's lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object's lock. All objects and classes have locks. A class's lock is acquired on the class's Class object.

Q             When can an object reference be cast to an interface reference?
A             An object reference be cast to an interface reference when the object implements the referenced interface.

Q             What is the difference between a Window and a Frame?
A             The Frame class extends Window to define a main application window that can have a menu bar.

Q             What do heavy weight components mean?
A             Heavy weight components like Abstract Window Toolkit (AWT), depend on the local windowing toolkit. For example, java.awt.Button is a heavy weight component, when it is running on the Java platform for Unix platform, it maps to a real Motif button. In this relationship, the Motif button is called the peer to the java.awt.Button. If you create two Buttons, two peers and hence two Motif Buttons are also created. The Java platform communicates with the Motif Buttons using the Java Native Interface. For each and every component added to the application, there is an additional overhead tied to the local windowing system, which is why these components are called heavy weight.

Q             Which package has light weight components?
A             javax.Swing package. All components in Swing, except JApplet, JDialog, JFrame and JWindow are lightweight components.

Q             What are peerless components?
A             The peerless components are called light weight components.

Q             What is the difference between the Font and FontMetrics classes?
A             The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object.

Q             What happens when a thread cannot acquire a lock on an object?
A             If a thread attempts to execute a synchronized method or synchronized statement and is unable to acquire an object's lock, it enters the waiting state until the lock becomes available.

Q             What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
A             The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.

Q             What classes of exceptions may be caught by a catch clause?
A             A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.

Q             What is the difference between throw and throws keywords?
A             The throw keyword denotes a statement that causes an exception to be initiated. It takes the Exception object to be thrown as argument. The exception will be caught by an immediately encompassing try-catch construction or propagated further up the calling hierarchy.
The throws keyword is a modifier of a method that designates that exceptions may come out of the mehtod, either by virtue of the method throwing the exception itself or because it fails to catch such exceptions that a method it calls may throw.

Q             If a class is declared without any access modifiers, where may the class be accessed?
A             A class that is declared without any access modifiers is said to have 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.

Q             What is the Map interface?
A             The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with values.

Q             Does a class inherit the constructors of its superclass?
A             A class does not inherit constructors from any of its superclasses.

Q             Name primitive Java types.
A             The primitive types are byte, char, short, int, long, float, double, and boolean.

Q             Which class should you use to obtain design information about an object?
A             The Class class is used to obtain information about an object's design.

Q             How can a GUI component handle its own events?
A             A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener.

Q             How are the elements of a GridBagLayout organized?
A             The elements of a GridBagLayout are organized according to a grid. However, the elements are of different sizes and may occupy more thanrow or column of the grid. In addition, the rows and columns may have different sizes.

Q             What advantage do Java's layout managers provide over traditional windowing systems?
A             Java uses layout managers to lay out components in a consistent manner across all windowing platforms. Since Java's layout managers aren't tied to absolute sizing and positioning, they are able to accommodate platform-specific differences among windowing systems.

Q             What are the problems faced by Java programmers who don't use layout managers?
A             Without layout managers, Java programmers are faced with determining how their GUI will be displayed across multiple windowing systems and finding a common sizing and positioning that will work within the constraints imposed by each windowing system.

Q             What is the difference between static and non-static variables?
A             A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.

Q             What is the difference between the paint() and repaint() methods?
A             The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invoked by the AWT painting thread.

Q             What is the purpose of the File class?
A             The File class is used to create objects that provide access to the files and directories of a local file system.

Q             What restrictions are placed on method overloading?
A             Two methods may not have the same name and argument list but different return types.

Q             What restrictions are placed on method overriding?
A             Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides. The overriding method may not throw any exceptions that may not be thrown by the overridden method.

Q             What is casting?
A             There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.

Q             Name Container classes.
A             Window, Frame, Dialog, FileDialog, Panel, Applet, or ScrollPane

Q             What class allows you to read objects directly from a stream?
A             The ObjectInputStream class supports the reading of objects from input streams.

Q             How are this() and super() used with constructors?
A             this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.

Q             How is it possible for two String objects with identical values not to be equal under the == operator?
A             The == operator compares two objects to determine if they are the same object in memory. It is possible for two String objects to have the same value, but located indifferent areas of memory.

Q             What an I/O filter?
A             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.

Q             What is the Set interface?
A             The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements.

Q             What is the List interface?
A             The List interface provides support for ordered collections of objects.

Q             What is the purpose of the enableEvents() method?
A             The enableEvents() method is used to enable an event for a particular object. Normally, an event is enabled when a listener is added to an object for a particular event. The enableEvents() method is used by objects that handle events by overriding their event-dispatch methods.

Q             What is the difference between the File and RandomAccessFile classes?
A             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.

Q             What interface must an object implement before it can be written to a stream as an object?
A             An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object.

Q             What is the ResourceBundle class?
A             The ResourceBundle class is used to store locale-specific resources that can be loaded by a program to tailor the program's appearance to the particular locale in which it is being run.

Q             What is the difference between a Scrollbar and a ScrollPane?
A             A Scrollbar is a Component, but not a Container. A ScrollPane is a Container. A ScrollPane handles its own events and performs its own scrolling.

Q             What is a Java package and how is it used?
A             A Java package is a naming context for classes and interfaces. A package is used to create a separate name space for groups of classes and interfaces. Packages are also used to organize related classes and interfaces into a single API unit and to control accessibility to these classes and interfaces.

Q             What are the Object and Class classes used for?
A             The Object class is the highest-level class in the Java class hierarchy. The Class class is used to represent the classes and interfaces that are loaded by a Java program.

Q             What is Serialization and deserialization?
A             Serialization is the process of writing the state of an object to a byte stream.
Deserialization is the process of restoring these objects.

Q             what is tunneling?
A             Tunneling is a route to somewhere. For example, RMI tunneling is a way to make RMI application get through firewall. In CS world, tunneling means a way to transfer data.

Q             Does the code in finally block get executed if there is an exception and a return statement in a catch block?
A             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 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.

Q             How you restrict a user to cut and paste from the html page?
A             Using JavaScript to lock keyboard keys. It is one of solutions.

Q             Is Java a super set of JavaScript?
A             No. They are completely different. Some syntax may be similar.

Q             What is a Container in a GUI?
A             A Container contains and arranges other components (including other containers) through the use of layout managers, which use specific layout policies to determine where components should go as a function of the size of the container.

Q             How the object oriented approach helps us keep complexity of software development under control?
A             We can discuss such issue from the following aspects:
Objects allow procedures to be encapsulated with their data to reduce potential interference.
Inheritance allows well-tested procedures to be reused and enables changes to make once and have effect in all relevant places.
The well-defined separations of interface and implementation allow constraints to be imposed on inheriting classes while still allowing the flexibility of overriding and overloading.

Q             What is polymorphism?
A             Polymorphism allows methods to be written that needn't be concerned about the specifics of the objects they will be applied to. That is, the method can be specified at a higher level of abstraction and can be counted on to work even on objects of yet unconceived classes.

Q             What is design by contract?
A             The design by contract specifies the obligations of a method to any other methods that may use its services and also theirs to it. For example, the preconditions specify what the method required to be true when the method is called. Hence making sure that preconditions are. Similarly, post conditions specify what must be true when the method is finished, thus the called method has the responsibility of satisfying the post conditions.
In Java, the exception handling facilities support the use of design by contract, especially in the case of checked exceptions. The assert keyword can be used to make such contracts.

Q             What are use cases?
A             A use case describes a situation that a program might encounter and what behavior the program should exhibit in that circumstance. It is part of the analysis of a program. The collection of use cases should, ideally, anticipate all the standard circumstances and many of the extraordinary circumstances possible so that the program will be robust.



addressing modes types,1,advance-java,2,advancejava,1,aktu entrance exam,1,aktu exam schedule,1,ASP,1,bare machine,1,base register and limit register,1,C Programming,13,C Plus Plus,1,C Programming,6,C Programming MCQ,2,C Programming Questions,2,C programming study material for gate exam,10,Cache Memory,1,CBNST Program,1,Childcare,1,CJ,2,Cloud Computing,1,COA GATE Questions,1,components of use case diagram,1,Computer Architecture,2,Computer architecture based questions for gate exam,11,Computer Network,4,Computer Network Study Material,2,Computer network study material for gate,2,Computer Networks,6,Computer networks GATE Questions,1,Computer Science Study Material for Gate,19,computer science study material for gate exam,32,content based image retrieval content based image retrieval system,1,contiguous memory allocation,2,Core Java,8,COre Java Interview Questions,1,core java interviews questions,1,cyber crime report,1,Cyber crime status,1,cybercrime and security,1,cybercrime examples,1,Data Mining,1,Data Structure,2,Data Structure Questions,1,Data Transmission Architecture,1,Data Transmission in wsn,1,DBMS,5,dbms question paper,1,DE,1,Digital Electronics,1,DS,4,dynamic linking,1,dynamic linking in memory management,1,Dynamic memory allocation in c,1,Electroencephalogram,1,file management in operating system notes,1,FOC,1,Fundamenatl of Computer,1,Gate 2017,5,Gate 2017 Admit card,1,Gate 2017 Exam Schedule,1,Gate 2017 Syllabus,1,gate 2018,1,gate cse study material,1,gate practice set,10,gate study material for computer science,16,Gate study material for computer science 2017,1,GatePreviousYear,1,General,3,HCL Aptitude Test,1,HR Interview Questions,1,HTML,4,Image Processing,1,Important Date of Gate 2017 Exam,1,Information Security Policy,1,internal and external fragmentation,1,JS,1,lagrange's interpolation formula,1,lagrange's interpolation formula examples,1,MComputing,1,memory fragmentation,1,memory management,1,memory management questions and answer in os,1,Motivational,4,NCER,2,Numerical Techniques Lab,1,OOT,1,Operating System,12,Operating System Gate Questions,1,Operating System Objective Questions,4,Operating System Questions Bank,1,Operating system questions for gate,1,Operating System Study material,2,operating system study material for gate exam,16,Operating system tutorial,2,page swapping,1,paged memory allocation,1,paged memory allocation in operating system,1,paging technique of memory management .paging technique,1,paging technique of memory management program in c,1,Pointer in C,4,Process based question for gate,1,Quiz on non conventional energy resources,1,Regression testing,1,relocation in memory management,1,relocation registe,1,relocation register,1,resident monitor,1,resident monitor in operating system,1,routing table,1,segmentation in memory management,1,segmentation in memory management in operating system,1,Servlet,1,session tracking,1,session tracking in java,1,session tracking in servlet,1,Software Engineering,10,Software Engineering baes study material for gate,1,software engineering interview questions,1,Software Quality Assurance,3,software verification methods,1,SPM,1,Stack,1,Structure in C,1,Study Material for gate Computer Science,9,swapping in memory management,1,swapping in operating system,1,TCS Code Vita,1,TCS Interview Questions,1,Technical Interview,1,Technical Questions from DBMS,1,Thrashing in Operating System,1,Threads concept in operating system,1,Tips to Learn Coding,1,Top 30 Core Java Interview Questions with Answer,2,top down approach,1,top down approach in programming,1,Types of operating system,1,UML,1,use case diagram explanation,1,website uses cookies,1,what is cookies website,1,What is process control block ?,1,what is software testing?,1,Wireless Sensor Network,3,worst fit algorithm for memory allocation,1,XML,2,
Computer Science Junction: Short Interview Questions and Answers from Core Java
Short Interview Questions and Answers from Core Java
Interview questions from core java
Computer Science Junction
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share. STEP 2: Click the link you shared to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy