This week's giveaway is in the Spring forum.
We're giving away four copies of liveProject: Protecting User Data with Spring Security and OAuth2 and have Laurentiu Spilca on-line!
See this thread for details.
Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Sybex CSG 11: Answer -> Chap 2. Question 3 -> var day = 1/0; does not compile

 
Greenhorn
Posts: 18
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question is:

Which of the following code snippets about var compile without issue when used in a method? (Choose all that apply.)



Options:
A. var spring = null;
B. var fall = "leaves";
C. var evening = 2; evening = null;
D. var night = new Object();
E. var day = 1/0;
F. var winter = 12, cold;
G. var fall = 2, autumn = 2;
H. var morning = ""; morning = null;

Answer in the book: B, D, E, H.

But option E (var day = 1/0;) will result to a compilation error. -> java.lang.ArithmeticException: / by zero
 
Marshal
Posts: 26517
81
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That snipped compiles just fine for me (I just tried it). Perhaps you're confusing compiler errors with runtime errors? The compiler doesn't throw exceptions when it reports on errors.
 
Arnold Gatmaitan
Greenhorn
Posts: 18
IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:That snipped compiles just fine for me (I just tried it). Perhaps you're confusing compiler errors with runtime errors? The compiler doesn't throw exceptions when it reports on errors.



Yes I got confused! I am using single-file source code and were compiling and running in one go.

java Test.java



 
I've never won anything before. Not even a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic