This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!

Mike Vella Zarb

Greenhorn
+ Follow
since Dec 28, 2009
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 Mike Vella Zarb

Vaibhav Mittal wrote:you might find link useful.


That did help a bit, thanks for your input
8 years ago

Seetharaman Venkatasamy wrote:Hmm, ok.

this is my short explanation:

1. compile time error:thrown by compiler while interpreted, if any syntax error in your code. programmer is responsible to clear this error

2.exception/runtime error : thrown by JVM in some exceptional condition. this error may occured due to programmer mistake or internal problem like hardware failure, no memory etc...

<edit>is it help you? </edit>


Thanks, but I'm looking for a way to tell which one is which. I get many multiple choice questions in sample tests and they give me the choice of either Compile-time Error or Runtime Error. I know there's an error, but when is it set off is the hard part...
8 years ago
I searched on Google before I asked but could not really find anything helpful - some questions need a long explanation and not just a few search key words. I was hoping that someone might be able to explain it to me in their own words. I'm sorry if you don't see anything in my question, but I did try to explain myself as clearly as possible...
8 years ago
Hello all,
I am currently studying for the SCJP certification using the Sierra and Bates Study Guide and in many of the self tests (mock exam questions) I keep running into the same problem - I can't tell whether a particular error will be at runtime (an exception) or at compile (compile error). I know this is a bit of a vague question and that it might not be possible to answer but, how can I tell if it's at compile or at runtime? Would you be able to send me some website links that might be able to help me?

Thanks in advance,
Mike
8 years ago
Thanks for all your replies. I seem to have figured it out now. The code that wasn't working had to be in a method, constructor, or initialization block so that it could be ran.

Jim Hoglund wrote:Your other two examples are valid declaration and initialization statements.
Your two lines of code must be placed within a method() or an initialization
block like this:
{
int[] test;
test = new int[] {1,2,3,4,};
}

Jim ... ...


Thanks for the reply, but yes, I already know that. I'm asking why it's like that?
Hi,
I have some doubts with anonymous array creation. Here is my code:


If I don't put that code in a main method it gives the following error:
AnonymousArray.java:9: <identifier> expected
testScores = new int[] {4,7,2};

Why is this?

And also, this code works outside of a main method:
int[] testScores = {4,7,2};
And so does this:
int[] testScores = new int[] {4,7,2};

So why doesn't that particular code work?



I bow down to Raju and appreciate him. CLAP HANDS! Stupid me, forgot that bits are binary...blonde moment much?!
Anyways, thanks to all of you guys for your help and for sticking through my intense stupidity!

Mike

Raju Champaklal wrote:byte occupies 8 bits..so its range is -128 to 127.....now 130 is 00000000000000000000000010000010.....



oooooooh I see, in binary! Then it trims to the eight bits to the right and if the first bit is a 0, it's positive, if it's 1, then negative. The rest of the 1s and 0s form a number in binary, that being -126, am I correct? (I sure do hope so! :S)

James Carter wrote:

Oh OK But do you know why it prints -126 and not -127, since -127 is the most a byte can go to?


well actually its the least value a byte can go


Yeah ok, least, but then why does it print -126?
Huh? Didn't quite get that last one...

Raju Champaklal wrote:hey i was just messing around..just kidding...


Oh OK But do you know why it prints -126 and not -127, since -127 is the most a byte can go to?
Hey Raju, I appreciate your answer too! It's just I didn't understand it as well...but then, why is it that when we print the value of b, it prints -126 and not -127....isn't 127 the biggest value a byte can hold?

James Carter wrote:suppose you have this 0000000000000000000000000000001000 then rightmost 8 bits will be 00001000
hope you get it now



I see, thanks for your help!

James Carter wrote:first of all you must know that byte is of 8 bts and long is of 64 bits
so whn you casting from an long to an byte ou are casting a 64 bits into 8 bits so only the the rightmost 8 bits would be left.
now a sign bit implies a sign a+ or -
if the first bit is 1 then the value is - otherwise +
10000000 is negative because first bit is 1
00000000 is positive because first bit is 0



Thanks for your quick answer, much appreciated. But what do you mean by rightmost 8 bits?