• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Complile and Runtime errors

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can anyone please explain to me how I can know when a program will produce a compile time error or a runtime error.
Thanks,
Anthea.
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A compile-time error will be produced when you fail to follow the basic syntax of Java. For example, the following would cause a compile-time error due to incorrect array-access syntax:

However, if the code follows all of the syntax rules, it won't generate a compile-time error but, if you're doing something "bad", you could still produce a run-time error. Take this example:

Even though this meets the syntax requirements, this will cause an ArrayIndexOutOfBounds exception to be thrown at run-time.
I hope this helps a little. If you're having a problem with a specific example, perhaps you could ask about that and I can try to be of more help.
Corey
 
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It really depends on the situation. You'll have to read up on APIs and how they work and/or write some code and experiment. Writing code is a good way to learn things for the certification exam.
This may have been a more general answer than what you wanted but I think if you take the time and write code you will be doing yourself a favor.
Good luck!
 
Anthea Blake
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for your responses.
I think I understand the concept behind it, but I always seem to have problems with questions like this when I do sample exams. I wrote the exam once before and failed miserably on these kind of questions.
So would you suggest that a rule of thumb is to check to see if the question has the correct syntax first, and then rule out the multiple choice answers as I go along?
Thanks again,
Anthea
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If a question says, "What is the result of compiling and running this code?", the first thing I do is look for compiler error. That means look at every nit-picky detail - be a human compiler for a minute.
If you're sure there aren't any of issues there, then you can rule out that response and move on to look for potential run-time errors.
Again, if you don't find any of those, then you know that the app will run properly so now all you have to do is figure out what it does!
I hope that helps a little,
Corey
 
Anthea Blake
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks...
I guess it all comes down to making sure you know your stuff before you rule out any answer. :-)
Thanks again,
 
We should throw him a surprise party. It will cheer him up. We can use this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic