Basics 1

      Question

      1. What do you mean by Platform independence of java?
        You can write and compile program in one Operating system and run in other operating system (windows,unix,mac,etc.).Answer
      2. What is difference between JVM, JRE and JDK ?
        JVM : JVM stands for Java Virtual Machine. It is virtual machine which actually runs the byte code.
        JRE : JRE stands for Java Runtime Environment. It provides runtime environment for java code. It has JVM , libraries such as rt.jar and other files.
        JDK : JDK stands for Java development kit. It is superset of JRE, it has JRE + compilation and debugging tools(javac and java).
        Answer
      3. What are memory areas allocated in JVM?
        Memory areas allocated in JVM are:
        Heap area
        Method area
        JVM language stacks
        Program counter (PC) register
        Native method stacks
        Answer
      4. What are some core concepts of OOPS in Java ?
        Encapsulation
        Polymorphism
        Abstraction
        Inheritance
        Answer
      5. What is Abstraction?
        Data abstraction is the process of hiding certain details and showing only essential information to the user.
        Abstraction can be achieved with either abstract classes or interfaces
        Answer
      6. What is inheritance in java?
        Inheritance allows to inherit properties and methods of parent class, so you can reuse all of its.Answer
      7. What is constructor in java?
        Class and Constuctor name should match.
        Constructor should not have any return type.
        Constructor is used to initiaze objects.
        Answer
      8. Can we declare constructor as final?
        No, Constructor can not be declared as final. It will get compile time error. Answer
      9. What is immutable object in java?
        Immutable object is object whose state can not be changed once created. You can take String object as example for immutable object. Answer
      10. Why String is declared final or immutable in java?
        There are various reasons to make String immutable.
        String pool
        Thread Safe
        Security
        Class Loader
        Answer
      11. What are access modifier available in java?
        It Specifies accessibility of variables, methods , constructor of class.
        It is of four types in java
        Private : Accessible only to the class.
        Default : Accessible in the package.
        Protected : Accessible in the packages and its subclasses.
        Public : Accessible everywhere
        Answer
      12. Can one interface implement another interface in java?
        No, One interface can not implement another interface. It can extend it using extends keyword. Answer
      13. What is marker interface?
        Marker interfaces are interfaces which have no method but it is used to indicate JVM to behave specially when any class implement these interfaces.
        For example : If you implement Serializable interface
        Answer
      14. What is method overloading and method overriding in java?
        Method overloading : Method overloading is concept that allows a class to have same method name but diferent number and type of method arguments.
        Method overloading is also known as compile time polymorphism.

        Method overriding : If child class contain same method as parent class with same method signature. It will called by parent class refernce with child clas Class name as Object. This is called method overriding.
        Method overriding is also known as dynamic polymorphism.
        Answer

      15. Can you override static methods in Java?
        No, you can not override static methods in Java. You can create same method in child class but it won’t be dynamic polymorphism. It will be method hiding. Static methods belong at class level not at object level hence you can not override static method. Answer
      16. Can you override private methods in Java?
        No, you can not override private methods in Java. Private methods are not visible to subclass, hence you can not override private method but you can hide it.Answer
      17. Difference between path and classpath in java?
        Path
        a)It allows operating system to locate executable such as javac, java Overriding
        b)You need to include bin folder of jdk
        c) operated by Operating system

        classpath
        a) It allows classloader to locate all .class file used by program
        b) You need to include all the classes which is required by program
        c) operated by java classloaders
        Answer

      18. What is difference between StringBuffer and StringBuilder in java with Threadwise ?
        StringBuffer is thread safe. Two threads can not call methods of StringBuffer simultaneously.
        StringBuilder is not thread safe, so two threads can call methods of StringBuilder simultaneously.
        Answer
      19. What are methods you should override when you put an object as key in HashMap?
        You need to implement hashcode() and equals() method if you put key as object in HashMap. Answer
      20. The difference between Serializable and Externalizable in Java?
        Serializable interface is used to make Java classes serializable so that they can be transferred over network or their state can be saved on disk, but it leverages default serialization built-in JVM, which is expensive, fragile and not secure. Externalizable allows you to fully control the Serialization process, specify a custom binary format and add more security measure.Answer









      <Previous> <Next>