java结构设计_Java基本的程序设计结构(一)

前言:虽然说学过设计模式,J2EE,这个学期才开始学Java,呵呵,有点颠倒了,但是还是要从基本的抓起。hoho~~

(一)一个简单的java应用程序

Package edu.ynu.java.lession1

/*

The simplest Java program

*/

public class FirstJavaProg

{

public static void main(String[] args)

{

// System.out is the standard output stream.

System.out.println("Hello!");

}

}

(二)注释

// This is my first Java program

(三)数据类型

byte (1 bytes, -128 … 127)

short (2 bytes, -32,768 … 32,767)

int (4 bytes, -2,147,483,648 … 2,147,483,647)

long (8 bytes)

Integer literals can be specified in several bases:

Decimal — -99 or 32174

Octal — 012 or 07

Hexadecimal — 0xff or 0XABCDEF01

float

4 bytes

6.5 significant digits

±3.4028E+38F

denoted by ‘F’ or ‘f’ suffix

double

8 bytes

15 significant digits

±1.7977E+308

denoted by ‘D’ or ‘d’ suffix (or no suffix)

if (Double.isNaN(x)) // check whether x is "not a number"

boolean

char

(四)变量

赋值和初始化

常量

Example:

public class Constants

{

public static void main(String[] args)

{

final double CM_PER_INCH = 2.54;

double paperWidth = 8.5;

double paperHeight = 11;

System.out.println("Paper size in centimeter: "

+ paperWidth * CM_PER_INCH + " by "

+ paperHeight * CM_PER_INCH);

}

}

(五)运算符

Arithmetic +, -, *, /, and %.

Prefix and postfix ++ and --.

Boolean ==, !=, , >=, &&, and ||.

Bitwise &, |, ^, and ~.

Arithmetic shift << and >>.

Logical shift >>>.

Java logical operators

&&   (conditional AND)

&     (boolean logical AND)

||   (conditional OR)

|     (boolean logical inclusive OR)

^     (boolean logical exclusive OR)

!     (logical NOT)

数学函数和常量

Constants (e.g, Math.PI)

Functions (e.g., Math.sin())

数值类型之间的转换

0818b9ca8b590ca3270a3433284dd417.png 强制类型转化 double x = 9.997; int nx = (int)Math.round(x); 括号和运算符级别 如记不得可以使用括号 枚举类型 enum Size{SMALL, MEDIUE, LARGE, EXTRA——LARGE}; Size s = Size.SMALL; 注:变量用小写字母开头,常量和类名用大写字母开头

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值