About Question enthuware.ocajp.i.v7.2.1377 : (2024)

Moderator: admin

Post Reply

  • Print view

7 posts• Page 1 of 1

Myzreal
Posts: 1
Joined: Mon Jun 16, 2014 6:25 am
Contact:

Contact Myzreal

Send private message

About Question enthuware.ocajp.i.v7.2.1377 :

  • Quote

Postby Myzreal »

Note under option #4 says that "the floating point suffices f, F or d, D are used only when using decimal system or hexadecimal and not while using binary".

However, hexadecimal numbers make use of the F character as a digit. How does the compiler know when we meant to use F as a digit and when as a floating point suffix?

Will the number 0x1f be considered integer 31 or float 1.0f?

Top

admin
Site Admin
Posts: 10119
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Contact admin

Send private message

Re: About Question enthuware.ocajp.i.v7.2.1377 :

  • Quote

Postby admin »

Integer 31. Compiler has no issues figuring that out because any number starting with 0x is in binary and since there is no 'p' or 'P' in the number, it is a decimal. To write a floating point number is binary, there must be a 'p' or 'P' in the number. Please see this for full details: http://docs.oracle.com/javase/specs/jls ... jls-3.10.2

BTW, 'p' and 'P' are not required for the exam.

HTH,
Paul.

If you like our products and services, please help us by posting your review here.

Top

Kevin_C
Posts: 14
Joined: Mon Nov 03, 2014 5:18 am
Contact:

Contact Kevin_C

Send private message

Re: About Question enthuware.ocajp.i.v7.2.1377 :

  • Quote

Postby Kevin_C »

Why are the suffices with binary only invalid for floating points? So, why is this invalid:

Code: Select all

float x = 0b100f;

but this valid:

Code: Select all

long x = 0b100L;

Also, is there a difference between lower-case and upper-case? Or is f and F the same, d and D the same, l and L the same?

Top

admin
Site Admin
Posts: 10119
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Contact admin

Send private message

Re: About Question enthuware.ocajp.i.v7.2.1377 :

  • Quote

Postby admin »

That is how the language designers designed this feature. There is no technical limitation that prevents it.

There is no difference between lower and upper case.

HTH,
Paul.

If you like our products and services, please help us by posting your review here.

Top

gparLondon
Posts: 63
Joined: Fri Oct 31, 2014 6:31 pm
Contact:

Contact gparLondon

Send private message

Re: About Question enthuware.ocajp.i.v7.2.1377 :

  • Quote

Postby gparLondon »

Hi,

What else should we know about octal, hexadecimal and binary number?

1>I mean should be know the output of the program when they are written?

example :float hexa=0x01dfeacL; System.out.println(hexa);

2>Should we know about the range they take?

example:byte b = 0b1100110011; // Type mismatch: cannot convert from int to byte

Thanks,
GPAR

Top

admin
Site Admin
Posts: 10119
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Contact admin

Send private message

Re: About Question enthuware.ocajp.i.v7.2.1377 :

  • Quote

Postby admin »

No, don't worry about ranges. Just knowing how to write numbers in binary, octal, and hex is enough. No need to translate from one format to another either.

If you like our products and services, please help us by posting your review here.

Top

scranen
Posts: 12
Joined: Thu May 07, 2015 8:55 am
Contact:

Contact scranen

Send private message

Re: About Question enthuware.ocajp.i.v7.2.1377 :

  • Quote

Postby scranen »

Maybe the explanation could be clearer on the difference between integer literals in hexadecimal format and floating point literals in hexadecimal format (recognizable by the 'p' or 'P' exponent indicator).

Code: Select all

float f1 = 0xffff_ffff; // int literal, assigned to a floatfloat f2 = 0xffff_ffffL; // long literal, assigned to a floatfloat f3 = 0xffff_ffff_ffff_ffffL; // Dittofloat f4 = 0xffff_ffff_ffff_ffff; // Not a valid int literal, because the specified number does not fit in an int!float f5 = 0xffff_ffffp0f; // float literal, assigned to a floatfloat f6 = 0xffff_ffffp0; // double literal, assigned to a float: Possible loss of precision!float f7 = 0xffff_ffff_ffff_ffffp0f; // (very large) float literal, assigned to a float

It is useful to know that hexadecimal integer literals (without the 'p') are interpreted as two's complement, whereas floating point literals are interpreted as unsigned numbers.

Code: Select all

System.out.println(f1); // prints -1.0System.out.println(f2); // prints 4.2949673E9System.out.println(f3); // prints -1.0System.out.println(f5); // prints 4.2949673E9System.out.println(f7); // prints 1.8446744E19

Top

Post Reply

  • Print view

7 posts• Page 1 of 1

Return to “OCA OCP Java Programmer Certification Questions Discussion”

Jump to

  • Discussion Forum
  • ↳ OCFA Java Foundations Certified Junior Associate Questions
  • ↳ OCA OCP Java Programmer Certification Questions Discussion
  • ↳ Servlet/JSP Web Component Developer Certification (SCWCD/OCE-WCD/OCWCD) 1Z0-899/1Z0-858
  • ↳ EJB/JPA Certification (SCBCD/OCE-JPA/OCE-EJBD) 1Z0-895/1Z0-898
  • ↳ Java Web Services Developer Certification (OCE-JWS) 1Z0-897
  • ↳ Other Certifications
  • ↳ Time Pass Lounge
  • ↳ Feedback, Suggestions, Comments, Admin Communication
  • ↳ General Java Discussion
  • ↳ Errors/Bugs that have been fixed

Who is online

Users browsing this forum: No registered users and 45 guests

About Question enthuware.ocajp.i.v7.2.1377 : (2024)

References

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Moshe Kshlerin

Last Updated:

Views: 6423

Rating: 4.7 / 5 (77 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Moshe Kshlerin

Birthday: 1994-01-25

Address: Suite 609 315 Lupita Unions, Ronnieburgh, MI 62697

Phone: +2424755286529

Job: District Education Designer

Hobby: Yoga, Gunsmithing, Singing, 3D printing, Nordic skating, Soapmaking, Juggling

Introduction: My name is Moshe Kshlerin, I am a gleaming, attractive, outstanding, pleasant, delightful, outstanding, famous person who loves writing and wants to share my knowledge and understanding with you.