• What is Java?
    • Java is a high-level object-oriented programming language that can be used to develop large-scale applications. It was developed by James Gosling in 1982.
  • List down features of Java?
    •  Java features are mentioned below:
      • Abstraction
      • Architecture Neutral: In C language the size of the data type may change depending on the architecture (32-bit or 64) which is not applicable in Java, the size will remain the same.
      • Distributed: Users can create distributed applications in Java which allow us to access files by calling the method from any machine on the internet.
      • Dynamic: Dynamic mean users can load classes on demand, we can also load functions from it native language.
      • Encapsulation
      • High Performance: The performance of Java is fast because its byte code is close to native code.
      • Interpreted: JIT is used to interpret along with the compiler.
      • Inheritance:
      • Multithreaded: we can write a program with multiple threads to handle many tasks at once which will share common memory space for all the threads.
      • Polymorphism:
      • Object Oriented: Java is object-oriented language means we declare classes and create objects of the same to have data and function instances of each object.
      • Portable: Java is read once and write-anywhere language which means we can run Java code on any machine by converting Java program (.java) to bytecode(.class) to run on any machine.
      • Platform Independent: Java is platform independent means it is not dependent on operating system to run the code instead it comes with its own platform on which the code is executed.
      • Robust: Because of having a very strong memory management system like automatic garbage collection and exception handling etc., Java is known for its robustness.
      • Secured: Because of not using explicit pointers Java is knowns as a secured language.
      • Simple: Syntax in Java is similar to C++ which makes it easier to use.
  • What is a Java virtual machine?
    • Java Virtual Machine (JVM) enables the computer to run the Java program by invoking thw run-time engine which calls the main method presented in the Java code. JVM specification must be implemented in the computer system to compile the Java code to convert it into a Bytecode which is machine independent and close to the native code.
  • Explain JDK, JRE, and JAR.
    • JDK is also known as a Java development kit. JDK provides a software development environment to develop any Java program or applet.
    • JRE also known as Java Runtime Environment is a part of the JDK which includes a JVM, core classes, and several libraries that support application development. It is the implementation of JVM which physically exists.
    • JAR also known as Java Archive is a package file format, it is used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file to distribute application software or libraries on the Java platform. These files are built in the ZIP format with a .jar file extension.
  • Explain allocation of memory areas by JVM in Java.
    • The main important types of memory allocation by JVM are mentioned below:
      • Heap: Under this memory area objects are allocated during runtime.
      • Stack: This type of memory stores frames to hold local variables and partial results. It also helps in method invocation and its return. Whenever any method is invoked, it will create a new frame every time and destroy the same as soon as invocation gets completed. Each thread has a private JVM stack which gets created at the same time as the thread.
      • Class/Method Area: This type of memory stores the structure of each class such as the method data, runtime constant pool, field, and the code for methods.
      • Native Method Stack: This type of memory stores all the native methods used in the application.
      • Program counter Register: This type of memory stores the address of the Java virtual machine instruction currently being executed.
  • Differentiate between Heap and Stack memory?
Stack MemoryHeap Memory
Stack memory is the portion of memory that is fixed and assigned to every individual program.On the contrary side Heap memory is the portion of memory which is not fixed, although is available to use as required by any Java program during runtime.
All the variables and methods etc of any Java program are stored under Stack memory.Any object created in any Java method is stored under Heap memory and referenced from Stack memory.
  • What do you understand by Data encapsulation in Java?
    • Data Encapsulation is an Object-Oriented Programming concept that helps in hiding or encapsulating the data attributes and behaviors in a single unit. It can also be used for the security of the private properties of an object, that’s how it serves the purpose of data hiding.
    • The data encapsulation concept also enables modularity property which helps developers to develop such a program where each object is independent of other objects by having its own methods, attributes, and functionalities.
  • What is the difference between Composition and Aggregation in Java?
    • Composition: If a container object or class gets destroyed then the contained objects will also get destroyed automatically because of a strong association between the objects, this strong association is called Composition.
    • Aggregation: If a container object or class gets destroyed and the contained objects will not get destroyed because the container object only holds reference to contained objects, although contained objects will be set free to make association with other objects because of weak association between the objects which is called Aggregation.
  • What is a default Constructor in Java?
    • Instances or objects of any class are created using new keywords by the constructor in Java. Sometimes constructors are also referred to as special methods to initialize the state of an object, except its name should be the same as the class name and it should not have any explicit return type.
    • These constructors are invoked when the class is instantiated to create an object and the memory is allocated for the object.
  • Explain different types of constructors in Java.
    • Broadly Constructors can be divided into two types according to the parameters passed:
      • Default Constructor: Default constructors don’t accept any value/arguments and are mainly used to initialize the instance variable with a default value. The compiler will invoke the default constructor implicitly if no other constructor is defined in the class.
      • Parameterized Constructor: The parameterized constructor can initialize the instance variables with the given values by passing the arguments.
  • What is Copy Constructor in Java?
    • Constructors cannot be copied in Java, although values from one object to another can be copied using below-mentioned techniques:
      • By assigning the values of one object into another
      • By constructor
      • By clone() method of Object class
  • What is constructor overloading in Java?
    • When we create multiple constructors of any given class, having the same name but differences in the parameters, this process is called constructor overloading. The compiler will distinguish the different types of constructors by the number of parameters passed and its datatype.
  • What is Marker Interface in Java?
    • Market Interfaces will not have any method and constant defined inside them, these interfaces are meant to help the compiler and JVM to get runtime object information. These interfaces are also known as tagging interfaces.
  • What do you understand by Object Cloning in Java?
    • To create the exact copy of any object we use clone() method in Java. The java.lang.Cloneable interface is mandatory to implement by the class whose object clone is to be created. If this interface is not implemented then clone() method generates CloneNotSupportedException.
  • What is method overloading?
    • Method overloading is known as polymorphism technique where multiple methods can be created with the same name but different signatures. Method overloading can be done using below two ways.
      • By Changing the number of arguments
      • By Changing the data type of arguments
  • What is the method overriding?
    • Method overriding is the specific implementation of a method in any subclass which is already provided by its parent class. This feature is used for runtime polymorphism and to implement the interface methods. Rules for Method overriding are mentioned below:
      • The method must have the same name as in the parent class.
      • The method must have the same signature as in the parent class.
      • Two classes must have an IS-A relationship between them.

admin
http://www.learnwithgeeks.com

Leave a Reply