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
Is Java a fully object oriented programming or not? If not why?
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
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
Answered by: Srimant Misra
Answered On : Aug 12th, 2005A 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)
{
}
If you synchronized on static method ,its lock on class level not only that method.
yes a method can be static and synchronized
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
make a class abstract in this class you do not need to implement all methods of interface .
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
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)"?
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.
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
Abstract class can be extends, while in case of final class we cant do it.
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?
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...
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...
What is the difference between mvc1 & mvc2 in Java?
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?
How an treeset maintains the unique element? Which algorithm does it use? what is the advantages over doing the same using the arraylist manually?
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.
It uses Red-Black tree alogorithm.
Why Java does not support multiple inheritance?Why Java is not pure object oriented?
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.
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.
What is the default value for tostring() in Java? Explain me with an example?
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.
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?
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.
Using assertion keyword.
How many ways we can create object ?
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
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
Can we decalre Java inner class as priVATe and protected? if yes....Please explain if no....Please explain
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.
Why platform independence is needed in real world ?
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...
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??
Please answer my question....
Based on hashcode the data is saved in hashtable.
hashcode
Why we can not override static method?
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
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?
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...
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?
If yes then how?
No because we all know we cannot override static method. It is a final method.
main method is static.
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?
Yes we can.
As main is static we cant declare final.
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 :-)
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
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...