Constants and variables

Source: Internet
Author: User

All functions in Java belong to a class. Therefore, the main method in Java must have a shell class.

The main method in Java must be static.

public class ClassName{    public static void main(String[] args)    {        program statements    }}

 

Java is portable, and its data types occupy a fixed amount of space.

Integer: int 4 bytes, short 2 bytes, long 8 bytes, byte 1 byte

A long value has a suffix L, and a hexadecimal value has a prefix 0x.

Java does not have the unsigned type

 

Floating Point: Float 4 bytes 6 ~ 7-bit valid number, double 8-byte 15-bit valid number

A float value has a suffix F. The default value without a suffix is double.

 

In C ++, a value or pointer can replace a Boolean value. 0 is equivalent to false. A non-0 is equivalent to true, but not in Java.

 

C and C ++ differentiate the Declaration and definition of variables, for example, int I = 10; is to define a variable, and extern int I; is to declare a variable, java does not differentiate the Declaration and definition of variables.

 

Java uses the keyword final to define constants, similar to const in C ++.

 

For Boolean values, & and | are calculated in short-circuit mode, that is, if the first expression can get the result, it does not have to calculate the second expression, & | is not calculated in short-circuit mode.

 

>>> The operator fills the left digit with the symbol bit, >>> the operator fills the left digit with 0.

 

Constants and variables

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.