Java Basic data types

Source: Internet
Author: User

Integral type
public static void Thenumber () {
BYTE BYTE1=127;//1 byte 8-bit -128--127
Short SHORT=1200;//2 bytes 16 bit
int NUM1=1200;//8 byte 32 bit
Long NUM2=121L;//8 byte 64 bit long type recommended plus l
int num3=0b0000_0000_0000_0000_0000_0000_0000_0011;//jdk1.7 binary Representation 3
int num4=1234_1234;//jdk1.7 12341234
System.out.println (NUM3);
}
Binary conversion
public static void Scalenumber () {
int num1=10;
String num2=integer.tobinarystring (NUM1);//Convert to 2 binary
String num3=integer.tooctalstring (NUM1);//Convert to Octal
String num4=integer.tohexstring (NUM1);//Convert to 16 binary

}
Floating-point type floating-point type constants are double by default
public static void floating () {
Double d=3.14; 8 bytes
Float f=3.14f;//4 bytes
Double d2=10e-2;//scientific Counting method 0.1
Floating-point numbers lose precision if requirements are strict, the use of floating-point type constants is double by default
float f1=0.1f;
Double D3=1/10;
}
Character type
public static void character () {
Char c1= ' q ';
Char c2= ' in ';//unicode 2 bytes: 0-65535
Char c3= ' \ ';//\ is the output of the signifier character '
Char c4= ' \ n ';//turn meaning to indicate line break
Char c5= ' a ';
int n=c5+2;//99 ASCII Code
Char c6= (char) n;//integer to Char
Cycle Print A-Z
for (int i=0;i<26;i++) {
Char temp= (char) (' a ' +i);
SYSTEM.OUT.PRINTLN (temp);
}
In Java, strings are defined as string types.
String str= "ABCDEFG";
}
Yes/No
public static void whether () {
Boolean boo=false;//1 bytes
}

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.