GeekInterview.com
Answered Questions

System.Out.Println()

Asked By: nikhil.petkar | Asked On: May 7th, 2009

Why do we use 'out' in system.Out.Println();?

Answered by: r.praveenkumar on: May 8th, 2009

out is the object of printstream class... System.write() will write in byte stream fashion.. but System.out.println() will write in character stream format..

Answered by: myogeshchavan97 on: May 8th, 2009

out is a object of System class.
It is used to display output on the console.

Thread disadvantages

Asked By: ankitchauhan22 | Asked On: Apr 11th, 2009

What are the disadvantages of using thread?

Answered by: r.praveenkumar on: Apr 11th, 2009

while using threads, each thread has access to object's instance variable. so while one thread is making changes to that instance variable, another thread may access it. It results in inconsistenc...

Userdefined unchecked exceptions

Asked By: Jagadish.gadarla | Asked On: Sep 16th, 2008

Java has userdefined unchecked exceptions or not? If answer is yes, how to create userdefined unchecked exceptions?

Answered by: r.praveenkumar on: Sep 17th, 2008

i think there is no possibility of creating user defined unchecked exceptions.

Answered by: aleemkh on: Sep 17th, 2008

Unchecked exceptions are those which extend RunTimeException? what do you mean by userdefined unchecked exceptions? Unchecked exceptions are thrown only at run time. The question is ambiguous.

Why is that the final variable has to be initialized as soon as it is declare?

Asked By: vishalanand_154 | Asked On: Jul 31st, 2008

Star Read Best Answer

Editorial / Best Answer

Answered by: r.praveenkumar

View all answers by r.praveenkumar

Member Since Oct-2007 | Answered On : Aug 1st, 2008

when a variable is declared as final we cant change its value again. we use final variable to declare a constant so when we declare a variable as final and if we were allowed to not to give its value at the time of declaration it would not make sense so people who designed java made mandatory to give the value when we declare a final variable. then only it will be sensible.
final PI=3.14;
then we cant change PI's value. think if the above statement do not contain a vl it would not make sense.

Answered by: Nitin Maulekhi on: Jul 18th, 2012

final keyword can be applied on:- 1.class 2.member functions(only non-static) 3.data-members(both static and non-static) 4.local variables. 1.by making a class final ,that class cannot be inherited....

Answered by: Rohit Verma on: Jul 10th, 2012

Like any variable, a final variable can also be first declared and then assigned a value. But it can be only assigned a value once and only once ( as its final variable ). for example :- final Strin...

Overriding methods

Asked By: vishalanand_154 | Asked On: Jul 31st, 2008

Suppose a super class method throws an exception and this method is overriden in the subclass with no exception. Now if you create a super class reference that has a subclass object. This throws a compile time error, why?

Star Read Best Answer

Editorial / Best Answer

Answered by: bharathnav

View all answers by bharathnav

Member Since Oct-2008 | Answered On : Oct 13th, 2008

"Suppose a Super Class method throws an exception and this method is Overriden in the subclass with no exception. Now if you create a super class reference that has a subclass object. This throws a compile 
Latest Answer: Because at run time, the super class will compiled first, so it will gives the run time error. ..."

if the object has been created to the subclass and both the methods are non static then the method we overriden doesn't produce any errors or exceptions.

Answered by: sampra on: Mar 6th, 2012


if the object has been created to the subclass and both the methods are non static then the method we overriden doesnt produce any errors or exceptions.

Answered by: techbuz on: Dec 23rd, 2011

throws exception in super class doesnt affest over-riding:code eg as follows: "java public class Ride{ void clay(){ System.out.println("am in base class"); } public static voi...

Static data member

Asked By: amitjhjsr | Asked On: Jul 12th, 2008

What is the use of static data member?

Answered by: Sarje on: Aug 13th, 2009

Static data members field (variable) and method belong to class. Static fields can be used before creating an instance of the class and static method can be accessed using class name.

Answered by: aditya_8584 on: Mar 24th, 2009

Static data member has a class scope. A single copy of static data member get shared within the objects of that class. A non-static member cannot access a static member of that class.

Exception handling

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

What is the output of the following program, when tested under jdk 5.0class exceptiondemo{ public static void main(string[] args) { int a[] = new int[] {1,2,3,4,5}; try{ system.Out.Prinltln(a[6]); } catch(exception e) { system.Out.Println("catching exception ..."); ...

Answered by: kuchipudi Prasad on: May 30th, 2012

Output is "catching exception"

Answered by: sampra on: Mar 6th, 2012

This will give error that exception caught already

What will be the result and why

Asked By: Arnab.infinity | Asked On: Mar 19th, 2008

Int i=10;i=i++;system.Out.Println(i);

Answered by: jawaharl0207 on: Nov 30th, 2009

11, because even it is post increment, it will increment by 1 when it is going to reach println() statment, for the first statement(i++;) it wont increment, after completing the execution of this method i incremented by 1 and prints the result.

Answered by: sujithkthomas on: Nov 12th, 2009

Yes this is similar to
temp = i;
i = i+1;
i = temp;
It will restore the value 10 since post increment. If its pre-increment last assignment will be i = temp+1

Difference between Java and j2ee

Asked By: tanu84 | Asked On: Mar 10th, 2008

Explain the difference between Java and j2ee in detail?

Answered by: deepak_tandon2005 on: Jun 30th, 2008

java refers to basic concept of java as well as new technical features making foundation of java/j2ee.
j2ee is used for enteprise application based on java concept.
if java is foundation then j2ee is building for business purpose. 

Answered by: r.praveenkumar on: Mar 19th, 2008

java refers to core java and j2ee refers to the technologies that are developed using java. for example inheritance, exception handling, multithreading are some of the concepts in java and servlets, R...

Inheritance

Asked By: chaitugoud | Asked On: Feb 13th, 2008

What is inheritance? Why we use it? Plzz can anybody explain me with one example and where we use that concept?

Answered by: navneet.navu on: Apr 19th, 2010

It is an object oriented feature which provides the reusablity of code. All the properties defined in the parent class can be used by its child classes without writing the code again.

Answered by: Samuel Rengarajan on: Dec 11th, 2009

All Common features are come to parent class. So we can extend this class to child classes. Child classes contais some special features.

Useage of inheritance : it reduce the code. If we use inheritance, we avoid redundent code.

Convert string object to primitive integer type

Asked By: tapan_1984 | Asked On: Feb 3rd, 2008

How can I convert a string object to a primitive integer type???????Thanks

Answered by: maddy_me on: Sep 18th, 2009

class StringConver{ public static void main(String[] s) {     //String s1 = "Hello"; If you try this you will get NumberFormatException     ...

Answered by: r.praveenkumar on: Sep 17th, 2008

if u try to convert "hello" to int u will get NumberFormatException

Does Java support pass by reference. If yes/no- why?

Asked By: sha_kr2001 | Asked On: Dec 21st, 2007

Answered by: babusek on: Dec 22nd, 2010

Java Does not Support Pass by Reference

Answered by: uncer on: Jan 17th, 2010

Java does not support pass by reference. Java actually pass-by-value for all variables running within a single VM. pass-by-value means pass-by-variable-value and that means pass-by-copy-of the variabl...

What happens if public static void main(){} is made protected?

Asked By: venkat | Asked On: Nov 20th, 2007

Star Read Best Answer

Editorial / Best Answer

Answered by: Sushil Jain

Answered On : Nov 21st, 2007

You will be able to compile but it will through a run time error saying "main method not public".

Answered by: AA on: Apr 22nd, 2012

It will compile but gives error at run time......

Answered by: divya_mini4u on: Sep 21st, 2010

The complier will throw error that there is no main()  method. main() should be public always please note.

How can you convert a string value into integer and viceversa in Java

Asked By: rama | Asked On: Oct 11th, 2007

Answered by: r.praveenkumar on: Nov 19th, 2007

String s="10";
int a= Integer.parseInt(s);  //Integer.parseInt() method is used to convert str to int

Answered by: sarathi trichy on: Oct 25th, 2007

String a='5';
int i;
i=int(a);

Could any one explan me what happens in this program. Main(){ int i=10; i=(++i)/(i++); printf("i=%d",i); }

Asked By: vaasu | Asked On: May 21st, 2006

Answered by: KishoreKNP on: Dec 2nd, 2009

The answer is 2, because  the statement
i = (++i) / (i++)

will be processed from left to right
i = (++10) / (10++)

which means

i = 11/10++

Here still ++ operator is not executed

i = 1++; // 1 because it is an integer operation
i = 2;

if you change
i = (++i) / (++i) you will see 1

Answered by: r.praveenkumar on: Mar 9th, 2008

chethan is write

The term _____________ refers to a class's direct ancestor or to any of its ascendant classes.

Asked By: Interview Candidate | Asked On: Jan 9th, 2006

Skill/topic: inheritancea) sub classb) super classc) class hierarchy

Answered by: minisharma17 on: Oct 7th, 2008

sub class

Answered by: r.praveenkumar on: Jul 10th, 2008

super class

What is the output of the following? // a simple example of recursion.Class factorial { // this is a recursive method int fact(int n) { int result; if(n==1) return 1; result = fact(n-1) *...

Asked By: Interview Candidate | Asked On: Dec 10th, 2005

A) factorial of 3 is 3b) factorial of 3 is 6c) factorial of 3 is 9d) none of the above

Answered by: r.praveenkumar on: Feb 25th, 2009

Ans is (d) None of the above

Because we are not defining else part of the if statement.

Unreachable code error because of the absence of else part.

Answered by: Sheriffh on: Feb 24th, 2009

D)None of the above

Java allows objects to initialize themselves when they are created using _________

Asked By: Interview Candidate | Asked On: Dec 10th, 2005

A) argumentsb) classesc) constructorsd) parameters

Answered by: r.praveenkumar on: Aug 5th, 2008

Yes objects can be created only using constructors if we do not provide one compiler will create a default cons for us thus allocating memory for objects we are going to create and the default values ...

Answered by: mrsunilg on: Aug 5th, 2008

Yes, Constructors only initializes the object.

When we create a class, we are creating a new data type

Asked By: Interview Candidate | Asked On: Dec 10th, 2005

A) trueb) false

Answered by: r.praveenkumar on: Jul 14th, 2008

true

Answered by: ksrikanth5g on: Jul 14th, 2008

False

When you read your e-mail, you are viewing _________ data

Asked By: Interview Candidate | Asked On: Dec 10th, 2005

A) activeb) passivec) bothd) none of the above

Answered by: myogeshchavan97 on: Feb 14th, 2009

When we read e-mail, we are viewing passive data.

Answered by: Sheriffh on: Feb 13th, 2009

Passive

What is the data type for the parameter of the sleep() method?

Asked By: Interview Candidate | Asked On: Dec 10th, 2005

A) doubleb) intc) longd) float

Answered by: myogeshchavan97 on: Feb 16th, 2009

int type is the parameter of sleep() method.

Answered by: r.praveenkumar on: Feb 16th, 2009

long is the correct answer.

Abstract class a{void display(){}}class b extends a{void display(){}psvm(string args[]){how can I instantiate the overridden method in class a}}

Asked By: vishnu | Asked On: Oct 27th, 2005

Answered by: r.praveenkumar on: Apr 10th, 2009

all three answers above are correct. in 3rd one we are assigning object of B to reference of B itself. But in first and second answers we are assigning object of B to Reference of A. In all three cases JVM will invoke B's display() only.

Answered by: anithananduri on: Apr 9th, 2009

abstract class A {     void display()     {     } }class B extends A {     void display()     {   &n...

Can we declare multiple main() methods in multiple classes.Ie can we have each main method in its class in our program?

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

Answered by: r.praveenkumar on: Aug 5th, 2008

Yes I tested this we can have main method in two different classes this will not give error and we should save that doc with the class name which has the main we want to be executed first and inside t...

Answered by: vinaymudgil007 on: Jun 3rd, 2008

yes this is possible...... but within a single file only one class can be declared puiblic!!!!
and whichever class you run, that class's main() mentod would be called.......

vinny

comment: C++ "includes" behavior and Java "imports"

Asked By: Interview Candidate | Asked On: Jun 24th, 2005

Answered by: whenkeys on: Aug 11th, 2008

Both behave the same way except that when we import in java we can import single class also but we have to include a file and not a Class in C++.eg: import java.lang      ...

Answered by: r.praveenkumar on: Mar 19th, 2008

by using include preprocessor kn c++  the program size will be slightly increased but when we use import statement in java the program size will not be increased at all

what will happen to the exception object after exception handling

Asked By: Interview Candidate | Asked On: Jun 24th, 2005

Answered by: r.praveenkumar on: Mar 19th, 2008

exception object can be caught only once after it was caught i think it will be eligible for garbage collection. Not that it will be immediately destroyed but it will be destroyed soon if we are not using that object to detect what kind of exception it is.

what is the method used to clear the buffer

Asked By: Interview Candidate | Asked On: Jun 24th, 2005

Answered by: r.praveenkumar on: Aug 7th, 2008

BufferedWriter obj=new BufferedWriter(new FileWriter(new File("test.txt")));obj.write("hai");    //after this without using flush if u close obj "hai" will...

Answered by: mrsunilg on: Aug 6th, 2008

flush();

Interview Question

 Ask Interview Question?

 

Career Counselling

 Have Career Question?

 Ask Chandra

 Ask Only Career questions.

Follow us: