Five types of data type parsing in Java

Source: Internet
Author: User

I don't know if you understand the simple data types of Java, the following five types of simple data types for Java represent numbers and characters for detailed explanation and analysis.

First, simple data type initialization

In the Java language, a simple data type is automatically initialized to a default value when declared as a member variable of a class, unless explicitly declared. A simple data type that declares a local variable for a method is not automatically initialized and causes the compiler to throw an error message similar to the following "Variable X may not have been initialized. (x variable not initialized) "Table B defines the default values for Java simple data types.

Second, packaging class

The 1ava also provides built-in encapsulation classes such as Byte, short, Boolean, Character, Integer, Double, float, and long. These encapsulation (wrapper) classes provide a very intuitive and practical approach. For example, the Byte, Float, Integer, long, and double classes all have the Doublevalue () method, which allows you to convert the value stored in an instance of a class to a double type. Also, all encapsulation classes provide a static valueof (string s) method to put a given string.

Third, the data type

The data type is an abstract representation of the memory location. Programmers can take advantage of a variety of data types: some are defined by programming languages, some are defined by external libraries, and others are defined by programmers. Many programming languages rely on specific computer types and specific compilation implementations of data type properties, such as the size of Word and integer data types. On the other hand, Java's virtual machines are responsible for defining all aspects of their built-in data types. This means that the properties of the data type are exactly the same regardless of the low-level operating system that the Java Virtual Machine (JVM) is running on.

Iv. default initial values for Java simple data types

The code in Listing B shows that all Java simple data types are used as member variables of the initialization class. The example also shows that an int variable is declared locally in the constructor of the initialization class. Without modifying the above code, the compiler throws an error when compiling the above code.

Once the line of code that caused the problem (those that referred to an uninitialized variable that caused the error to occur) was deleted or commented out.

Summary: Java defines a complete set of simple data types. In addition, Java cancels other hardware and compiler dependencies that become languages, allowing programmers to divert attention to other issues. In the next article, we will continue to discuss some of the frequently used, Java-defined complex data types, while understanding how to use them to handle typical programming problems.

V. Simple data types for Java

All numeric variables in Java are signed, and Java does not allow arbitrary conversions between data types. Type conversions can only be made between numeric variables. For example, a Boolean cannot be converted to another data type, and other data types cannot be converted to Boolean. Because Java's simple data types are precisely defined, and direct memory access is not allowed, the sizeof operator is canceled in the Java language. Java's simple data type is not an object. To treat Java simple data types in an object-oriented manner, you need to encapsulate them first with classes.

Five types of data type parsing in Java

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.