lu v thuan

Ranch Hand
+ Follow
since Oct 25, 2001
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 lu v thuan

Hi friends!
I hava a column type containning more than 1000 characters in Oracle. I would like to get the first 255 characters in this column. Could any one pls tell me the way?
Thanks in advanced
I made a search engine by using SQL and Oracle?
But I would to make a search in XML. First I make XML files from
data stored in Oracle. Then, I would like to build index on these files.
Could any one pls tell any J2EE server supporting index tool?
Thanks in advanced
I use Oracle thin driver to connect to my database in a JSP.
Several days ago, It worked well, but today, I got the error message "SQLException: Io exception: The Network Adapter could not establish the connection"
Could you please help me to solve this problem?
Thanks in advanced
Hi Friends
I'm new to XML
Could you pls give me an XML example about the thing like
this: I would like to display PC components and PC's price.
After a week, some components and PC's price change.Do I have to make a new XML file every change, If not which part I have to change to reflect my changes?
Thanks in advanced
Hi friends
I have a Date field in Oracle. I use JDBC to get that field.
I would like to display the format like this :mm/dd/yyyy
but in java I can display as :yyyy-mm-dd
I tried to used getMonth(),getDate,getYear() to get the desired
format
Could anyone pls tell me another way ?
Thanks in advanced
Hi ravish :
as I mention in comment that if you do not call method1() in class Parent then you won't get any compile error as compilier will find that yes method1() exist in class Parent.(This will true even if you comment out class Child). You tell me yourself ... when you are calling method1(), is it declared/defined? No, it is not declared and defined(as you have commetned it) so how can compiler assume that u are going to declare and define method1() in subclass , so it gives u error.
When you remove the comment, compiler finds method1() and compiles. Runtime it checks first in the object, then in refernce, if it finds in object then it execute that method, else it will execute refrence's method.
NOTE: This is called dynamic binding.
You're right in this case.

But I know that method with private/static/final modifier is static binding
Note:using public static method1 in Parent and Child class .You will get Parent's method1 is called even though the actual object is an object of Child class
Ex:
The out put :
Parent's method2
Parent's method1
--------->static method is static binding
You see the actual object is Child object -->if it was dynamic binding the method1 in Child class would be called
am i wrong?
Hi FEI NG:
This is corect:type checking
The compiler has no way of knowing what object reference P is denothing. it knows the class of reference. And the Parent class doesn't have that menthod which would be a compiler error.
This is dynamic binding
And The acutal invoked method is determined by dynamic method lookup at runtime.
Sorry A mistake
I don't understand what you mean by "If no dynamic binding why this code give compile time error"

Little change on the code and it give the same error but clear.

Complie time error because class member with private keyword is visible only in enclosing classThis time compiler knows the class of reference, method1 is private

ex: static bindingremove private keyword from Parent class.Using public static
method1() in Parentclass and Child class. This time method1() in
Parent class is called not in Child class
Note:private/static/final method use static binding

out put :
Parent's method 2
Parent's method 1
You see this time the actual object is of Child type
(Parent p = new Child()) but method1 in Child not called
method1 in Parent worked -->Static Binding
am I wrong?

Hi ravish and FEI Ng:
If no dynamic binding why this code give compile time error

Note : This proves that when compling Java compiler checks the existence of method1() in Parent class
But if you remove Parent's method1() comment. It compliles sucessfully and when running method1 in Child is called even though in compile time the compiler checked if thod1 in class Parent
------->Dynamic Binding Exists

Could you please explane why method1 in class Child not in class Parent is called ?
[This message has been edited by lu v thuan (edited November 07, 2001).]
Hi FEI NG:
Could you explane why if removing private keyword -->method1 in Child class is called?
I think : because of static/dinamic binding method1() in parent class or child class was called
[b]Method with private/static are static binding
am I wrong?
Hi Valentin:
Thank for your explanation.
But I think class B and class A have their own static var i
(because A is subclass of B --> A inherits i from B)
Could you pls tell me which class static var i belongs to?
Thank in advanced
Hi Friends

I think the result is :15 , 15
Am i wrong, if so pls make it clear to me?
Thank in advanced
Hi Friends
class B extends Thread
{
static protected int i = 0;
public void run()
{
for(; i<5; i++) System.out.println("Hello");
}
}

public class A extends B
{
public void run()
{
for(; i<5; i++)System.out.println("World");
}
public static void main(String args [])
{
Thread t1 = new B();
Thread t2 = new A();
t2.start(); t1.start();
}
}
My qus is : why it prints total five words not ten words and how to modify this code to prints either five words ("hello") or five words ("world")
Thank in advanced
Hi Michael :
The main ideal likes this:
ex: String a, b;
a = new String("cat");//a is a ref to String object containing value cat
b = a;//both b and a point to the same String object
// a ref -->String Object <-- b ref .Note b and a have the same value <br /> but You think b ref --> a ref --> String object .Note b points to a, a points to String object(wrong)
Now, a = new String("dog");
b still point to old object b--> old String object("cat")
but a points to new String object ("dog")

Hope this help
Hi Jose:
In the bytecode you got five String objects because of String
Optimization(An implementation may choose to perform conversion and concatenation in one step to avoid creating and concatenation in one step to avoid creating and then discarding an intermediate String objectsJLS 15.18.1.2)
you are correct
Thank Jose
Hi friends
This question from Marcus Green Mock3 question no.6
Which of the following statements are true?
1) The instanceof operator can be used to determine if a reference is an instance of a class, but not an interface.
2) The instanceof operator can be used to determine if a reference is an instance of a particular primitive wrapper class
3) The instanceof operator will only determine if a reference is an instance of a class immediately above in the hierarchy but no further up the inheritance chain
4) The instanceof operator can be used to determine if one reference is of the same class as another reference thus
The ans is 2
I think none of them , could anyone correct me?
Thanks in advance
------------------

[This message has been edited by lu v thuan (edited November 02, 2001).]