Saturday 24 August 2013

Top Most Core Java Popular Interview Questions - 2

41
Q
What does wait method do ?


A
It causes current thread to wait until either another thread invokes notify or notifyAll method of the current object, or a specified amount of time has elapsed.





42
Q
What are the different states of a thread ?


A
The different thread states are ready, running, waiting and dead.





43
Q
What is the difference between static and non static inner class ?


A
A non-static inner class can have an object instances that are associated with instances of the class's outer class. A static inner class can not have any object instances.





44
Q
What is the difference between String and StringBuffer class ?


A
Strings are immutable (constant), their values cannot be changed after they are created. StringBuffer supports mutable objects.





45
Q
Which is the base class for all classes ?



java.lang.Object.


Q
What is the difference between readers and streams?


A
Readers are character oriented where streams are byte oriented.  The readers are having full support for Unicode data.





46
Q
What is constructor chaining ?


A
When a constructor of a class is executed it will automatically call the default constructor of the super class (if no explicit call to any of the super class constructor) till the root of the hierarchy.





47
Q
What are the different primitive data type in java ?


A
There are 8 primitive types in java. boolean , char, byte, short, int long, float, double.





48
Q
What is static ?


A
static means one per class.  static variables are created when the class loads. They are associated with the object.  In order to access a static we don't need objects. We can directly access static methods and variable by calling classname.variablename.





49
Q
Why we cannot override static methods?


A
Static means they are associated with a class. In static methods , the binding mechanism is static binding. So it must be available at the compile time.





50
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. There will be only one value for static variable for all instances of that class.  Non-static variables take on unique values with each object instance.





51
Q
When does a compiler supplies a default constructor for a class?


A
If there is no other constructor exist in a class, the compiler will supply a default constructor.





52
Q
What are the restrictions placed on overriding a method ?


A The overridden method have the exact signature of the super class method, including the return type. The access specifier cannot be less restrictive than the super class method. We cannot throw any new exceptions in overridden method.
53
Q
What are the restrictions placed on overloading a method ?


A
Overloading methods must differ in their parameter list, or number of parameters.





54
Q
What is casting ?


A
Casting means converting one type to another. There are mainly two types of casting. Casting between primitive types and casting between object references. Casting between primitive numeric types is used to convert larger data types to smaller data types. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.





55
Q
What is the difference between == and equals ?


A
The equals method can be considered to perform a deep comparison of the value of an object, whereas the == operator performs a shallow comparison.  If we are not overriding the equals method both will give the same result. == will is used to compare the object references. It is used to check whether two objects are points to the same reference.





56
Q
What is a void return type ?


A
A void indicates that the method will not return anything.





57
Q
What will happen if an exception is not caught ?


A
An uncaught exception results in the uncaughtException() method of the thread's ThreadGroup, which results in the termination of the program.

58
Q
What are the different ways in which a thread can enter into waiting state?


A
There are three ways for a thread to enter into waiting state. By invoking its sleep() method, by blocking on I/O, by unsuccessfully attempting to acquire an object's lock, or by invoking an object's wait() method.





59
Q
What is a ResourceBundle class?


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

60
Q
What is numeric promotion?


A
Numeric promotion is the conversion of a smaller numeric type to a larger numeric type. In numerical promotion, byte, char, and short values are converted to int  values. The int, long and float values are converted to the desired types if required.





61
Q
What is the difference between the prefix and postfix forms of the ++ operator?


A
The prefix form first performs the increment operation and then returns the value of the increment operation. The postfix form first returns the current value of the expression and then performs the increment operation on that value.





62
Q
What are synchronized methods and synchronized statements?


A
Synchronized methods are methods that are declared with the keyword synchronized. A thread executes a synchronized method only after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. It is a block of code declared with synchronized keyword. A synchronized statement can be executed only after a thread has acquired the lock for the object or class referenced in the synchronized statement.





63
Q
How can we create a thread?


A
A thread can be created by extending Thread class or by implementing Runnable interface. Then we need to override the method public void run().





64
Q
What is the difference between a switch statement and an if statement?


A
If statement is used to select from two alternatives. It uses a boolean expression to decide which alternative should be executed. The expression in if must be a boolean value.  The switch statement is used to select from multiple alternatives.  The case values must be promoted to an  to int value. 

65
Q
What is hashCode?


A
The hashcode of a Java Object is simply a number (32-bit signed int) that allows an object to be managed by a hash-based data structure. A hashcode should be, equal for equal object (this is mandatory!) ,  fast to compute based on all or most of the internal state of an object, use all or most of the space of 32-bit integers in a fairly uniform way , and likely to be different even for objects that are very similar. If you are overriding hashCode you need to override equals method also.





66
Q
What is 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.





67
Q
What is the difference between RandomAccessFile and File?


A
The File class contains information  the files and directories of the local file system. The RandomAccessFile class contains  the methods needed to directly access data contained in any part of a file.





68
Q
What is final ?


A
A final is a keyword in java. If final keyword is applied to a variable, then the variable will become a constant. If it applied to method, sub classes cannot override the method. If final keyword is applied to a class we cannot extend from that class.





69
Q
What is the difference among JVM Spec, JVM Implementation, JVM Runtime ?


A
The JVM spec is the blueprint for the JVM generated and owned by Sun. The JVM implementation is the actual implementation of the spec by a vendor and the JVM runtime is the actual running instance of a JVM implementation





70
Q
How is the difference between thread and process?


A
A process runs in its own address space. No two processes share their address space. Threads will run in the same address space of the process that owns them.





71
Q
What is the difference between Vector and ArrayList ?


A
Vector is synchronized, ArrayList is not. Vector is having a constructor to specify the incremental capacity. But ArrayList don't have. By default Vector grows by 100% but ArrayList grows by 50% only.





72
Q
What is the difference between Hashtable and HashMap ?


A
Hashtable is synchronized . but HashMap is not synchronized.  Hashtable does not allow null values , but HashMap allows null values.





73
Q
What are the access modifiers available in Java.


A
Access modifier specify where a method or attribute can be used. Public is accessible from anywhere. Protected is accessible from the same class and its subclasses. Package/Default are accessible from the same package. Private is only accessible from within the class.





74
Q
Why java is said to be pass-by-value ?


A
When assigning an object to a variable, we are actually assigning the memory address of that object to the variable. So the value passed is actually the memory location of the object. This results in object aliasing, meaning you can have many variables referring to the same object on the heap.

75
Q
What do you mean by immutable ? How to create an immutable object ?


A
Immutability means an object cannot be modified after it has been initialized.  There will not be any setter methods in an immutable class. And normally these classes will be final.





76
Q
What is class loader in java ?


A
A class loader is a class that is responsible for loading the class. All JVM contains one class loader called primordial class loader.





77
Q
What is a weak reference ?


A
A weak reference is the one that does nor prevent the referenced object from being garbage collected. The weak reference will not keep the object that it refers to alive. A weak reference is not counted as a reference in garbage collection. This will make the memory use more effective.





78
Q
What is object cloning?


A
It is the process of duplicating an object so that two identical objects will exist in the memory at the same time.





79
Q
What is object pooling?


A
Creating a large number of identical short lived objects is called object pooling. This helps to minimize the need of garbage collection and makes the memory use more effective.





LinkWithin

Related Posts Plugin for WordPress, Blogger...

Labels

Core Java programming core java interview question Core Java Faq's Servlets coding database jsp-servlet spring Java linux unix interview questions java investment bank Web Services Interview investment bank mysql Senior java developer interviews best practices java collection tutorial RMI SQL Eclipse FIX protocol tutorial tibco J2EE groovy java questions SCJP grails java 5 tutorial jdbc beginner error and exception Design Patterns Java Programming Tutorials fundamentals general object oriented programming xml Java Programs Hibernate Examples Flex JAMon Java xml tutorial logging Jsp Struts 2.0 Sybase and SQL Server debugging java interviews performance FIX Protocol interview questions JUnit testing WebSphere date and time tutorial experienced java IO tutorial java concurrency thread Ejb Freshers Papers IT Management Java Exapmle Java Script SQL and database tutorial examples Scwcd ant tutorials concurrency example and tutorial future state homework java changes java threading tricky Agile Business of IT Development JSTL Java JSON tutorial Java multithreading Tutorials PM Scrum data structure and algorithm java puzzles java tips testing tips windows 8 5 way to create Singleton Object Architect Interview Questions and Answers Architecture Architecure Bluetooth server as swing application that searches bluetooth device in 10 meter circle and show all devices. You can send file to any bluetooth device. C Programming CIO Callable Statement in Java Circular dependency of Objects in Java Comparable Example in Collection Custom annotation in Java Developer Interview Divide and rule example in java Drupal Example of Singleton Pattern FIX protocol ForkJoin Example in Java 7 Get data from dynamic table with Java Script Git HTML and JavaScript Health Hello World TCP Client Server Networking Program Hibernate Basics Hibernate Interview Question Answer J2EE Interview Question And Answers J2ME GUI Program JEE Interview QA JMS interview question Java J2EE Hibernate Spring Struts Interview Question Java System Property Java Threads Manager Portlets Provident Fund Read data from any file in same location and give the required result. Reading Properties File in Java Redpoint Rest WebService Client Rest Webservice Test SAL join with ven diagram SCP UNIX COMMAND SSL Singleton Pattern in Java Spring Bean Initialization methods and their order Spring Interview Questions Struts Struts 2.0 Basics Struts 2.0 Design Pattern Submit Html Form With Java Script On The Fly Unix executable For Java Program XOM DOM SAX XP books computers core java; core java; object oriented programming data structure; java investment bank; design pattern dtd duplicate rows in table get browser name with jquery grails podcast inner class java beginners tutorial java cache java networking tutorial java spring java util; java collections; java questions java.java1.5 linked list mailto function with all browser oracle database oracle duplicate rows orm schema social spring mvc questions struts transaction tricks tweet windows xslt