Java interview questions and answers


156 Java interview questions and answers

8 Things you should always remember before go for an interview


What do you known  about Java?
             Java is a high-level programming language originally developed by sun microsystem. Supported oops concepts and it  provides high security. Java is a platform independent programming language(Linux,Windows,Unix...). Now it is owned by Oracle Corporation.

What is Java technology and why we need it?
                Java is Object based programming language first released by Sun Microsystems in 1995. Java is platform independent language, secure , reliable and robust. In present world lots of applications and websites working on Java technology, to use that application we need to install Java.

What is platform independent?
            A Java program can run on any hardware platform like windows,Linux,Unix.
Example: If we write a java program in windows machine  we can execute in another operating system like a Linux machine.
"Write Once, run anywhere"(WORA) Java quotation.




Why we are using java rather than other technologies?
            Java is platform independent language and supported OOPs concepts and provides more security rather than other technologies.

How many platforms supported java programming language?
            Java programming language is platform independent, so it supports a variety of platforms like Windows, Linux, Solaris, Ubuntu, etc…

What is the difference between class and classpath?
            The classpath and path are OS level environment variables. The classpath is describing location of .class files and path is describing the location of .exe files.

What is JIT compiler?
JIT(Just in time complier): It is converting byte code to executable code providing high performance. The java code will be executed both interpreter and JIT compiler simultaneously it reduces compilation time.

Why we need command line arguments in java?
            For customization we use command line arguments.

Is java a pure object oriented programming language?
            In java uses primitive data types so java is not a pure object-oriented programming language.

What are the features of java?
            The features of java are supports OOPs, platform-independent, secure, robust, high performance, portable.

 Why java doesn’t support pointers?
            The pointer is a reference to a memory location. The readability is the big problem and pointers are leads to memory leaks.

 What is aggregation in java?
            If a class has an entity type reference is known as aggregation. The aggregation represents HAS-A relationship. The code reusability is the main use of aggregation.

List of few java keywords unlike C, C++ keywords?
            Import
            Super
            Finally

What is the base class of all classes?
            The base class is java.lang.Object

How to declare constant variables in java?
            By using static and final keywords we can declare constant variables.
Example: static final int number =10;


JVM:
            The JVM is a platform-dependent and it is an abstract machine. The JVM executes only byte code. The Java Virtual Machine is known as JVM.
JDK:
            The JDK is a software development environment used for developing Java applications. It includes the Java Runtime Environment (JRE), and development tools. The Java Development Kit is known as JDK.
JRE:
            The Java Runtime Environment is known as JRE. The JRE provides runtime environment and it is an implementation of JVM. The JRE is a software environment it consists of a set of library files and its related files.

What is high performance?
            Java contains JIT (Just-In-Time) compiler. It compiles byte code in time only. The instructions are directly sent to a processor.

List of java IDE’s?
            Eclipse
            Netbeans
            JDeveloper, etc...

What is java quotation?
            Write once run anywhere.

What is call by value?
            In java if we call the method passing a value is known as call by value.
Example:   sample.add(50);

What is recursion?
            Recursion is a process of few statements calling itself. A method calling itself is known as recursion in java.
Example:
public class Factorial{
static int fact(int number){
if (number==0)
return 1;
else
return number=number*fact(number-1);     //recursion  method is calling it self
}
     public static void main(String []args){
        int number2= fact(5);    
        System.out.println(number2);
     }
}


Is java is a pure object-based programming language?
                 In java we are using primitive type data types, so is not a pure object-oriented programming language.

What is an object-based programming language?
                The object-based programming language has followed all features of OOPs concepts except inheritance.


What is a constructor in java?
            A constructor is a special method that is used to initialize that is used to initialize an object. The java constructor is a special method it looks like a method but it is not a method.

What is the return type of constructor?
            Constructor doesn’t have any return type even void.

How many types of constructors in java?
            There are two types of constructors in java user defined constructor and default constructor.

What is user default constructor?
            The default constructor JVM will provide.

What is a user defined constructor?
            The parameterized constructor is known as the user-defined constructor.

What is “this keyword“in java?
            In java, this is a reference variable and it refers to a current object.

What is the use of this keyword in java?
              In java “this” is an instance variable and used in the constructor. In java, this keyword can be passed as an argument in the method call.
Program:
public class Variables{
    public int x = 0;
    public int y = 0;
    //constructor
    public Variables(int x, int y) {
        this.x = x;              //this is used here
        this.y = y;
}
void display( ){
        System.out.println(+x);
        System.out.println(+y);

}
     public static void main(String []args){
        Variables v = new Variables(10,10);            //we are usd this so here 10,10 values are passed to constructor
        v.display();                   //calling display( ) to print output
     }
}

Why we are using “new keyword” in java?
            If we new keyword allocated memory at runtime and by using we are creating an object in java.

Define about super keyword?
            In java super is a reference variable If we overload a constructor into child class then it is immediately refers to parent class object. The super( ) is used in constructors.
Example:
public class Basicphone {
    public void features() {
        System.out.println("Few features available");
    }
}
public class Smartphone extends Basicphone {

                                // overrides features from Basicphone class
    public void features() {
        super.features();                                     //super refers to parent class
        System.out.println("Advanced features available");
    }
    public static void main(String[] args) {
        Smartphone s = new Smartphone();
        s.features();   
    }
}

Main() method


Is main( ) method compulsory in a java class?
            In java class main( ) method  is not necessary, if we compile a class without main( ) method there is no error in compile time but run time you well get an error.

public static void main(String args[])                 

Is write this order only or we can change order?
            We can change an order but must should declare void beside main( ) method because main() method id doesn’t return anything.

What is the return type of main( ) method?
            In java main( ) method nothing will return so it declared as void.

Can we overload main( ) method in java?
            We can overload main( ) method in java.

What type of error will get if we apply final to main( ) method?
We can apply final to main( ) method and there is no error in compile time and run time.

Why main( ) method is static in java?
            In java main( ) method is a class method. Initially, JVM creates an object and call main( ) method it leads to big problem for memory allocation, so main( ) method is static in java.


Variables:


Which type of variables a class can consist of?
            The java class consists of class variables, local variables and instance variables.

What is a local variable?
            The local variables are defined inside class and inside method. The local variables are declared and initialized inside of a method and it will destroy when a method has completed.
Example: Constructors or blocks variables are local variables.

What is an instance variable?
            The instance variables are created inside class and outside method.  The instance variables are allocated memory at run time.

What is a class variable?
            The class variables are created inside class and outside method. The class variables are also known as static variables. The class variable is declared with static keyword and allocates memory at compile time.
Program:
public class Variables{
static int i=10;                                //class variables
int j=15;                                         //instance variables
     public static void main(String []args){
            int k=20;                                             //local variable
            System.out.println(“Different types of variables here”);
     
}
}


Data types:


What is the default values of byte, float, double data type in java?
            The default value of byte data type is 0 and float data type value is 0.0f and double is 0.0d.

List of primitive types in java?
            The primitive types are byte, char, short, int, long, float, double, boolean.

What is type casting?
            Type casting means converting one data type to another data type.
Example: int a = 20;
                byte b = (byte)a;


What are the differences between String and StringBuffer and StringBuilder?
String:
            String is immutable and content is fixed. If we concat new string to old string then it creates a new object. The String class overrides equals( ) method of Object class. To compare two strings equals( ) method is useful.
StringBuffer:
            StringBuffer is mutable and content is not- fixed. The StringBuffer is fast and consumes less memory. The StringBuffer is synchronized i.e. thread safe. It is less efficient than StringBuilder. The StringBuffer class doesn’t override equals ( ) method of Object class.
StringBuilder:
            StringBuilder is mutable and content is not- fixed. The StringBuilder is non- synchronized i.e. not thread safe. It is more efficient than StringBuffer.


Why java doesn’t support multiple inheritance?
            To reduce complexity and simplify language java doesn’t support multiple inheritance and another one is Diamond problem.

What is up casting in java?
            The reference variable of parent class object  refers to child class object is known as up casting.

Which relation inheritance follows?
            Inheritance follows IS-A relationship.

Can we extend more than one class into a single class?
            No, because java doesn’t support multiple inheritance.

What is downcasting?
            The reference variable of child class object refers to parent class is known as downcasting.

What are the differences between static binding and dynamic binding?

Static Binding
Dynamic Binding
The object is determined at compile time is known as static binding.
The object is determined at run time is known as dynamic binding.
The static binding is also known as early binding.
The dynamic binding is also known as late binding.
The Overloaded methods are bonded using static binding.
The overridden methods are bonded using dynamic binding at runtime.


What is marker interface in java?
            An interface that has no member is known as maker interface. An interface with no fields and methods and variables is called as a marker interface. A maker interface is an empty interface. In another word a tagged object is getting extra functionality is known as a marker interface.
Example: Serializable, Clonnable.

How to make variable constant in java?
            By using final and static keywords we can declare constant variables in java. The final variables are declared outside of main() method and inside of class. If we declare inside of main() method compile time error will occur.
Example:
public class Sample{
public  final static int A = 110;
     public static void main(String []args){        
        System.out.println("Final varible value is :"+A);
     }
}


What is the default imported package in java?
                java.lang.package default imported package for all classes without any declaration.

List of three pre-defined classes in java.lang package?
Object
String
StringBuffer
Math
Vector
Thread
System





8 things to remember before go for an interview ans successful carrier

8 Things you should always remember before go for an interview

Company requirement: Read twice company requirements and job description.
Most of the times Job seekers are directly applying to the companies without reading of job role and company requirements. According to the company, requirements change your career objective.
Example:       
          

Company profile:
            Read once about a company and who is present CEO and what types of services are providing and client names.

Technical skills:                                                        
            Job seekers are starting with C language  and end somewhere (like c, c++, Java, HTML, .Net , Linux......) in resume that is not a good idea. The important thing is to write only what you and cross check your skill set to company requirements (from company job description profile).




Resume:
            In interview process everything is interlinked with resume, so write in your resume what you are (don’t copy and paste somewhere). Make sure don’t lie in your resume.
Example: If you are Witten reading books in the resume. In the interview process, questions may ask on books.
 What type of books did you like?
How many books you read so far?
So write your resume carefully.

Tell me about yourself:
            As we all are known this is the first question in every interview. So write about yourself on a single paper read it once before going for an interview. Based on this answer interviewer ask next question so be careful don’t lie. Explain what you are and what do you know on the technical side. Give a detail explanation on your skill set and how this are used in your life.


Dress sense:          
            We know dress sense is possess a key role in the interview. So wear formal dress for interview.

Confidence:
            Your confidence is telling lot about yourself, so be confident whenever you go for an interview.
Example: Assume a situation if you went an supermarket to buy something. If sales person shivering and explaining about product how you feel.

Communication:
            English is a global language so learn it and speak it. Don’t speak US or UK accent in an interview (if Interviewer understands not a problem).


How communication is helpful...



            Be yourself and believe yourself.
                                                                                                                         All the best…             
                                                            


bangalore metro rail corporation ltd

bangalore metro rail corporation ltd

Name of Organization:   (BMRCL) Bangalore Metro Rail Corporation Ltd...


Total vacancies:   308 Posts

Job Role: Mainter, Train Operator, Section Engineers

Eligibility:  Matriculation, ITI, Diploma (Eng), Engineering Degree

Job Location: All India

Last Date: 11-07-2016


Website: http://bmrc.co.in

Institute of Genomics and Integrative Biology

Name of an Organization: Institute of Genomics and Integrative Biology        

 
Total vacancies: 12 Posts

Job Role: Project Fellow, SPF, Research Associate

Eligibility: B.E/ B.TECH / MBBS or M.Sc, Ph.D

Job Location: All India

Last Date: 10-06-2016

Website: https://www.igib.res.in


nagpur metro rail corporation ltd jobs notification

 

Name of an Organization: Nagpur Metro Rail Corporation Ltd

Total vacancies:  09 Posts

Job Role : CPM, GM, Manager

Eligibility: BE/ B.Tech, M.Tech

Job Location : All India

Last Date: 17-06-2016

Website: http://www.metrorailnagpur.com/


What do you know about Inheritance in java?

Java Inheritance:

                  Acquiring features from the super class (parent class) to subclass(child class) in known as inheritance.
Inheritance follows IS-A relationship, it is also known as  parent to child relation.
By using of extends keyword we can inherit super class into subclass.

Derived class: Derived class is also known as child class (or) subclass.
Base class: In Java base class is also known as parent class (or) super class.

                In inheritance subclass has all properties  of super class &  subclass have extra properties.

Types of inheritance:

There are Five  types of inheritances in java.
1.Single inheritance
2.Multilevel inheritance
3.Multiple inheritance
4. Hierarchical inheritance
5. Hybrid Inheritance

 1.Single inheritance:        
                                                When a class extends another  class is known as single inheritance. It containing single base class and single derived class in the example manager class is a base class(parent class) and Employee class is derived class(child class).
Example :

2. Multilevel inheritance:
                                In Multilevel inheritance  initially  consisting one base class(parent class) and one derived class(child class) and derived class(child class) act as a base class to another class.
Example:Multilevel  inheritance                     
Initially HOD class act as a parent class to student class.Principal class act as the parent class to HOD class and now HOD class becomes child class to Principal class.


3.Multiple inheritance:
                             Java doesn’t  support  Multiple inheritance, because of Diamond problem.         
 Multiple inheritance consisting of one parent class and two child classes.

4. Hierarchical inheritance:
                                In Hierarchical inheritance  one parent class(base class) and two many child classes(derived classes).
Example:
                Mobile subscribers there is postpaid subscribers and prepaid subscribers.
                                        


5. Hybrid Inheritance:
                                Hybrid Inheritance  is a combination of both multiple inheritance and single inheritance. Java doesn’t  support Hybrid Inheritance but by using of Interface we can achieve this.
Example:

In Hybrid Inheritance   class A acting as a base class for class B, class C(derived classes) and class B and class C acting as a base class(parent class) to class D(child class).
Syntax for inheritance:
                Class child class extends  parent class{
                //methods
                }
Advantages with inheritance:
1.Inheritance provides Code reusability.
2.By using inheritance we can achieve Run time polymorphism.
3. Method overriding.
Limitations:
1.Minimum two java classes are required.
2.Handling complexity.
3.Multiple inheritance doesn't  support java.                  
4. Hybrid Inheritance doesn't  support java but by using the interface we can achieve.
5.Java extends only one class.


Interview Questions:
1.Explain about Java inheritance?
2.Is Java support multiple inheritance?
3.Limitations of inheritance?
4.Explain about oops concepts?
5.What is the relationship inheritance follows?
6.How many class can extend at a time in a Java class?
7.How can we achieve Hybrid inheritance?
8.Write syntax of inheritance?
9.Why do we need inheritance?
10.Why Java doesn't support multiple inheritance?

Kategori

Kategori