Java基本的程序设计结构(一)
2008-03-15 10:38
417 查看
前言:虽然说学过设计模式,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;
注:变量用小写字母开头,常量和类名用大写字母开头
(一)一个简单的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;
注:变量用小写字母开头,常量和类名用大写字母开头
相关文章推荐
- Java基本的程序设计结构(二)
- Java基本的程序设计结构(五)
- 三、 Java基本的程序设计结构(一)
- 第三章 Java基本的程序设计结构---笔记
- Java基本的程序设计结构(三)
- 重新学习Java——Java基本的程序设计结构(二)
- 重新学习Java——Java基本的程序设计结构(一)
- 【codejava】第八版:第三章 Java基本的程序设计结构[20180103]
- Java基本的程序设计结构(四)
- 程序设计基本结构(顺序、选择、循环)
- [转载]windows过滤驱动程序设计入门(驱动程序基本结构,设备栈,IRP栈和工作原理)
- Java(三)Java基本的程序结构
- java学习笔记(一)程序基本结构
- JAVA程序的基本结构,标识符和关键字
- Java的基本程序结构
- 【Java】程序基本结构
- java学习之路 之 基本语法-程序流程控制-循环结构-while循环练习题
- java学习之路 之 基本语法-程序流程控制-循环结构-for 循环练习题
- JAVA学习笔记-JAVA程序的基本结构
- 程序设计基本结构----顺序、选择与循环