GeekInterview.com
Series: Subject: Topic:

Core Java Interview Questions

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

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: void on: Jun 6th, 2013

ArrayIndexOutOfBounds Exception :
indexing starts from 0, and Since only 3 arguments are passed from the CLA
Java will fail to find the 4th argument when trying to search for s[3] and hence it will result in a compilation error

Answered by: akii on: Apr 30th, 2013

exception will be come when using class: java.lang.ArrayIndexOutOfBoundsException: 1 , because 12345 input comes at s[0] places and when we are getting s[1] it come java.lang.ArrayIndexOutOfBounds...

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

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

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

Answered by: chaithanya chatla on: Dec 27th, 2012

Java is fully Oops language ..even though it is having primitive datatypes again it is having corresponding wrapper classes for each and every primitive datatype..

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: 
synchronized(XYZ.class) 

}

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

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: akii on: Apr 30th, 2013

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

Answered by: Vaibhav on: Aug 20th, 2012

You can use inheritance for that... You can inherit new class from the Existing class and add the method in that.

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

Answered by: Praveen Kumar on: Dec 13th, 2012

There is no way to determine which thread is executed first, it is solely dependent on the scheduling algorithms adapted by the operating system and underlying hardware architecture, one way to guarantee the that the thread runs in a particular order is using synchronized methods.

What is the difference between abstract class & final class

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

Answered by: Nikhil Srivastava on: Apr 7th, 2013

Abstract class can be extends, while in case of final class we cant do it.

Answered by: AWADHESH on: Dec 3rd, 2012

An abstract class is a class which must be sub-classed and a final class is a class which cant be sub-classed. That means to get the functionaity of an abstract class we must sub class it and use the ...

What is the difference between static and final?

Asked By: Gaurav Sharma | Asked On: Oct 25th, 2006

Answered by: venkata on: Mar 18th, 2013

Static: Attributes whose value remains same throughout all its instances , But can be changed by Any instance Final: Attributes whose values remains same throughout every Specific instance of the clas...

Answered by: sampra on: Feb 11th, 2008

static varibale is a such type varible which loaded in to memory at class loading tim only one copy of varible is accessble in entire programfinal variable is such type varible which value we cant cha...

Mvc architecture

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

What is the difference between mvc1 & mvc2 in Java?

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

How treeset implementation maintains unique elements in it?

Asked By: shreekarjain | Asked On: Nov 16th, 2012

How an treeset maintains the unique element? Which algorithm does it use? what is the advantages over doing the same using the arraylist manually?

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

Tree Set using internally HashTable for storage the objects using of key and values. Internally its using hashing mechanism. It displays the order on Ascending order.

Answered by: Nikhil on: Feb 20th, 2013

It uses Red-Black tree alogorithm.

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

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

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.

Answered by: pmetha2 on: Jan 3rd, 2013

Actually,Multiple Interfaces are inherited but by inherting them,we wont get any defination(its just a blank body).
so, Java supports Multiple Inheritence is a Myth.Its just an illusion.

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

Answered by: sampra on: Mar 6th, 2012

toString() will do the object representation of data(Object) into String representation

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

Asked By: Raj | Asked On: May 6th, 2007

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

Answered by: Hariom Singh on: Jan 25th, 2013

Using assertion keyword.

How many ways we can create object ?

Asked By: kishore | Asked On: Nov 8th, 2006

Answered by: chandrasekhar rao naidu on: Feb 8th, 2013

3 ways

1. new Operator,
2.object class clone() method
3.newInstance()
these are main.
and another ways also there
1.class.forName()---------> this method internally uses the newInstance method,
2.Deserialization-----> this is also internally use the above 3 ways

Answered by: Sreenivasulu B on: May 17th, 2012

We can create an object in java by six ways.......

1.new operator
2.class.forName
3.Factory Method
4.Cloning
5.Deserialization
6.Reflection API

Inner class

Asked By: vshri12 | Asked On: Jan 24th, 2013

Can we decalre Java inner class as priVATe and protected? if yes....Please explain if no....Please explain

Answered by: Priya on: Jan 28th, 2013

If it is a Regular Inner Class or Static Inner class private and protected modifiers can be applied. If it is a method local inner class, then we can use only abstract or final modifier.

Platform independence

Asked By: nitya123 | Asked On: Sep 9th, 2012

Why platform independence is needed in real world ?

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

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

JVM uses which one of these to save hashcode,hashtable or hashmap or hashset??

Asked By: Divya6171 | Asked On: Aug 20th, 2012

Please answer my question....

Answered by: sowjanya on: Dec 10th, 2012

Based on hashcode the data is saved in hashtable.

Answered by: manvi on: Sep 30th, 2012

hashcode

Why we can not override static method?

Asked By: sachinTest | Asked On: Aug 9th, 2006

Answered by: Muhammed Younus Attari on: Nov 28th, 2012

For calling every method either we need an Object or ClassName,
static is one which can be called directly, main is defined as static because it can be called directly by JVM

Answered by: Ganga_busi on: Oct 26th, 2012

The static method is public final method , which is called by JVM directly before initializing the instances.
thats why we create our java main method (ie., public static void main(String args[])) as a static and this method is in side the user defined class.

Why should every class in Java extend object class?

Asked By: kalyan | Asked On: Apr 19th, 2006

Answered by: sushant on: Nov 17th, 2012

If you see the definition of class Object, it is defined as "Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the metho...

Answered by: Sandhya on: May 26th, 2006

Hey Guys,Object class implements a set of methods and variables which are common to all the objects being created in the application. This is the main reason why we have Object class as a base class f...

Is it possible to override the main method in Java?

Asked By: aparesh_c | Asked On: Aug 4th, 2012

If yes then how?

Answered by: RAJASEKAR on: Oct 27th, 2012

No because we all know we cannot override static method. It is a final method.

main method is static.

Answered by: avinash on: Sep 26th, 2012

we cant override static methods in java.if we take main() in sub class that is method hiding not overriding.

Can we declare main() as final?

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

Answered by: visal Sigh on: Oct 26th, 2012

Yes we can.

Answered by: manas on: Jul 7th, 2012

As main is static we cant declare final.

First | Prev | | Next | Last Page

 

 

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

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.