Oracle OCA j2se7 cetificate-rules for Primitive Types

Source: Internet
Author: User

    • Any bigger than an int can never is assigned to a int or anything smaller than int (byte, char, or short ) without explicit cast.


    • Constant values up to int can is assigned (without cast) to variables of lesser size (e.g. short to byte) if the values AR e representable by the variable.


    • Operands of mathematical operators is always promoted to at LEAST Int. (e.g. Byte*byte both bytes would be first promoted to int) and the return value is at LEAST Int.


    • Compound Assignment operators (+ =, *= etc) has strange ways so ready this carefully:a Compound assignment expression of The form E1 op = E2 is equivalent to E1 = (T) ((E1) op (E2)), where T is the type of E1


    • A char value can always be assigned to an int variable, since the int type is wider than the char type.


    • A narrowing primitive conversion May is used if all of the following conditions is satisfied:

      1. The expression is a constant expression of type int.

      2. The type of the variable is a byte, short or char.

      3. The value of expression is representable in the type of the variable.

      4. NOTE that narrowing conversion doesn ' t apply to long or double. So, char ch = 30L; Would fail Althrough representable by a char.


Oracle OCA j2se7 cetificate-rules for Primitive Types

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.