Java Basic Learning Chapter 02 (data type conversion and fundamental questions)

Source: Internet
Author: User

    1. Java Basic data type conversions

      Data types in Java, categorized as reference data types and basic data types. The basic data type is 8

      Integer: Byte 8-bit, short 16-bit, int 32-bit. Long 64 bits, (8 bits = 1 bytes)

      Float type: Float 32-bit, double64-bit

      Character type: Char

      Boolean Type: Boolean



Automatic type conversion

Conversion diagram

The positive direction is the auto-convert inverse direction cast (char--->double conversion and byte-to-double conversion)

Char-->int-->long-->float-->doubl

Byte-->shot-->int-->long-->float-->double


The interview questions are as follows

1. Will the following code compile pass?

public class test{public static void Main (string[] args) {byte a=1;    BYTE b=a+1; }} A: The type conversion error will be prompted when the a+1 operation is not automatically promoted to type int.

2. The following code compilation will pass, if compiled through, what output?

test{Main (string[] args) {a=;        B=++a; System:    println (+B);  }} A: Compiled through, because + + + + is the Java language specified by the operator, Java will be special processing. Output: b=2;


This article is from the "Java Learning route" blog, reproduced please contact the author!

Java Basic Learning Chapter 02 (data type conversion and fundamental questions)

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.