Core Java Interview Questions

Showing Questions 1 - 20 of 588 Questions
First | Prev | Next | Last Page
Sort by: 
 | 
Jump to Page:
  •  

    Output of Java Program

    What is the output of the following program?class A{ public static void main(String[] s) { System.out.println(s[1] + s[2] + s[3]);}}java A 12345Options(i) 1(ii) 12(iii)1234(iv)234(v) Compilation Error

    Star Read Best Answer

    Editorial / Best Answer

    abuthahir.d  

    • Member Since Jan-2008 | Apr 14th, 2008


    Khadar , i tried this code . it gives that exception

    for the foll reason : 
     when u give a CLA(command line argument) , it will be inserted in the index 0 of the array and then will proceed to 1 ,2 ....

    so as per the question , "12345" will be at s[0] . and length of that aray will be 1when u try to access s[1] , we are trying for 2nd element which is unavailable..... 


    Hope this answers u  :-)

    disha bisht

    • May 11th, 2016

    This code will give "Array out of bound exception".... but if we provide space after each number then it will give 234 as output.

    Biswajit

    • Jan 29th, 2015

    That's right. Onlty ArrayIndexOutofBoundsException will come, as silly mistake is there in the code.

  •  

    Can we serialize the static variable?

    shanu

    • May 9th, 2016

    You cannot serialize static variable as they belong to class not obj. and serialization is all about object. static int x= 10; int y =5 , if you seralize both the ans will be 10 and 5. But wait 10 is...

    swapna

    • Jul 7th, 2015

    Static variable is class variable but always part of each object also, So we can serialize the static variables. Always serialized static variable holds the value of particular state object. {geshib...

  •  

    Mystique Function

    Today we have a special function called Mystique Function.Mystique function for any value x is denoted by H(x). H(x) is defined as the count of positive integers such that (Let k be one of such positive integer)

    1) x%k=0

    2) for every integer z it satisfies (z^k-z)%k=0.

    3) k>1

    Now given a value x you need to print the sum of H(2)+H(3)+H(4)..H(x).

    Rajesh Swarnkar

    • May 8th, 2016

    The condition 2 is not very clear.
    "for every integer z it satisfies (z^k-z)%k=0"

    How would I test the satisfiability against every integer z as they are infinite?

  •  

    What is throwable and where should we use this?

    Bikram

    • May 4th, 2016

    Throwable is the super class for Error and Exception class. Throwable extends Object class. But more often you will not see the user will be extending Throwable. It is used for Handling Exception. But also when you will be catching multiple Exceptions then it is a good idea to implement this one.

    Anny

    • Dec 18th, 2015

    Thorwable is the parent class for error and exception. It is used for exception handling

  •  

    Can we declare main() as final?

    Palash khatri

    • May 4th, 2016

    There is no such type of error is coming neither in compiling nor in running

    Debashis Nanda

    • Apr 22nd, 2016

    Yes, we can declare main method as final no compile time error and no run time error.
    But if we can not override that main method in subclass so if we want to execute the subclass, so we have to invoke everything inside static block of subclass.

  •  

    Can we override the main method?

    Star Read Best Answer

    Editorial / Best Answer

    ashish_setia  

    • Member Since Oct-2006 | Oct 3rd, 2006


    check out this example

    class Checkmain{
    public static void main(String args[]){
    args[1]="ashish";
    System.out.println("hello ");
    }
    }
    class Checkmain1 extends Checkmain{
    public static void main(String args[]){
    System.out.println("how r u");
    }

    }
    class Jo{
    public static void main(String args[]){
    String S[]=new String[10] ;

    Checkmain.main(S);
    Checkmain1.main(S);
    }}

    swarnendu2016@gmail.com

    • Apr 7th, 2016

    It is method hiding concept involved if Static is there, No overriding possible.

  •  

    Sub Class method call

    When the Subclass method is called, does the SuperClass constructor execute? If so, which Constructor executes first (Sub Class OR Super Class) for the given below scenarios?
    a. Given that we are NOT inheriting SuperClass constructor?
    b. Given that we are inheriting SuperClass constructor?

    Shrimp

    • Apr 1st, 2016

    When a sub class method is called from parent class, constructor will be executed dude, constructor only executed when you create an object

  •  

    What is the use of interface in realtime java project ?

    meena

    • Feb 16th, 2016

    Consider a construction of a building. The basic entire PLAN of the building I what an INTERFACE does. Next, the implementation of that PLAN is done by CONCRETE methods. If some of the work is done and still some is left is what ABSTRACT method/class does.

  •  

    What is the difference between abstract class & Final class

    baban

    • Feb 11th, 2016

    Abstract class cannot create object but final class create a object
    abstract class which have must a subclassed but final class which have no subclassed

  •  

    Why we can not override static method?

    Ramesh

    • Feb 4th, 2016

    If a subclass defines a class method with the same signature as a class method in the superclass, the method in the subclass hides the one in the superclass. You didn't override the method a(), because static methods are not inherited. If you had put @Override, you would have seen an error.

  •  

    Why java is not 100% object oriented language??

    i have not ..asked in TCS interview ..if any one have plz answer me on er.anuj.mittal@gmail.com

    kiran

    • Mar 1st, 2016

    Because of primitive data types, if we use Wrapper classes then Java is 100% pure object oriented.

    pranathi repaka

    • Feb 11th, 2016

    Object oriented is a concept which not only deals with objects but also with other concepts like class, object, encapsulation, abstraction, message passing, dynamic binding, polymorphism and inheritan...

  •  

    String Format Expression

    In the expression String.format("%2d", 5)
    what are the things below, be specific. for example, if the thing is an operator, indicate whether it is binary/unary and whether it is arithmetic/logical/relational. If it is a method, indicate whether its static or not

    a. String
    b. .
    c. format()
    d. "%2d" and 5

    meena

    • Feb 16th, 2016

    It returns a formatted string with a value of 5.

  •  

    What is the difference between inheritance and extends?

    I have not mistaken extends for polymorphism or encapsulation or anything else.. my question is correct!!!

    ANKIT SHARMA

    • Feb 14th, 2016

    In Inheritance the object aquires all the properties & behaviour of parent object

  •  

    Why can't we create object for an abstract class?

    Naveen Kumar K R

    • Jan 17th, 2016

    In this case JVM does not know how much memory it has to allocate for that abstract method, because abstract method does not have any implementation. So JVM will not be able to allocate memory for that abstract method

    ambarish upadhyay

    • Aug 7th, 2015

    We cannot create object in abstract class because when we can compile the abstract class the compiler create them incomplete so in the abstract class we cannot create object

  •  

    Need of Polymorphism

    What is need of polymorphism in Java? What could have happen if polymorphism is not present?

    Star Read Best Answer

    Editorial / Best Answer

    syamala235  

    • Member Since Mar-2010 | Apr 8th, 2010


    Polymorphism in simple terms means one name many forms. Polymorphism enables one entity to be used as a general category for different types of actions. The specific action is determined by the exact nature of the situation.

    Polymorphism exists in three distinct forms in Java:
    • Method overloading
    • Method overriding through inheritance
    • Method overriding through the Java interface

    Ajas Mohammed

    • Jan 13th, 2016

    This is method overloading. Polymorphism enables method overriding not overloading. Method overriding means use of same method with same name, parameters and return type.

    avinash

    • Sep 26th, 2012

    Jdbc,servlets,jsp have come through polymorphism,if not there we have to remember all dependent classes related to DB,Servers...to use in our java coding

  •  

    If there are multiple If-else, what is the alternative algorthim we can use apart from using switch?

    Govardhan

    • Feb 14th, 2013

    I think switch case is better alternative instead of more if-else statements owing that another alternative ternary operator it would be complicated and a little bit of confusion thats why, I would prefer to go for switch case.

  •  

    What is difference between array & arraylist?

    Arraylist is resizable where as using array it is not possible.

    Sukhrob

    • Dec 24th, 2015

    First difference: array is already with fixed size while array lists size could be dynamically changed.

    Secondly, array can include only the same type of data while array list can consist of different primitive data types as well as objects.

    rakesh

    • Nov 18th, 2015

    Array is collection of similar data type values. We cant resizable and growable of array. It is already fixed when you declared while array list works as a dynamic in which size could be grow. It is a part of collection framework to handle or store the collection of object not any type of values.

  •  

    What is MVC architecture

    Star Read Best Answer

    Editorial / Best Answer

    Answered by: Mitchel K

    • Jun 27th, 2005


    A design pattern describes a proven solution to a recurring design problem, placing particular emphasis on the context and forces surrounding the problem, and the consequences and impact of the solution.  
     
    There are many good reasons to use design patterns. Here are three: 
     
    1) They are proven. You tap the experience, knowledge and insights of developers who have used these patterns successfully in their own work. 
     
    2) They are reusable. When a problem recurs, you don't have to invent a new solution; you follow the pattern and adapt it as necessary. 
     
    3) They are expressive. Design patterns provide a common vocabulary of solutions, which you can use to express larger solutions succinctly. 
     
    The goal of the MVC design pattern is to separate the application object (model) from the way it is represented to the user (view) from the way in which the user controls it (controller).  
     
    The MVC architecture has the following benefits: 
     
    1) Multiple views using the same model: The separation of model and view allows multiple views to use the same enterprise model. Consequently, an enterprise application's model components are easier to implement, test, and maintain, since all access to the model goes through these components. 
     
    2) Easier support for new types of clients: To support a new type of client, you simply write a view and controller for it and wire them into the existing enterprise model. 
     
    3) Clarity of design: By glancing at the model's public method list, it should be easy to understand how to control the model's behavior. When designing the application, this trait makes the entire program easier to implement and maintain. 
     
    4) Efficient modularity: of the design allows any of the components to be swapped in and out as the user or programmer desires - even the model! Changes to one aspect of the program aren't coupled to other aspects, eliminating many nasty debugging situations. Also, development of the various components can progress in parallel, once the interface between the components is clearly defined.  
     
    5) Ease of growth: Controllers and views can grow as the model grows; and older versions of the views and controllers can still be used as long as a common interface is maintained.  
     
    6) Distributable: With a couple of proxies one can easily distribute any MVC application by only altering the startup method of the application.

    yura

    • Dec 2nd, 2015

    Everyone explained what is MVC... This is outcome of one more design pattern called "separation of concerns", which means a "view" should only handle rendering logic of the model and should not be co...

    Anil Nivargi

    • Jun 26th, 2014

    The MVC consists of three kinds of Objects i.e Model,View and Controller. Lets start explaining one by one. 1) Model- It handles data processing and database works part. Model processes event...

Showing Questions 1 - 20 of 588 Questions
First | Prev | Next | Last Page
Sort by: 
 | 
Jump to Page:

 

Have Interview Question?

Please select the most appropriate category and mention a brief question title along with clear question details.

Ask Question

Login to Ask Question or Register your free account   

Name:
Email:
Category :
Sub Category :
Question Title:
Question in Detail :
Job Role (Optional) :
Company (Optional) :
 

Optional Features

Register at GeekInterview

Register me.

Subscribe to GeekInterview Newsletter

Yes, Subscribe me to Interview & Career Tips