Short Interview Questions from Core Java

Interview Question from Core Java basic, interview questions questions are related to Variable, operators, JVM and Jdk, Interface and access specifier, methods , class, use of encapsulation,etc.

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 Variable, operators, JVM and Jdk, Interface and access specifier, methods , class, use of encapsulation,etc.


Q             How the private constructor is called in the main java program?  
A             Have a look at this demo.
public class Test2 {
            private Test2(){
            class Subclass extends Test2{
                        public Subclass(){
            public static void main(String[] args){
                        Subclass s = new Test2().new Subclass();
This works because an inner class is allowed to access private members of its enclosing instance, including the private constructor.

Q             Which is garbage collected first: Normal variables or static variables?  
A             Normal variables will be collected first. Lets take a simple example:
Class A is having a static variable s which is used by obj1, obj2 and obj3 of Class B. Each object of class B is having instance variables a and b (normal variables). Lets say if obj1 is not being in use since long time, then automatically the garbage collector will collect the space occupied by obj1. It will not destroy the static variable S as it is being used by the other two objects obj2 and obj3. Therefore only normal variables will be destroyed first.
We can say it in a simple statement that "Variables having less scope will be destroyed first"

Q             Difference between JRE And JVM AND JDK   
A             The "JDK" is the Java Development Kit. I.e., the JDK is bundle of software that you can use to develop Java based software. The "JRE" is the Java Runtime Environment. I.e., the JRE is an implementation of the Java Virtual Machine which actually executes Java programs. Typically, each JDK contains one (or more) JRE's along with the various development tools like the Java source compilers, bundling and deployment tools, debuggers, development libraries, etc.

Q             Is it necessary to initialize a final variable at the time of declaration?  
A             NO, it's not necessary.
Many text books say like this but that’s not true. Value of a final variable can be instance specific also, but in this case we have to initialize the variable in all the constructors. If we want to have a common final value of a variable for all the instances then there are two ways.
1.      Initialize the variable at class level (at the time of declaration) or
2.      just declare variable at class level and initialize it in any one of the instance blocks i.e.
a.             class A { final int a; {a=5;}}
b.             class A { final int a = 5;}

Q             What is the output of the following line? System.out.println(-5<<-2);  
A             At This point of time I am not sure about the answer. If anybody knows, please tell me at OR I shall be highly thankful to you.

Q             What is a compilation unit?  
A             A compilation unit is a Java source code file.

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             How can a dead thread be restarted?  
A             A dead thread cannot be restarted.

Q             What happens if an exception is not caught?  
A             An uncaught exception results in the uncaughtException () method of the thread's ThreadGroup being invoked, which eventually results in the termination of the program in which it is thrown.

Q             Which arithmetic operations can result in the throwing of an ArithmeticException?  
A             Integer / and % can result in the throwing of an ArithmeticException

Q             Can an abstract class be final?  
A             An abstract class may not be declared as final

Q             What happens if a try-catch-finally statement does not have a catch clause to handle an exception that is thrown within the body of the try statement?  
A             The exception propagates up to the next higher level try-catch statement (if any) or results in the program's termination

Q             What is numeric promotion?  
A             Numeric promotion is the conversion of a smaller numeric type to a larger numeric type, so that integer and floating-point operations may take place. In numerical promotion, byte, char, and short values are converted to int values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required

Q             What is the difference between a public and a non-public class?  
A             A public class may be accessed outside of its package. A non-public class may not be accessed outside of its package.

Q             To what value is a variable of the boolean type automatically initialized?  
A             The default value of the boolean type is false

Q             Can try statements be nested?  
A             Yes

Q             What is the difference between the prefix and postfix forms of the ++ operator?  
A             The prefix form performs the increment operation and returns the value of the increment operation. The postfix form returns the current value all of the expression and then performs the increment operation on that value.

Q             What is the purpose of a statement block?  
A             A statement block is used to organize a sequence of statements as a single statement group

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 modifiers may be used with a top-level class?  
A             A top-level class may be public, abstract, or final.

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             How does a try statement determine which catch clause should be used to handle an exception?  
A             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 appear. The first catch clause that is capable of handling the exception is executed. The remaining catch clauses are ignored.

Q             What are synchronized methods and synchronized statements?  
A             Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.

Q             What is the difference between an if statement and a switch statement?  
A             The if statement is used to select among two alternatives. It uses a boolean expression to decide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternative should be executed.

Q             What gives java it's "write once and run anywhere" nature?  
A             Java is compiled to be a byte code which is the intermediate language between source code and machine code. This byte code is not platform 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.

Q             What are the four corner stones of OOP?  
A             Abstraction, Encapsulation, Polymorphism and Inheritance

Q             Difference between a Class and an Object?  
A             A class is a definition or prototype whereas an object is an instance or living representation of the prototype

Q             What is the difference between method overriding and overloading?   
A             Overriding is a method with the same name and arguments as in a parent, whereas overloading is the same method name but different arguments

Q             What is a "stateless" protocol?  
A             Without getting into lengthy debates, it is generally accepted that protocols like HTTP are stateless i.e. there is no retention of state between a transaction which is a single request response combination

Q             What is constructor chaining and how is it achieved in Java?  
A             A child object constructor always first needs to construct its parent (which in turn calls its parent constructor.). In Java it is done via an implicit call to the no-args constructor as the first statement.

Q             What is passed by ref and what by value?  
A             All Java method arguments are passed by value. However, Java does manipulate objects by reference, and all object variables themselves are references

Q             You can create a String object as String str = "abc"; Why can’t a button object be created as Button bt = "abc";? Explain  
A             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 can be assigned a literal String is java.lang.String. Important to note that you are NOT calling a java.lang.String constructor when you type String s = "abc";

Q             What does the "abstract" keyword mean in front of a method? A class?  
A             Abstract keyword declares either a method or a class. If a method has an 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 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

Q             How many methods do u implement if implement the Serializable Interface?  
A             The Serializable interface is just a "marker" interface, with no methods of its own to implement. Other 'marker' interfaces are

Q             What are the practical benefits, if any, of importing a specific class rather than an entire package (e.g. import* versus import  
A             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 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.

Q             What is the difference between logical data independence and physical data independence?  
A             Logical Data Independence - meaning immunity of external schemas to changes in conceptual schema. Physical Data Independence - meaning immunity of conceptual schema to changes in the internal schema.

Q             What is user defined exception?  
A             Apart from the exceptions already defined in Java package libraries, user can define his own exception classes by extending Exception class.

Q             Difference Between Abstraction and Encapsulation  
A             Abstraction is removing some distinctions between objects, so as to show their commonalities.
Encapsulation is hiding the details of the implementation of an object so that there are no external dependencies on the particular implementation.

Q             What are Checked and Un-Checked Exceptions? Explain.  
A             Throwable extends Object (checked)
Exception extends Throwable (checked)
RuntimeException extends Exception (un-checked)
Error extends Throwable (un-checked)
So anything that extends Throwable or Exception (except RuntimeException) will be checked. Anything that extends Error or RuntimeException will be un-checked
Checked exceptions are problems that arise in correct code and may be due to technical problems such as IO problems or user mistakes such as opening a socket when the remote machine does not exist. Because these problems can occur at anytime, say due to network outage, you must have code that can handle and recover from these. In fact, the Java compiler checks that you have trapped them hence checked exceptions.
Runtime exceptions are typically bugs in the program. Errors are severe problems such as out of memory and sufficiently rare, that you are not required to handle them as they are usually unrecoverable.



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 from Core Java
Short Interview Questions from Core Java
Interview Question from Core Java basic, interview questions questions are related to Variable, operators, JVM and Jdk, Interface and access specifier, methods , class, use of encapsulation,etc.
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