Asif Masood

Greenhorn
+ Follow
since Dec 13, 2000
Merit badge: grant badges
For More
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 Asif Masood

I am gettting "java.io.StreamCorruptedException: invalid stream header" exception while trying to read a binay object from MS SQL Server database. I successfully stored this object (this is an object of a text file) earlier.

Here is the code;

ObjectInputStream ois=new ObjectInputStream(rs.getBinaryStream(4));
Object encodedReturn =ois.readObject();

rs.getBinaryStream() returns an invalid stream header.

Please help me in finding out the reason of this exception. Any suggestion or piece of code will surely help me in resolving this issue.

Thanks
Asif Masood
19 years ago
Thak you awais, Reid and Jose.
Your replies really were of help to me.
-Asif
I am bit confused from the different behaviour for almost same expresion.

char ch2 = '2';
char ch3 = '1';
ch3 += ch2; //this works fine

But the following expression gives compiler error.
ch3 = ch3 + ch2;
Why it's so.
Hi,
Class Another is extending Applet and implementing Cloneable, so Another is of Type both Applet and Cloneable at the same time. When you call show() method by passing a Reference of type Another (which is of both Applet and Cloneable type), Compiler gets confused which version of show method to call either show(Applet) or show(Cloneable), that's y it gives compile time error.
Hope this will help to understand.
-Asif
The size of the boolean is 1 byte (8-bits) as specified in the section of sizes for data types in RHE book.
Asif
In case of apending text, you are operating on original reference to the object which is "one" that'y its being reflected in the main method.
I hope following description will help to understand things better.
In Main Method
a => "one"
b => "two"
Here variable a and b are local to main method which contains reference to two objects "one" and "two" respectively.
swap method call: swap(a , b)
through this method call, only reference to the two objects "one" and "two" is passed, not variables.
In Swap Method
public static void swap(StringBuffere a, StringBuffere b)
The above line of code, creates its own variables a and b (which are now local to the Swap method and has nothing to do with the ones in main method) and holds the "reference" to two objects "one" and "two" respectively created in the main method.
a.append("more");
As variable a contains reference of exactly that object which was created in main method, that's why it will be updated now to "onemore" and as variable a in main method also points to this object that's why this change will be reflected there in main method.
b = a;
When the above line of code will be executed, it will assign reference in variable a (to "onemore" object) to variable b. Now variable b also points to the object "onemore". But this assignment is local to this method because we decided already that variables a and b in swap method are local to only this method, that's why this reference assignment will not reflected in the main method.
Hope this will help....
Asif
public class Test { public static void main(String args[]) {
StringBuffer a = new StringBuffer("One");
StringBuffer b = new StringBuffer("Two");
Test.swap(a,b);
System.out.println("a is "+ a +"\nb is " + b);
} static void swap (StringBuffer a, StringBuffer b) {
a.append(" more");
b=a;
}
}
answer is
a is One more
b is Two
Why it is not
a is One more
b is One more

What is the actual process taken ?
This is because reference in variable a is assigned to local variable b (as b is a local variable of swap method). This assignemnet is absolutely local to the swap method and it will not reflected in the variable b of main method.
Hope this will help
Asif
Hi Valentin Crettaz,
Many thanx for the help. This seems very useful as the technique stated in the book, gives a very close estimate of the memory consumption and I think this ll help me to solve the problem as well.
Thanx again.
Asif Masood
22 years ago
Hi Avin & Sean,
Can you help me pls regarding above problem.
Thanks
22 years ago
I want to know the memory required by an object to execute. Actually based on this memory, I have to calculate the number of threads (of the Object) that can be allowed to an application.
I think this time it would be more clear.
Thanks
22 years ago
Hi,
I need the memory required by a Java Object on the fly, when the object is created. Needs Help in this regard.
Thanks in advance.
Asif
22 years ago
how the memory required by an object to execute can be calculted?
thanx
22 years ago
Hi,
As it is said that final variables should be declared and initialized in one line OR final varible should be initialized before using it and ONE MORE THING which is important here for this question that is the value of the final variable can not be changed once assigned. We are violating this rule here in this program by assigning the value to final varible in both if statements (CASE 2) because both the if statements are independant and compiler does not know at compile time that wether one or both will execute that's why it objects that the final variable is being initialzed twice. While in CASE 1, compiler knows by the combination of if, else that only one block will be executed that's why it does not give error in that case.
Hope this explanation will clear all doubts.
Asif Masood
you will have to handle the exception where you will make a call to derived class constructor, or in other words where you will make an instance of the derived class.
Hope this will help to understand
Junilu,
You Wrote:
String s1 = new String("foo");
String s2 = new String("foo");
results in 1 String in the constant pool ("foo") and two Strings on the heap (s1 & s2).
Would it results in one string in constant pool i.e; foo? I don't think so because when you are making object through new operator it will not copy that string in pool as well.
Corect me if I am wrong.
Thanks
Asif Masood