JAVA data type, java Basic Data Type

Source: Internet
Author: User

JAVA data type, java Basic Data Type

Java, like the C language, specifies the storage of data in the memory. We call this a java data type:

Java defines four integer types: (1), byte, short, int, and long ).
(2) Two floating point data types: float with single precision and double with double precision.
(3) There is also a boolean type, that is, boolean, which occupies 16 bytes.
In addition, there is no unsigned keyword in java, which is different from the C language, that is, all the numbers are signed numbers.

Example:

Boolean application instance
1. The value of this type of variable can only be true or false. The default value is false.
2. Because the variable of this type is a logical value, it is unnecessary to write a statement such as true or false in the if Condition Statement.

public class BoolTest{    public static void main(String args[]) {        boolean y;        y=false;        System.out.println("y is"+y);        y=true;        if(y)        {            System.out.println("y is true");        }    }}

 

 

 

 

// Bytes type/* character type data occupies 8 digits in C language, while java uses unicode, so it occupies 16 digits. Some other operations are the same as those in C. */public class CharDemo {public static void main (String args []) {char character, ch2; character = 65; ch2 = 'B '; system. out. print ("between and ch2"); // The System does not automatically wrap. out. println (Bytes + "" + ch2); // will automatically wrap }}

 

Integer and floating point

/* In java, the data types are sorted from low to high (in bytes): byte, short, char, int, long, float, and double. 1. The basic data type is automatically converted. It can be automatically converted from low to high. 2. Forced conversion of basic data types. Force conversion is required from high to low. */
Public class BasicData {public static void main (String args []) {byte B = 15; int h = B; long I = B; float j = B; double k = B; system. out. println ("h is:" + h); System. out. println ("I is:" + I); System. out. println ("j is:" + j); System. out. println ("k is:" + k); System. out. println ("\ n \ t \ n"); double b1 = 15.96857143698656; byte h1 = (byte) b1; int i1 = (int) b1; long j1 = (long) b1; float k1 = (float) b1; System. out. pr Intln ("h1 is:" + h1); System. out. println ("i1 is:" + i1); System. out. println ("j1 is:" + j1); System. out. println ("k1 is:" + k1); // converts string-type data to other types. In java, int x1 = 10; float y1 = 3.14f; double z1 = 3.1415926; Integer X1 = new Integer (x1 ); // generate the integer class Float Y1 = new Float (y1); Double Z1 = new Double (z1 ); // convert String s1 = X1.toString (); String s2 = Y1.toString (); String s3 = Z1.toString (); System. out. println (s1); System. out. println (s2); System. out. println (s3 );}}

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.