1) What are the principle concepts of oops?
Ans :The different OOPS concepts are :
Encapsulation :The process of wrapping or putting up of data into a single unit class & keep data safe from misuse is called encapsulation.
- Example : Take a car class, In car we have many parts which is
not required for driver to know.He is required to know only about
how to start and stop the car.So, we can expose what all are required
& hide the rest by using encapsulation.
Inheritance :Inheritance is concept of getting properties of one class object to another class object.
- Extends is the keyword used for developing inheritance between two classes and two interfaces.
- Implements is the keyword used to developed inheritance between interface and class.
Polymorphism :Polymorphism is an important Object oriented concept and widely used in Java and other programming language.Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.
There are two types of polymorphism:
- Compile time polymorphism: This is done using method overloading.
- Run time polymorphism: This is done using inheritance and interfaces.
2) Why is java called a platform independent language?
Ans :When java compiles a java program, it generates .class file. Class file contains bytecode.These byte codes are interpreted by JVM.Since JVM is available for all the platform by Sun MicroSystem,we can execute this bytecode in any platform.A byte code which is generated in windows platform can be executed in Linux platform.This make java a platform independent.
3) Why java is not pure Object Oriented language?
Ans :Java is not pure Object Oriented language because it supports Primitive datatype such as int, byte, long... etc, to be used, which are not objects.
There are few reasons why java is not pure Object Oriented language :
- Java supports primitive data type such as int . char , float .
- All these are not object but you can argue we have wrapper class for each of the data type such as Integer(int) , Float(float) etc .
- Even without object we can run a java program (using static)
- Features like multiple inheritance which are part of oops are not supported
There are seven qualities to be satisfied for a programming language to be pure Object Oriented.They are:
- All predefined types are objects
- All operations are performed by sending messages to objects
- All user defined types are objects.
4) What is the difference between private, protected, and public?
Public : Public is the most well known of the Java keywords. Public is also the easiest of the Java access modifiers because of its nature. A variable or method that is public means that any class can access it. This is useful for when the variable should be accessible by your entire application. Usually common routines and variables that need to be shared everywhere are declared public.
Private Private access modifier is the most restrictive access level. Class and interfaces cannot be private. Private variables and methods are those that are meant to be directly accessed by the Java class that owns them.
Protected:Protected variables and methods allow the class itself to access them,classes inside of the same package to access them, and subclasses of that class to access them. Variables, methods and constructors which are declared protected in a superclass can be accessed only by the subclasses in other package or any class within the package of the protected members' class.
5) What is the difference between JVM JRE and JDK?
JVM (Java Virtual Machine) : JVM is an abstract machine.It is a specification that provides runtime environment in which java bytecode can be executed.It runs pre compiled Java programs, which mean JVM executes .class files (byte-code) and produces output. It provides a machine interface that does not depend on the underlying operating system and machine hardware architecture. Programs written in Java are compiled into machine language, but it is a machine language for a computer that is, virtual and doesn't really exist. This so-called "virtual" computer is known as the Java virtual machine (JVM).
The JVM performs following main tasks:
- Loads code
- Verifies code
- Executes code
- Provides runtime environment
JRE (Java Runtime Environment JRE is used to provide runtime environment.JRE is an implementation of the JVM which actually executes Java programs.It contains set of libraries + other additional components that JVM uses at runtime.It does not contain any development tools such as compiler, debugger.If you want to run any java program, you need to have JRE installed in the system.
JDK (Java Development Kit) :JDK is a bundle of software components or a group of utilities that is used to develop Java based applications and JRE to run the programs.It is an implementation of either of Java SE, Java EE or Java ME.
Java Development Kit is a bundle of the following software components that are needed to develop Java based applications.
- Java Compiler
- Java Interpreter
- Java Disassembler
- Java Documentation
- Java Debugger
- Java Applet Viewer
6) What is the difference between java compiler and java interpreter?
Ans : The difference between java compiler and java interpreter: