This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Well, a compile time error is something that does not match the API. So this would be a compile time error: Vector v = new Vector(); v.AddElement("foo"); Notice the upper case "A" in AddElement. In the Java API all methods start with lower case letters, only Class names start with upper case. Therefore, this would not compile. However, run time errors are also known as "logic errors". They are errors where you THINK you coded your program correctly ,and it does compile, but the logic doesn't do what you thought it would. Example. Let's say I want to bet $50 if my poker hand is a straighflush and $10 if it's just a straight. And I want to bet $5 on all other hands. I may have code like this: (assume all the methods actually exists and all the data types are correct)
OK, that LOOKS right. But the evil bit here is that I didn't use curly braces to delimit my if statements. So even though it LOOKS like my else statement is attached to the if(type >= hand.STRAIGHT) line, it's ACTUALLY attached to the most recent if statment. Which in this case is the if (type >= hand.STRAIGHT_FLUSH) line. In other words, this is what I THOUGHT I wrote:
But this is what I actually wrote:
That would be an example of a run time error because the code is valid, it will compile, but it doesn't do what you thought the code should do.
For a good Prime, call:<br />29819592777931214269172453467810429868925511217482600306406141434158089