Data types in Java

Source: Internet
Author: User

Data type in/**java */

public class demo03{
static Boolean B; Member variables: In-body methods the out-of-body scope is the entire class. When used, the default value can be executed without assigning a value
public static void Main (String []args) {
System.out.println (Math.PI);
Boolean b;//declares that the declaration of the same variable in a method can only be used once
B = true; Assign value
System.out.println (the value of "B" is: "+b);
b = false;
System.out.println (the value of "B" is: "+b);
Final Boolean cc = TRUE; A measure called constant that is decorated by final
System.out.println (the value of "C is:" +CC);
CC = false;//Error: Cannot assign a value to the final variable cc
char c = ' a ';
System.out.println ("C:" +c);
Char C1 = 97;//ansi 0-65535
SYSTEM.OUT.PRINTLN ("C1:" +C1);
char c2 = ' \u0000 ';
System.out.println ("C2:" +C2);

Long l =1l;
float f =1.0f;
Double D1 = 1.0;
String name = "Wangxiao";
String dd = name+ "" +l+ "" +f+ "" +D1;
SYSTEM.OUT.PRINTLN (DD);


Type conversions
byte BB = 104;
int i = BB; Byte-->int small data types will automatically transform to big data types
System.out.println ("Byte small-->int Large" +i);

Long L1 = 1;
int i1 = (int) L1; Large data types are transformed into small data types, and small data types are required to undertake. Boolean type cannot be converted, char type automatically upward to int
System.out.println ("Long Big-->int Small" +i1);

Float F1 = (float) 1.0;
float F2 = 1.0f; F1 in F2 same role

Above already declared char C = ' a ';
int i2 = C;//char auto Go int
System.out.println ("Char c= ' a '-->int:" +i2);
}
}

Data types 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.