Sachin Kombrabail

Greenhorn
+ Follow
since Aug 28, 2000
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sachin Kombrabail

I am assuming that you intentionally do not want to implement all the methods that you have defined in your interface. One solution is to go back and implement all the methods of the interface. The other solution is to define an Adapter class. This class implements the interface and has empty implements for each. You can then subclass that adapter and define only those methods that you want. So first decide whether you want to implement all the methods or not.
Hi Guys,
Take a look at this example code
public class Outer
{
final int i = 10;
int j=5;
public void callme()
{
int k=9;
class Inner
{
public void innercalls()
{
System.out.println("i="+i);
System.out.println("j="+j);
System.out.println("k="+k);
}
}
Inner i = new Inner();
i.innercalls();
}
public static void main(String[] argv)
{
Outer o = new Outer();
o.callme();
}
}
If you try and compile this code, you will get a compilation error. The error is not for j which is not defined as final in the outer class but for k which is NOT defined as a final in the method. This means that an inner class which is defined within a method has access to all the variables defined in the outer class but to have access to variables defined within the method these variables have to be defined as final.
When we say that Strings are immutable, we mean the String object. The moment you copy the contents of a string object into a StringBuffer, it is a different object altogether. Nobody said that StringBuffers are immutable. So we can do anything with StringBuffer objects , but not String object.
Can you tell me which book told you that?
HiSadashiv,
As far as I can remember under JDK1.1 you use to have two library files in the LIB directory of JDK these were javai.lib and javai_g.lib. I think these files no longer exist in JDK1.2.
But it is possible to load these library files using the load command. Probably the documentation that you are seeing explains the naming convention that you need to use to load .lib files.
i/o

First of all when you created the file object using new File("\\12345.msg"), it will be looking for a file in the C:\ directory and not C:\JAVA directory. Methods like getPath, getParent, iaAbsolute, getName will be using the filename to give you the result. It is only when you come to exists() that it really tries to find out whether the file is there or not. Since you are looking in the wrong directory it will not find the file there and will give you a false. Same is true with isFile().
Why don't you change your new File() to the correct path of the file and see how it works.
Hi All,
Just wanted to ask Shikhar which version of the java compiler he is using. I have JDK1.3 and the only error that I get in the code sample that you gave was first an error that there was a } less. Once I corrected that it gave me the following error
Base.java:4: variable MAX_SIZE might not have been initialized
Base(){
That is all.
The InputStream is an abstract class whose subclasses are
ByteArrayInputStream, FileInputStream, FilterInputStream, InputStream, ObjectInputStream, PipedInputStream, SequenceInputStream, StringBufferInputStream

-> sb1 == sb2 is false Since the object references will be will be compared
-> sb1.equals(sb2) is false since StringBuffer does not have an equals method so the Object's equals method will be called (which does a comparision of the references)
-> sb1.equals(ss1) is false. for the same reason as sb1.equals(sb2)
-> "Poddar".subString(3) will give you "dar" provided you spell subString(3) with a lowercase 's' as substring(3).

The result that you will get is
a. byte b=(byte)255; (value will be -1)
b. byte b=(byte)128; (value will be -128)
c. byte b=(byte)-128; (value will be -128)
d. byte b=(byte)127; (value will be 127)
So from this the answer is (a) & (b).
The reason why this happens is given with examples in the JLS.
"The results for byte and short lose information about the sign and magnitude of the numeric values and also lose precision. The results can be understood by examining the low order bits of the minimum and maximum int. The minimum int is, in hexadecimal, 0x80000000, and the maximum int is 0x7fffffff. This explains the short results, which are the low 16 bits of these values, namely, 0x0000 and 0xffff; it explains the char results, which also are the low 16 bits of these values, namely, '\u0000' and '\uffff'; and it explains the byte results, which are the low 8 bits of these values, namely, 0x00 and 0xff."

The result that you will get is
a. byte b=(byte)255; (value will be -1)
b. byte b=(byte)128; (value will be -128)
c. byte b=(byte)-128; (value will be -128)
d. byte b=(byte)127; (value will be 127)
So from this the answer is (a) & (b).


There can be three ways in which castMe can be called. Let us see how each will react.
1. If you pass an instance of C1 then the method will try to cast into C3 this will give you a ClassCastException since java does not support downcasting.
2. If you pass an instance of C2 then the same message as in C1.
3. If you pass an instance of C3 that will go through.
So (c) is the only answer for your question.

As per my understanding
1. Both interfaces & abstract classes cannot be explicitly instantiated.
2. Even a single method being defined abstract makes the class abstract.
3. All the methods of an interface HAVE to implemented by the implementor.
4. Unlike a interface, a method of an abstract class can have default implementation.
5. A class can extend a single parent but can implement multiple interfaces.
6. The only thing that a class can inherit from an interface is the message signatures. From an abstract class you can inherit the default implementations.
For a good example take any listener say the WindowListener which is an interface. If you want to implement it you have to implement all the 7 methods that are there in the interface. Now look at the WindowAdapter. This is an abstract class which has implemented all the methods of the WindowListener but all the implementations are empty. To make use of this combination you will have to extend the WindowAdapter and only code that method you want.
Hi All,
To answer you question let me quote the JLS
1. Literal strings within the same class in the same package represent references to the same String object .
2. Literal strings within different classes in the same package represent references to the same String object.
3. Literal strings within different classes in different packages likewise represent references to the same String object.
4. Strings computed by constant expressions are computed at compile time and then treated as if they were literals.
5. Strings computed at run time are newly created and therefore distinct.
6. The result of explicitly interning a computed string is the same string as any pre-existing literal string with the same contents.
Now in our example there is no runtime allocations at all. The string literals "Hi" & "There" are created at compile time and are assigned. GC will only retrieve memory that has been allocated at runtime. One statement s2+=s1 does create a new string. But then it is never nulled. So i don't think that there is any scope for any GC in the program.