Core Java Interview Questions

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

    Is java a fully object oriented programming or not? if not why?

    Star Read Best Answer

    Editorial / Best Answer

    KanikaKG  

    • Member Since Jul-2008 | Aug 4th, 2008


    No. Java is not 100 % Pure OOP because of following three reasons:
    1) It doesnot support Multiple inheritance.
    2) It allows use of primitive data types which are not an objects.
    3) It allows static methods to call without creating the instance.

    This disobeys OOPs concepts?
    Java isnt 100% pure OOPS coz if it were then everything should be classes and objects, whereas java still has primitive data type which violates the above said statement...SmallTalk is the only 100% pure OOPS language

    Chaitra

    • Jun 6th, 2019

    Java is not a pure object oriented programming language because of the primitive data type.
    But java can be made 100% object oriented programming language by making use of wrapper classes.

    Amit Kumar

    • May 21st, 2018

    Sorry, I am completely agree that java is a pure object oriented language. First of all answer me one question , what do you mean by object oriented programming ? object oriented programming is a conc...

  •  

    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  :-)

    shyamasundar

    • Jun 2nd, 2018

    (v) Compilation Error

    shani

    • Mar 14th, 2018

    (v) Compilation Error

  •  

    How would you pass a java integer by reference to another function

    Mayank

    • Mar 13th, 2018

    I don't think that is right because if it was then changing the value inside the called function should reflect the change when the passed variable is accessed in calling function.

  •  

    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

    Prashant kumar gupta

    • Oct 28th, 2017

    We have different behaviors in different situations and in front of different people. A man behaves differently with his father, when he is with his friend he has different behavior. Another best exa...

    suraj

    • Jun 19th, 2017

    Polymorphism means one thing in many form. or one person different behavior is called polymorphism.

  •  

    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);
    }}

    vivek

    • Aug 26th, 2017

    Yes you can only do that by overriding main method signature for eg main(String[] args) to main(). Certainly there are no other ways to do that because JVM needs strings array arguments to take comma...

    Dharmendra Singh

    • Sep 15th, 2016

    yes we can"java public class HelloWorld { // arguments are passed using the text field below this editor public static void main(String[] args) { String []s =new Str...

  •  

    What is the difference between java and core java

    Rohit Manjunath Balekundri

    • Jun 8th, 2017

    Java: is a object oriented language for building platform independent application with OOPS concepts with set of API provided by Oracle. Originally it was owned Sun micro systems.

    Core Java: is a core/basic API to develop desktop applications.

    Ankur

    • May 31st, 2017

    Core Java is part of Java. Java has Core Java (J2SE), J2EE, J2ME.

  •  

    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 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...

  •  

    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...

  •  

    What is the difference between Static and final?

    Jitendra singh

    • Sep 23rd, 2015

    Actually main reason that new make a class create only print my name not use object. You can create a simple program without using object this reason Java not 100% object oriented language {geshibot l...

    SHWETHA g

    • Aug 31st, 2015

    "Static" keyword is used to a variable/method where a value of that variable has to be common to all objects created for example: bank interest rate for farmers loan common to all farmers.
    where as "final" is to make a method or variable that should not be modified once after implementing.

  •  

    What is the difference between a CallableStatement and PreparedStatement?

    kalyankarri

    • Dec 27th, 2014

    Callable stmt is used to call stored procedure,prepared stmts executes sql queries.

    satyendra kumar

    • Dec 2nd, 2014

    Prepared statement available in java.sql package and its extends statement but callable statement is available in java.sql package and its extends prepared statement ....

  •  

    Why do we write String args[] in main of the program?

    muskan

    • Jul 29th, 2013

    We have to write String args[] in main to run a program, because JVM(java virtual machine) can only recognize the main with string array as parameter, as starting method or a point.

    Gajavelli shiva krishna

    • Jul 18th, 2013

    We write in string args[] in main in Java because string args[] means it allows string of array objects

  •  

    MVC architecture

    what is the difference between MVC1 & MVC2 in Java?

  •  

    Adding Method in Java

    Hi

    I have interface in that interface 3 methods are there , after some days client said that,i want to add one more method in that interface ,so how can add 4 method so that the implemented class did not affect,

    Thanks

    Kalins Naik


    akii

    • Apr 30th, 2013

    Make a class abstract in this class you do not need to implement all methods of interface .

  •  

    Can a method be static and synchronized

    Star Read Best Answer

    Editorial / Best Answer

    Answered by: Srimant Misra

    • Aug 12th, 2005


    A static method can be synchronized. If you do so, the JVM will obtain a lock on the java.lang.Class instance associated with the object. It is similar to saying: 
    synchronized(XYZ.class) 

    }

    Akii

    • May 21st, 2013

    If you synchronized on static method ,its lock on class level not only that method.

  •  

    Platform Independence

    Why platform independence is needed in real world ?

    Praveen Kumar

    • Dec 13th, 2012

    Yes Java is Platform independent. When you compile your program, the java compiler provides you with a class file which consists of intermediate representation of the code. when you run this class fil...

    SOWJANYA

    • Dec 10th, 2012

    Write once and run anywhere, that means if we develop one application on one operating system and for using it will execute on any operating system.

  •  

    Object Creation

    In how many ways we can create an object? Explain with example.

    Star Read Best Answer

    Editorial / Best Answer

    vishrutha  

    • Member Since Feb-2009 | Feb 13th, 2009


    1. Using new keyword
    This is the most common way to create an object in java. I read somewhere that almost 99% of objects are created in this way.

    MyObject object = new MyObject();

    2. Using Class.forName()
    If we know the name of the class & if it has a public default constructor we can create an object in this way.

    MyObject object = (MyObject) Class.forName("subin.rnd.MyObject").newInstance();

    3. Using clone()
    The clone() can be used to create a copy of an existing object.

    MyObject anotherObject = new MyObject();
    MyObject object = anotherObject.clone();

    4. Using object deserialization
    Object deserialization is nothing but creating an object from its serialized form.

    ObjectInputStream inStream = new ObjectInputStream(anInputStream );
    MyObject object = (MyObject) inStream.readObject();

    5. Using class loader
    one more is through creation of object using classloader like

    this.getClass().getClassLoader().loadClass(com.amar.myobject).newInstance();

    Now you know how to create an object. But its advised to create objects only when it is necessary to do so.

    Max

    • Sep 7th, 2011

    All sorts of syntax sugar can also be named: 6. New String as a result of concatenation: String varName = getClass().getName(); //to avoid compile-time optimization String a = "Prefix" + varName; ...

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