Java 3 [Interface,string tokenizer]

If interface & abstract class have same methods & abstract class also not contain any implementation for those methods which one you prefer ?

Always Use abstract class because we implement only required methods of abstract class but for interface we must implement all methods whether or required or not.
Obviously one should ideally go for an interface.Coz one can only extend just 1 class where as one can implement as many interfaces as one can.And in case the class under contention has got some threads to invoke or if it is some JFrame kind of class then obviously it would make sense to use the interface.

How can you load DLL files when your java class is loading first time ?

class xxx
{
static
{
System.loadLibrary(String LibraryName);
}
public static void main(String[] args)
{
--------------------------
}
}
Declaring Static block is always a better option than static method.

what is difference between string and stringtokenizer?

StringTokenizer as it is suggested by its name tokenizes a String supplied to it as an argument to its constructor and the character based on which tokens of that string are to be made.The default tokenizing character is space .
A StringTokenizer is utility class used to break up string.

e.g.

StringTokenizer st new StringTokenizer( Hello World );
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}

Output:

Hello

World


We know that Object class is super class of every class & a class extends only one class. so how is it possible to a class to extend other than Object class?

Case 1

suppose you have a class Test which doesn't extend any other class. So by default Object becomes it's super class.

Object->Test

case 2

If your Test class wants to extend some other class for example Hashtable your class will become a sub class of Object through Hashtable because Hashtable is a subclass of Object. Any class you are trying to extend will be a subclass of Object directly or due to hierarchy.

Object->Map->Hashtable->Test

Object is the superclass of Test even when you have Test extend HahTable
So according to case 1 Test is a subclass of Object directly.
According to case 2 Test is a subclass of Object due to the hierarchy.
so no matter you extend a class or not your class will always be a subclass of Object.

Is java a fully object oriented programming or not? if not why?

No. Java is not 100 Pure OOP because of following three reasons:
1) It doesnot support Multiple inheritance.
2) It allows use of primitive data types which are not an objects.
3) It allows static methods to call without creating the instance.

This disobeys OOPs concepts
Java isnt 100 pure OOPS coz if it were then everything should be classes and objects whereas java still has primitive data type which violates the above said statement...SmallTalk is the only 100 pure OOPS language

Post a Comment

أحدث أقدم