Small white--java basic data types

Source: Internet
Author: User

PS: This article for small white provide, big guy please detour!!!!

First of all, special thanks to the Big Brother to provide me with this platform, in the future I hope to the Java This section of the content to complement.

Today is about the data type, the most basic content ~

Java identifiers, data types, keywords

Let's start by looking at how to annotate the Java code.

Identifier: Class name, method name, variable.

There are three different ways to

Represents a line of code for comments

/*

Represents a single line of comments or multiple lines of code

(code that is commented from above to below)

*/

Here's another way to annotate a document called a documentation comment.

/**

This usually means

*/

Document comments are generally written at the beginning of the code to describe the specific contents of your program, before we first look at the Javadoc command, I first write a simple code:

Package com.briup.chap02; /* * @author twinkle@version 1.0    */  Public class primitivetype{publicstaticvoid  main (string[] args) {byte  123; byte  - ;} }

We javadoc-d generate a directory compilation file

After the compilation succeeds, we open the newly generated doc and open the index.html to look at it, presumably this:

class overview

Class:

Student

Description

It ' s a text file

So that we can see the meaning of the document comment, which can be displayed in the description of the document that you compiled, but someone will find out why the author we wrote out didn't come out?

Because he has a @ at the front, we need to write it to add it to the show, now let's try it:

–javadoc-d bin/doc-author-version Src/primitivetype.java

So the author and version information comes out.

I. Class name

Here we want to remember some of the basic formatting of the code:

Class Name: Student (upper first letter uppercase)

Methods and variables: genderitem (lowercase in front, uppercase at the beginning of the word)

Constant notation: max_page (constant capitalization, usually underlined in the middle)

Two. Keywords

Keywords are actually defined in the computer has a special meaning of the identifier, such as int,for,double or anything is a keyword. Specific meaning please baidu a bit ~

Three. Data type

Data types are the focus of this article, so let's look at these basic data types

Type bits Case scope

BYTE 8-bit 11111111~01111111-2^7~2^7-1

Short 16-bit 16 binary code -2^15~2^15-1

int 32-bit 32 binary code -2^31~2^31-1

Long 64-bit 64 binary code -2^63~2^63-1

Floating point type:

Float 32-bit 32 binary code

Double 64-bit, 64-binary code

Boolean type:

Boolean has only two types of false and true.

Explain exactly why there are so many types? And why is bits different?

The reason for the type of many is because some of the value itself is very small, passed to the large data type, although can go in, but some bits is idle, occupy the extra memory but do not have any effect, so there will be so many types.

We know that the ultimate goal of programming is that we pass the code to the hardware, to work through the hardware, but that the hardware only recognizes the binary code, so Java has a transition to convert its code into binary code, the bits is the number of binary codes, and we want to see how big his range can be, The first bit of the binary is a marker, the popular point is the sign, and then there is n-bit, it is the range of-|2^n|~|2^n-1|

If we define a type that is out of this range (that is, if the pot is full of things if added), Java will make an error, beyond the specified range, so when we define the data type, we need to figure out the range of the data types.

There is also a special data type: char (' character ')

The specific number of bits of char to be combined with Unicode encoding. The question comes again, what kind of Unicode encoding is it! Unicode encoding is a character set, which contains the Chinese, Japanese, Korean, three kinds of text, we can use Char method to print out the characters: char (' U\unicode code '), Unicode table specific Baidu ha ~

Data type conversions:

Explicit conversions: that is, casts

Implicit conversions: self-converting by JVM virtual machines

Cast of data type: int a = (cast type) b

Conversion rules: From a type with a large storage range to a type with a small storage range.

The specific rules are: Double→float→long→int→short (char) →byte

byte B = 10;

byte a = (int) b;

If we convert the int type B to a byte type A, there will be overflow, so we will get an error.

So the correct way to cast is ~ ~:

byte B = 10;

int (or larger type) a = (int) b;

The basic Java data type is here.

Small white--java basic data types

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.