Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!

Jay Kay

Ranch Hand
+ Follow
since May 17, 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 Jay Kay

In other words, if a program generates a checked exception and exception is not handled a compiler error is generated
And, if a program generates an unchecked exception and the exception is not handled only a run time error is generated
Am I correct?
Thanks for your help guys.
-Jay
On Checked Exception, Khalid Mughal says,
"Except for RunTimeException, Error and their subclasses, all
exceptions are called checked exceptions. The compiler ensures
that if a method can throw a checked exception, directly or indirectly, then the method must explicitly deal with it."
On Unchecked Exception, Khalid Mughal says,
"Exceptions defined by Error and RuntimeException classes and
their subclasses are known as unchecked exceptions, meaning that
a method is not oblighed to deal with this kind of exceptions"
But Khalid confuses by saying, "If an exception is not explicitly caught and handled by the program, it perlocates upwards in the method activation stack, and is dealt with by the default exception handler"
What is the difference between a Checked Exception and an
UnChecked Exception?
Thanks.
-Jay
Thanks Gurpreet. Awesome explanation.
-Jay
Khalid Mughal pg. 126 says Transient modifier should not be
specified for static variables as static variables do not belong to objects

In question 4.26 page 130, Khalid Mughal says
(e) final transient static private double PI = 3.1415926......;
is a legal declaration within a class.
Not sure what Khalid is trying to say.
Does he mean, transient modifier should not be used for static variables logically as transient works for objects of a class
but if used there would be no syntax error.
Thank you.
-Jay

I was wondering what the top level class is.
Is it the class which contains the public static void main method?
Thank you.
-Jay
Yes, Micheal. I meant the load order.
Thank you.
-Jay
I was wondering if anyone could point out the precedance of static variables, static blocks and static methods
Thank you.
-Jay
Awesome. Thanks guys.
-Jay
If a package name is not specified for the class, the class
will be placed in a "default" package.
Where does this default package reside and what does it contain?
Is it garbage collected?

Any help is greatly appreciated.
Thank you.
-Jay
public class MyClass
{
long var;

public void MyClass (long param) // 1
{
var = param;
}

public static void main(String srgs[])
{
MyClass a, b;
a = new MyClass(); // 2
b = new MyClass(5); // 3
}
}
The above code does not compile. It gives a compiler error
at line // 3. The reason given is that since the declaration
at // 1, has a return type, it is not a constructor and is a
method. Is this a rule in JAVA that if a constructor
has a return type then it is a method?

Also, consider the following code,

public class MyClass
{
long var;

public MyClass (long param) // 1
{
var = param;
}

public static void main(String srgs[])
{
MyClass b;
b = new MyClass(5); // 2
}
}

Would (line // 2) b = new MyClass(5) still compile since the
constructor expects a long value and 5 is passed.
In other words is widening conversion allowed when calling
constructors or methods ? Is there any set of rules
available similar to assignment type conversions?

Thank you.
-Jay
[This message has been edited by Jay Kay (edited October 21, 2001).]
[This message has been edited by Jay Kay (edited October 21, 2001).]
Given the following code, which statements can be placed at
the indicated position without causing compile errors?
public class ThisUsage
{
int planets;
static int suns;
public void gaze()
{
int i;
//.... insert statement here
}
}
Select all valid answers:
a) i = this.planet;
b) i = this.suns;
c) this = new ThisUsage();
d) this.i = 4;
e) this.suns = planets;
Answer is a), b) and e)
I can understand a) as "this" points to the instance of object ThisUsage. But, I don't understand how "this" can point to
a static variable int sun. As static variables go by the class name and "this" refers to the instance of the object currently used.
For eg., if the above question had a main,

public static void main(String args[])
{
ThisUsage current = new ThisUsage();
current.gaze();
}
Here, "this" would reference the instance "current" of class ThisUsage. It perfectly makes sense for this to access
member variable planet of instance "current" through, this.planet
But how is this.sun correct?
Any help is greatly appreciated.
-Jay
Awesome guys. You made my day. Thank you.
-Jay

Originally posted by Valentin Crettaz:
i = i++;
the thing goes like this: first the value of i is stored in a register and then i is incremented, but the value used for the assignment is the old value of i stored in the register so the variable i (whose value is now 1) gets assigned the old value of 0, which is to say that i=i++; has no effect on the value of i. You are better off just doing i++;
HIH


According to Khalid Mughal, postfix operation is done before
assignment operation and also assignment operation has right
associativity i.e, right side expression is executed first.
Keeping all this in mind,
i = i++ ;
postfix operation should have been executed first and
since assignment operation is the last (in the order of precedance),i should have taken the value of 1.
Where am I wrong? Any help is greatly appreciated.
Thanks.
-Jay


[This message has been edited by Jay Kay (edited October 17, 2001).]