Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.

Ram Gopal

Greenhorn
+ Follow
since Apr 06, 2007
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 Ram Gopal

Hey is there any command in Java to trace the flow of control within the program..like in C language?
hey the kathy sierra book says that
"It is legal to omit either the catch block or the finally block, but not both"

so infering the above statement, i think the foll ways are legal

1) try{}
catch{}

OR

2) try{}
finally{}

OR

3) try{}
catch{}
finally{}

but it would be illegal to use only try{} block without catch or finally, as it would give compilation error.

btw it is also mentioned that the catch block should follow try block and finally (if any) should follow catch bloak.
But what if there are 2 catch blocks and 2 finally blocks?

should the finally block immediately follow its corresponding catch block or should we write 2 catch blocks and then followed by 2 finally blocks?
like

try{}
catch1{}
finally1{}
catch2{}
finally2{}

OR
try{}
catch1{}
catch2{}
finally1{}
finally2{}

which of the above is correct one?
consider the following statement
"A try block must have atleast one corresponding catch block"

True or False?
Hi i have one doubt abt overriding concept. As you know, "When a method in subclass has same name and type signature as a method in superclass, then the subclass method is said to override superclass method."

well, what does "type signature" mean?
yeah absolutely right...

infact i just tried to declare interface as private and it gives an error
"Bounceable1.java:1: modifier private not allowed here"

so i guess we can use ONLY public modifier for an interface...
Oh sorry, i just noticed the difference...

1) All interfaces are implicitly 'abstract', whether the word 'abstract' is typed or not.

2) All interface METHODS are implicitly 'public' and 'abstract'.

Originally posted by Chandra Bhatt:



NO!


4- Per source file there must not be more than one public class or interface. It means one public class or public interface; but there can be any number of non public class and interfaces in a .java source file.




hey wish to highlight the code which you modified

abstract interface Bounce // Modified line {
int v = 10;
}
public class Ball implements Bounce { //Modified Line
int x = v*2;
System.out.println("x : " +x);
}


In above code, although the interface hasnt been declared 'public', but by default it is 'public' implicitly. Also the class Ball is public.
i mean in this case, your 4th point (It means one public class or public interface) doesnt seem to apply....
ok... with this modification i am getting no error...

but what explains the earlier compile time error..

i mean the syntax was correct...

1) interfaces should be 'public' 'abstract'

2) class implements an interface

3) interface constants were implicitly 'public static final'

what surprised me that Bounce was an interface & Ball was a class, yet the error said that the class Bounce is public..
ya you are rite....in fact this error seemed surprising.

in my above code the class name is Ball, so i saved the file as Ball.java

i compiled it using the command 'javac c:\java\Ball.java'

and ran the program by typing 'java Ball'

yet am getting an error when i compile as follows:

c:\java\Ball.java:1: class Bounce is public, should be declared in a file named
Bounce.java
public abstract interface Bounce

1 error

why so ?
hey thanks .. i didnt notice that main method is missing..

but after including 'p.s.v.m' statement, i am getting compiler error, however the program runs giving expected output ' x : 20 '.

the compilation error is as follows:

c:\java\Ball.java:1: class Bounce is public, should be declared in a file named Bounce.java
public abstract interface Bounce
^
1 error

any reasons for such an error?
I just wrote a very simple small piece of code to test concepts abt interfaces.

public abstract interface Bounce
{
int v = 10;
}

class Ball implements Bounce
{

int x = v*2;

System.out.println("x : " +x);
}

And i get the following error:

c:\java\Ball.java:12: <identifier> expected
System.out.println("x : " +x);
^
1 error

Whats wrong?
What are the advantages of being Sun Certified Java Professional?

Knowledge?
Job prospects?
Better salary?
Please suggest some good reference books for SCJP Java2 Platform 1.4 ( CX 310-035 ), having lots of practical code examples and not just theory.

I intend to take the exam by May end. Will 2 months of intensive practice be enough to cover all topics for the exam.

Any general tips you would like to suggest are most welcome. Please help