Java - Language Syntax 090820

本文介绍了Java中的基本数据类型,包括整数型(byte、short、int、long)、浮点型(float、double)以及字符型(char)等,并详细列举了它们的取值范围与默认值。此外,还探讨了字符串的表示方式、运算符的使用、数组的声明与初始化方法及一些控制结构。

PRIMITIVE DATA TYPES

Integer

 

Minimum Value

Default

Maximum Type Value

byte

 

-128 (byte)

0

127

short

2 bytes

 -32,768 (short)

0

32,767

int

4 bytes

-2,147,483,648

0

2,147,483,647

long

8 bytes

-9,223,372,036,854,775,808

0

9,223,372,036,854,775,807

 

float (4 bytes with 7 digits fractions)

double (8 bytes with 15 digits fractions)

 

char (are specified between SINGLE quotation marks)

String (are specified between DOUBLE quotation marks)

 

Boolean

 

59 reserved words, including all of the data types.

 

CONSTANT

final

 

ARRAYS

One-dimensional array is a numbered list of variables of the same type.

 

String[] dinnerGuests = new String[8];

dinnerGuests[0] = “Fred”;

dinnerGuests[1] = “Jane”;

 

String dinnerGuests[] = {“Fred”, “Jane”, “Michael”, “Brenda”, … }

 

int twoDiArray[][]={{10,9,8,7,6,5,4,3,2,1},{}}; // Declare a two dimensional array

int[][][] threeDiArray;            // Uninitialized 3D array.

 

Array indexes must either be type int (32-bit integer) or be able to be cast as an int. As a result, the largest possible array size is 2,147,483,647.

 

STRING

String in Java is represented as a class, not as an array of characters, so it has methods such as length() and substring().

 

OPERATORS

+ Addition

- Subtraction

* Multiplication

/ Division

% Integer Remainder

++ increment operators

-- decrement operators

 

double * (float, long, int, short, byte) = double

double mySalary = 1000.65

int approxSalay = (int) mySalary //called casting process

 

== is equal to

!= is not equal to

< is less than

> is more than

<= is less than or equal to

>= is greater than or equal to

&& AND

|| OR

 

CONTROL STRUCTURES

if ( ) { … } else { … }

while ( ) { … }

do { … } while ( )

for (int i=10; i=0; i--) { … }

switch

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值