Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services forum!

vivek bawge

Greenhorn
+ Follow
since Apr 19, 2001
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 vivek bawge

Hi,
I am using stylesheets to generate html and then
JEditorPane to render and draw html in my application.
After drawing the report, i would like to place a
combo box, so that the user will be able to sort the
table on any column.
Is it possible to achive this in my java application?
Please treat this as urgent and give me any kind of
feedback.
Thanks in advance!
-Vivek
18 years ago
static methods never use dynamic binding. They are bound compile time.

Originally posted by shadow liu:
As I remember, the calling sequence is below:
1) if there are super or this call in constructor, do it.
2) call superclass (till Object) constructor
3) then the initial part the class
4) the rest of the class constructor.
so this(a) is exec in 1)
but 'int a' initial will be exec in 3).
HTH.



As per your sequence what should be the output of the following code
class Base
{
public void amethod()
{
System.out.println("Base.amethod()");
}
Base()
{
amethod();
}
}
public class Derived extends Base
{
int i = 10;

public static void main(String argv[])
{
Base b = new Derived();

}

public void amethod()
{
System.out.println("Derived.amethod() " + "Value of i is" + i);
}
}
As unexpected, the output is Derived.amethod() Value of i is 0.
As per your sequence, should it give a compile time error because the i in derived is not initialized when the base class constructor calls it.
Thanks,
Vivek

Originally posted by Lance Finney:
I forgot that main itself was static. Wouldn't my statement be true if the method weren't static?
For example, the following code returns 1 and 0. Although the variable is static, "this" has a link to it.
public class Test
{
static int i = 0;
public static void main(String[] args)
{
Test t = new Test();
t.amethod();
}
public void amethod()
{
int i = 1;
System.out.println(i);
System.out.println(this.i);
}
}


Yes because non static members have access to static members but not vice versa.
Vivek

Originally posted by Jini Varghese:
Choose the correct applicable statement for the following code fragment
1.String countries[];
2.countries[0]="india";
a. no error occurs
b. compile time error occurs because the countries array object has not been created
c. runtime error occurs because the countries array object has not been created
ans: c
But I got compiler error. Please confirm.


Go throught the following code to see what errors are caught at compile time and what errors are caught at run time
public class Z
{
Z()
{
System.out.print("Z");
String fruits[];
//fruits[0] = "Apple"; //compile time error . fruits is not initialized
String animals[] = new String[5];
animals[6] = "Tiger"; //run time error ArrayIndexOutOfBounds
}
public static void main(String[] args)
{
new Z();
}
Vivek

Originally posted by Jyotsna Clarkin:

Originally posted by vivek bawge:
[b]Because i am new to this list, can someone help me how to include the original post in reply and make it bold.
and include emoticons.
Vivek


Hi Vivek,
Reply with quote click on this icon at the top of message box

Smilies http://www.javaranch.com/ubb/smilies.html
Other useful tags http://www.javaranch.com/ubb/ubbcode.html
[/B]


Thanks Jyotsna
Welcome Denish
Now its very clear to the compiler that adding "" to a string variable isnt going to change it. I think they should have put that much intelligence in the compiler,
-Vivek
Hi Denish,
original message:
hey java ppl
Look at the code please
when i type this line
int[][]={{1,2,3},new int[1]};// it works fine but when i do this
int[][]={{1,2,3},{new int[1]}};//it gives comile time error
I don't understand what i am doing here??

Reply:
first thing . please post codes that compile.
e.g int[][] = ... doesnt make any sense because int[][] on LHS is a invalid syntax. Instead say int[][] a = ...
Now here is the explanation for your problem.
When the compiler sees brace i.e { in the array initializer list, the next thing it expects after it is array element. So in ur case the array element here is new int[] which is an array.
now its very clear that the declared array's second dimension is capable of holding only int array and not again array or array.
so {new int[1]} part of declaration is treated as if it is
{new int[1], null, null} etc.. got it.
Well, the compiler will not complain if the LHS is a 3 d array.
e.g
public class Test{
public static void main(String args[]){
int[][][] test1 = {new int[2][], {new int[2]}};
int[][][] test2={{{1,2,3},{2,3,4}},{new int[1]}};//it gives comile time error
}
}
will compile perfectly.
Let me know if that helps!
Because i am new to this list, can someone help me how to include the original post in reply and make it bold.
and include emoticons.
Vivek
hi folks,
the response is very discouraging.
atleast let me know if at all there is any solutionn to this problem.
expecting at least some reply.
pl help
Thanks,
Vivek
18 years ago
Thats what bothers me.
How can the base call constructor call derived class method because the derived class is not even full constructed.
This is different from C++ where virtual functions calls i.e polymorphism is disabled in the constructors.
Any comments or explanations?
Thanks,
Vivek
posted May 03, 2001 04:17 PM
--------------------------------------------------------------------------------
Hello,
the main ui class in my project calls a method that spawns several threads. I want to know if there is a way i can put a centralized catch so that all the exceptions are caught in this.
e.g MainUI.java
..
try{
//this method spawns several threads which may throw exceptions
ProjectManager.analyze();
}catch(Throwable t){
logError("Exception" + t + "in some thread spawned by PM.analyze");
}

Thanks in advance,
Vivek

hi sona,
u r little confused abt the immutability of string. strings r immutable but not reference to strings.
so
//Jack is allocated memory. a is just a reference to it.
String a = "Jack";
//can change a to point to anything but doesnt mean that i am
//playing with Jack. Jack is there in its memory area and noone
//can do anything to it. creating Jim in a new memory area and
//a is pointing to it now
a="Jim";

hope this funda is clr for u now,
Vivek
the only thing i can guess here is if u initialize the String statically then the compiler does know that it can optimize. but if u initialize a String from other String variables it doesnt. its very ad hoc answer i know.
Hello,
the main ui class in my project calls a method that spawns several threads. I want to know if there is a way i can put a centralized catch so that all the exceptions are caught in this.
e.g MainUI.java
..
try{
//this method spawns several threads which may throw exceptions
ProjectManager.analyze();
}catch(Throwable t){
LogError("Exception" + t + "in some thread spasned by PM.analyze");
}

Thanks in advance,
Vivek
18 years ago
hi ,
i dont know how java terminology is different than the world. if not then overloading is indeed polymorphism. i dont know if its in true java terms or not.
but poly is many morphism forms
in overloading we assign different tasks to the same method name depending on the context
so overloading is compile time polymorphism
tell me if i am wrong