前言:虽然说学过设计模式,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())
数值类型之间的转换
强制类型转化
double x = 9.997;
int nx = (int)Math.round(x);
括号和运算符级别
如记不得可以使用括号
枚举类型
enum Size{SMALL, MEDIUE, LARGE, EXTRA——LARGE};
Size s = Size.SMALL;
注:变量用小写字母开头,常量和类名用大写字母开头
评论
留下你的脚步