What are the disadvantages of using thread?
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
Java has userdefined unchecked exceptions or not? If answer is yes, how to create userdefined unchecked exceptions?
i think there is no possibility of creating user defined unchecked exceptions.
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?
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.
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....
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...
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?
Answered by: bharathnav
View all answers by bharathnav
Member Since Oct-2008 | Answered On : Oct 13th, 2008
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.
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...
What is the use of static data member?
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.
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.
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 ..."); ...
Output is "catching exception"
This will give error that exception caught already
What will be the result and why
Int i=10;i=i++;system.Out.Println(i);
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.
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
Explain the difference between Java and j2ee in detail?
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.
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...
What is inheritance? Why we use it? Plzz can anybody explain me with one example and where we use that concept?
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.
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
How can I convert a string object to a primitive integer type???????Thanks
class StringConver{ public static void main(String[] s) { //String s1 = "Hello"; If you try this you will get NumberFormatException ...
if u try to convert "hello" to int u will get NumberFormatException
Does Java support pass by reference. If yes/no- why?
Java Does not Support Pass by Reference
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?
Answered by: Sushil Jain
Answered On : Nov 21st, 2007You will be able to compile but it will through a run time error saying "main method not public".
It will compile but gives error at run time......
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
String s="10";
int a= Integer.parseInt(s); //Integer.parseInt() method is used to convert str to int
String a='5';
int i;
i=int(a);
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
chethan is write
The term _____________ refers to a class's direct ancestor or to any of its ascendant classes.
Skill/topic: inheritancea) sub classb) super classc) class hierarchy
sub class
super class
A) factorial of 3 is 3b) factorial of 3 is 6c) factorial of 3 is 9d) none of the above
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.
D)None of the above
Java allows objects to initialize themselves when they are created using _________
A) argumentsb) classesc) constructorsd) parameters
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 ...
Yes, Constructors only initializes the object.
When we create a class, we are creating a new data type
A) trueb) false
true
False
When you read your e-mail, you are viewing _________ data
A) activeb) passivec) bothd) none of the above
When we read e-mail, we are viewing passive data.
Passive
What is the data type for the parameter of the sleep() method?
A) doubleb) intc) longd) float
int type is the parameter of sleep() method.
long is the correct answer.
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.
abstract class A { void display() { } }class B extends A { void display() { &n...
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...
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"
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  ...
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
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
BufferedWriter obj=new BufferedWriter(new FileWriter(new File("test.txt")));obj.write("hai"); //after this without using flush if u close obj "hai" will...
flush();
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..
out is a object of System class.
It is used to display output on the console.