CORE JAVA INTERVIEW QUESTIONS 1

CORE JAVA INTERVIEW QUESTION
         31. How many types of memory areas are allocated by JVM?
                 There are many types of memory allocations in Java. They are:
                 Class (Method) Area
                 Heap
                 Stack
                 Program Counter Register
                 Native Method Stack
          32. What is JIT compiler?
                Just-In-Time (JIT) compiler: It is used to improve the performance. JIT compiles                   parts of the byte code that have similar functionality at the same time, and hence               reduces the amount of time needed for compilation. Here the term “compiler”                     refers to a translator from the instruction set of a Java virtual machine (JVM) to the           instruction set of a specific CPU.
         33. What gives Java its 'write once and run anywhere' nature?
               The bytecode. 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.
         34. What is difference between object oriented programming language and object            based programming language?
               Object based programming languages follow all the features of OOPs except                        Inheritance.
               Examples of object based programming languages are JavaScript, VBScript etc.
        35. What is constructor?
               Constructor name is same as the class name and it is invoked at the time of object              creation.
        36. What is the purpose of default constructor?
              The default constructor provides the default values to the objects. The java compiler         creates a default constructor only if there is no constructor in the class
         37. Is constructor inherited?
               No constructor is no inherited.
         38. Can you make a constructor final?
                No. Constructor can’t be final
         39. What is static method?
              A static method belongs to the class rather than object of a class.
              A static method can be invoked without the need for creating an instance of a class.
              Static method can access static data member and can change the value of it.
         40. What is static block?
               It is used to initialize the static data member.
               It is executed before main method at the time of class loading.
         41. Can we execute a program without main() method?
               Yes,one of the way is, by static block
         42. What is this in java?
               It is a keyword that that refers to the current object.
         43. What is Inheritance?
               Inheritance is a mechanism in which one object acquires all the properties and                     behavior of another object of another class.
                It represents IS-A relationship.
                It is used for Code Re-usability and Method Overriding.
         44. Which class is the superclass for every class?
               Object class is the super class for every class in java.
         45. Why multiple inheritance is not supported in java?
               To reduce the complexity and simplify the language, multiple inheritance is not                     supported in java in case of class.
         46. What is super in java?
               It is a keyword that refers to the immediate parent class object.
         47. Can you use this() and super() both in a constructor?
               No. Because super() or this() must be the first statement.
          48. What is object cloning?
                The object cloning is used to create the exact copy of an object.
          49. What is method overloading?
                If a class has multiple methods by same name but different parameters, it is known           as Method Overloading. It increases the readability of the program.
          50. What is method overriding?
                If a subclass provides a specific implementation of a method that is already                         provided by its parent class, it is known as Method Overriding. It is used for                         runtime polymorphism and to provide the specific implementation of the method.
           51. Can we override static method? 
                 No, you can't override the static method because they are the part of class not                    object.
          52. What is blank final variable?
                A final variable, not initialized at the time of declaration, is known as blank final                   variable
           53. What is Runtime Polymorphism?
                Runtime polymorphism or dynamic method dispatch is a process in which a call to             an overridden method is resolved at runtime rather than at compile-time. In this                 process, an overridden method is called through the reference variable of a                       superclass. The determination of the method to be called is based on the object                   being referred to by the reference variable.
            54. What is the difference between static binding and dynamic binding?
                  In case of static binding type of object is determined at compile time whereas in                 dynamic binding type of object is determined at runtime.
  55. What is abstraction?
                Abstraction is a process of hiding the implementation details and showing only                   functionality to the user.
           56. What is the difference between abstraction and encapsulation?
                 Abstraction hides the implementation details whereas encapsulation hides the                    data.
           57. What is abstract class?
                A class that is declared as abstract is known as abstract class. It needs to be                         extended and its method to be implemented in a subclass. It cannot be instantiated             i.e. we cannot create object for an abstract class.
           58. What is marker interface?
                An interface that has no data member and method is known as a marker interface.             For example Serializable, Remote etc.
           59. Can we define private and protected modifiers for variables in interfaces?
                  No, they are implicitly public.
           60. What is package?
                A package is a group of similar type of classes, subclasses, interfaces and sub                       packages. Package resembles to directory structure. It provides access protection               and removes naming collision.
           61. Do we need to import java.lang package any time? Why?
                  No. It is by default loaded internally by the JVM.
           62. What is static import?
                 By using static import, we can access the static members of a class directly. We                    need create the object for that class to access the static members because they can            be accessed by using class name itself.
           63. What is Exception Handling?
                 Exception Handling is a mechanism to handle runtime errors. It is mainly used to                handle checked exceptions.
           64. What is difference between Checked Exception and Unchecked Exception?
                 Checked Exception
                     The classes that extend Throwable class except RuntimeException and Error are                known as checked exceptions e.g.IOException,SQLException etc. Checked                              exceptions are checked at compile-time.
                 Unchecked Exception
                     The classes that extend RuntimeException are known as unchecked exceptions                  e.g. ArithmeticException,NullPointerException etc. Unchecked exceptions are not                checked at compile-time.
           65. What is the super class for Error and Exception?
                 Throwable class
           66. What is finally block?
                 Whether the exception is raised or not finally block is always executed.
           67. Can finally block be used without catch?
                  Yes, by try block. finally must be followed by either try or catch.
           68. Is there any case when finally will not be executed?
                 Finally block will not be executed if program exits(either by calling System.exit() or            by causing a fatal error that causes the process to abort).
           69. What is the meaning of immutable in terms of String?
                 The simple meaning of immutable is unmodifiable or unchangeable. Once string                  object has been created, its value can't be changed.
           70. How many ways we can create the string object?
                 There are two ways to create the string object, by string literal and by new                           keyword.
           71. What is the basic difference between string and stringbuffer object?
                 String is an immutable object. StringBuffer is a mutable object.
           72. What is the difference between StringBuffer and StringBuilder ?
                 StringBuffer is synchronized whereas StringBuilder is not synchronized.
            73. What is the purpose of toString() method in java ?
                  The toString() method returns the string representation of any object. If you print             any object, java compiler internally invokes the toString() method on the object. So             overriding the toString() method, returns the desired output, it can be the state of             an object etc. depends on your implementation.
           74. What is multithreading? 
                 Multithreading is a process of executing multiple threads simultaneously. Its main              advantage is:
                 1. Threads share the same address space.
                 2. Thread is lightweight.
                 3. Cost of communication between process is low.
           75. What is thread?
                 A thread is a lightweight subprocess. It is a separate path of execution. It is called                separate path of execution because each thread runs in a separate stack frame.
            76. What does join() method?
                 The join() method waits for a thread to die i.e. it causes the currently running                       threads to stop executing until the thread it joins.
            77. Is it possible to start a thread twice?
                 No, there is no possibility to start a thread twice. If we do, it throws an exception.
            78. What about the daemon threads?
                  The daemon threads are basically the low priority threads that provide the                         background support to the user threads. It provides services to the user threads.
           79. What is shutdown hook?
                 The shutdown hook is basically a thread which is invoked implicitly before JVM                  shuts down. So we can use it perform clean up resource.
            80. What is synchronization?
                  Synchronization is the capabilility of control the access of multiple threads to any                shared resource.It is used:
                   1.      To prevent thread interference.
                   2.      To prevent consistency problem.
           81. What is the purpose of Synchronized block?
                 Synchronized block is used to lock an object for any shared resource. Scope of 
                 synchronized block is smaller than the method.
           82. Can Java object be locked down for exclusive use by a given thread?
                 Yes. You can lock an object by putting it in a "synchronized" block. The locked                      object is inaccessible to any thread other than the one that explicitly claimed it.
          83. What is the difference between notify() and notifyAll()?
                The notify() is used to unblock one waiting thread whereas notifyAll() method is                  used to unblock all the threads in waiting state.
          84. What is deadlock?
                Deadlock is a situation when two threads are waiting on each other to release a                 resource.
          85. What is Garbage Collection?
                Garbage collection is a process of reclaiming the runtime unused objects i.e. the                 garbage collector can identify the unused objects for some certain period and those           objects will be deleted in the heap. It is performed for memory management.
          86. What is the purpose of finalize() method?
                finalize() method is invoked just before the object is garbage collected. It is used to             perform cleanup processing.
           87. What kind of thread is the Garbage collector thread? 
                 Daemon thread.
           88. What is difference between final, finally and finalize?
                 final: final is a keyword, final can be variable, method or class.You, can't   change                          the value of final variable, can't override final method, can't inherit final class.
                  finally: finally block is used in exception handling. finally block is always executed.
                  finalize():finalize() method is used in garbage collection. finalize() method is                                         invoked just before the object is garbage collected. The finalize() method                             can be used to perform any cleanup processing.
           89. What is the purpose of the Runtime class? 
                 The purpose of the Runtime class is to provide access to the Java runtime system.
           90. How will you invoke any external process in Java?
                 By Runtime.getRuntime().exec(?) method.
           91. What is transient keyword?
                 If you define any data member as transient, it will not be serialized. It means the                data present in the data member or instance variable does not store in the stream               -   i.e. a file.
           92. What is the difference between Serializable and Externalizable interface?
                  Serializable is a marker interface but Externalizable is not a marker interface.                     When you use Serializable interface, your class is serialized automatically by                       default. But you can override writeObject() and readObject() two methods to                       control more complex object serailization process. When you use Externalizable                  interface, you have a complete control over your class's serialization process.
            93. What are wrapper classes?
                  Wrapper classes are classes that allow primitive types to be accessed as objects.
           94. What is a native method?
                 A native method is a method that is implemented in a language other than Java.
           95. What is the purpose of the System class?
                  The purpose of the System class is to provide access to system resources like in,                 out and err.
            96. What is singleton class?
                  Singleton class means that any given time only one instance of the class is present,             in one JVM.
            97. If I do not provide any arguments on the command line, then the String                        array of main() method will be empty or null?
                   It is empty. But not null.