Series: Subject: Topic:

Core Java Interview Questions

Showing Questions 1 - 20 of 575 Questions
First | Prev | | Next | Last Page
Sort by: 

What is the use of interface in realtime Java project ?

Asked By: Raman KD | Asked On: Sep 16th, 2013

Answered by: prabhu.S.R on: Feb 16th, 2014

To import many subclasses.

Answered by: Sumit Thakkar on: Feb 6th, 2014

Interface allows to various design patterns, encapsulate the changing parts. some design patterns totally rely on interfaces for dynamically assigning the objects to perform functionality without major change in the code.

Determining the order of threads

Asked By: Sumantra_07 | Asked On: Jun 27th, 2012

Q.--" I created five(5) thread instances,say "1","2","3","4","5" and start all of them at the same time,one after the other. The priorities for the threads are same.What should be done so that the threads run concurrently in the same order,i.E1,2,3,4,5(is there any way at all)"?

Answered by: Vijay on: Jan 10th, 2014

We can do that by using the join. In the second thread run method, we can call the join on first thread object. In the third thread run method, we can call the join on second thread object. Like this ...

Answered by: mduhan on: Apr 8th, 2013

We have to implement run method to create a thread.We need to make that method synchronized so that only one thread can go inside and control will be given to second only and only of first is completed.

Guess the output of the following program

Asked By: pardeep131085 | Asked On: Nov 29th, 2013

Try to guess without running the program.

  1. public class IntegerClassExampleThree {
  2.  public static void main(String[] javalatte) {
  3.   Integer i = 400;
  4.   Integer j = 400;
  5.   if(i==j){
  6.    System.out.println("i==j is equal");
  7.   }else {
  8.    System.out.println("i==j is not equal");
  9.   }
  10.  }
  12. }
  13. public class IntegerClassExampleFour {
  14.  public static void main(String[] javalatte) {
  15.   Integer i = 127;
  16.   Integer j = 127;
  17.   if(i==j){
  18.    System.out.println("i==j is equal");
  19.   }else {
  20.    System.out.println("i==j is not equal");
  21.   }
  22.  }
  24. }

Answered by: onkar on: Dec 28th, 2013

1. First of all in one java file you can not have two public classes. 2. Second you will have to run a particular public class "java classname" and then its main method would run. Note - If there i...

Answered by: prashanth on: Dec 2nd, 2013

i==j is not equal

Synchronization in Java

Asked By: sathyasha | Asked On: May 30th, 2008

When we should use synchronization in Java and when we should not?

Answered by: sivapurammani on: Dec 16th, 2013

In simple terms we can say only one thread can act on selected resource(method or variable). Understanding the above sentence is as follows:: For example we are booking any ticket in a particular bu...

Answered by: Yeswanth on: Dec 6th, 2013

if you want to allow only one thread at a time to access block of code or method then we will go for synchronization.

  1. public synchronized
  2. void singleProcess() {
  3. // Insert code here
  4. }

Why we are using OOPS?

Asked By: narendra_d | Asked On: Oct 27th, 2011

Answered by: sivapurammani on: Dec 16th, 2013

Before introducing OOPS some other concepts are also introduced into the computer world, for example Procedure Oriented Language(The best example for this is C language) but these concepts are working...

Answered by: mukesh jha on: Aug 8th, 2013

OOPS  stands for object oriented programming . They are   1. Abstraction 2. Encapsulation 3. Inheritance 4. Polymorphism Abstraction is representation of  some property without giving backgroun...

What is the difference between abstract class & final class

Asked By: abhipsa | Asked On: Sep 30th, 2006

Answered by: sivapurammani on: Dec 3rd, 2013

If any class is declared as final class then other classes cannot able to interact with the final class i.e it is not possible to use the variables as well as methods of final class. But if we declar...

Answered by: naveen on: Nov 25th, 2013

Abstract class contains Abstract methods and normal methods. Where Abstract methods do not have any body. The implementation of abstract methods will be in their sub class.

Final class is a class where we cannot create any subclass to the final class.

Generating ppt through Java

Asked By: dinshetty | Asked On: Jul 11th, 2008

I am trying to generate ppt through Java using apache poi API. I am able to create table, bulleted text etc using this API. Please answer the following two questions, if anyone is aware of this. 1. How to split text across two slides, if the row had to be broken across 2 slides because the row is...

Answered by: Omen on: Nov 8th, 2013

Try this Java Library, i hope it will solve your problem:

Answered by: km.raghumudri on: Oct 8th, 2008

If data contains in the list, try to use two for loops. Or else list element is having the long text, try to use wrap text method, Try to verify POI API.

What is throwable and where should we use this?

Asked By: veera | Asked On: Dec 20th, 2006

Answered by: mukesh on: Oct 21st, 2013

In the Try Block
Caught in Throwable class

Answered by: santh kumar on: Dec 20th, 2006

" Throwable " is a class(it's default super class is Object) in java API. The Throwable class is the superclass of all errors and exceptions in the Java language. Only objects that are instances of ...

Output of Java program

Asked By: khadarzone | Asked On: Apr 11th, 2008

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

Answered by: abuthahir.d

View all answers by abuthahir.d

Member Since Jan-2008 | Answered On : 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  :-)

Answered by: Aneesh on: Oct 11th, 2013

s[1]+s[2]+s[3]=>s[0]+s[1]+s[2] javac java A 1 2 3 123

  1. class A{
  3.     public static void main(String[] s) {
  4.         System.out.println(s[0] + s[1] + s[2] ); // 3 args
  6.        // System.out.println(s[3]);
  7.     }
  8. }

Answered by: saheb on: Sep 4th, 2013

it will compile successfully but it will give ArrayIndexOutOfBoundException...
to run try System.out.print(s[0]);

Why Java does not support multiple inheritance?Why Java is not pure object oriented?

Asked By: vas | Asked On: Sep 18th, 2005

Answered by: ashutosh joshi on: Sep 23rd, 2013

Because the JVM can confuse while calling the overriding method defined in both the superclass for a subclass with a same name.For avoiding this we do not use multiple inheritance in java.

Answered by: Nitin Kumar Singh on: Mar 7th, 2013

In Java we have the concept of Super() class.
A class may have more than one super class. If there would be Multiple Inheritance then the super() class would be confused which one to refer and so we dont have a concept of Multiple inheritance in Java.

Can array with zero length exist in Java?

Asked By: KanchanT | Asked On: Jul 15th, 2006

Answered by: swapnil on: Sep 17th, 2013

Yes, array size in java is always 0 bz array is start with 0th location

Answered by: sujatham on: Aug 10th, 2007

Yes.Array can have zero length in java.

Can we declare main() as final?

Asked By: naveen.chinthala | Asked On: Feb 9th, 2012

Answered by: Indrajeet Kumar Singh on: Sep 12th, 2013

Yes, We can But we need to follow the order of specifier.

Answered by: smarti on: Aug 29th, 2013

there will be no exceptions occur while using final keyword in main i check it with my editplus editor by writing
simple java program

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

Asked By: manohar | Asked On: Jun 17th, 2007

Answered by: muskan on: 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.

Answered by: Gajavelli shiva krishna on: Jul 18th, 2013

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

Tostring function

Asked By: sandyl2 | Asked On: Jun 30th, 2011

What is the default value for tostring() in Java? Explain me with an example?

Answered by: sivapurammani on: Jul 10th, 2013

Default value is String representation of any Object. "java class Student { int rollNo; String name; public Student(int rollNo, String name){ this.rollNo = rollNo; = n...

Answered by: Nikhil on: Feb 21st, 2013

If toString() method is not overriden, it will return

public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());

This is Object version of this method.

Mvc architecture

Asked By: Murali100 | Asked On: Oct 7th, 2012

What is the difference between mvc1 & mvc2 in Java?

Answered by: sivapurammani on: Jul 10th, 2013

MVC(Model-View-Controller) :: This type of architecture makes our code to be reusable and separation of code. View :: Which presents the modal data, example if we are presenting any tabular data or c...

Answered by: Prasad MN on: Mar 11th, 2013

MVC1: Its a model view Controller architecture 1 that means all the presentation logic and business logic is mixed up. If any modification is required on its impact on the logic. Difficult ...

Is Java a fully object oriented programming or not? If not why?

Asked By: Beena | Asked On: Sep 16th, 2005

Answered by: sivapurammani on: Jul 8th, 2013

Java is not a fully Object Oriented Language because in OOB all the things should be done by Object only but in JAVA we are failing to do that(To be frank intentionally they did that)......For example...

Answered by: srusti on: Jun 7th, 2013

No, 100% sure Java is not fully object oriented programming language. Because multiple inheritance is one of the main concept in oops. But java doesnt support multiple inheritance and it uses primitive data types. hence its not object oriented language

Adding method in Java

Asked By: kalins.naik | Asked On: Aug 15th, 2012

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

Answered by: sivapurammani on: Jul 4th, 2013

If we implement any new method in Interface then by default that method is public and abstract, So the classes which are implementing that interface should implement that method that is one way in whi...

Answered by: akii on: 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

Asked By: Interview Candidate | Asked On: Aug 16th, 2005

Star Read Best Answer

Editorial / Best Answer

Answered by: Srimant Misra

Answered On : 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: 


Answered by: Akii on: May 21st, 2013

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

Answered by: sampra on: Mar 11th, 2008

yes a method can be static and synchronized

Compare two dates from input box using Javascript

Asked By: REENA123 | Asked On: May 14th, 2013

How to compare two dates from input box using Javascript?

Java command line arguments

Asked By: nagaratnapk | Asked On: Mar 25th, 2013

What is the difference between Java command line arguments and C command line arguments?

First | Prev | | Next | Last Page





twitter fb Linkedin GPlus RSS


Interview Question

 Ask Interview Question?


Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.