1
原始数据类型(primitive data type) == 基本类型 (fundamental type)
byte short int long float double char boolean
引用类型 reference type
2
System.in System.out
java.util.Scanner
Scanner input = new Scanner (System.in);
nextByte()
nextShort()
nextInt()
nextLong()
nextFloat()
nextDouble()
next()
nextLine()
3
标识符
标识符必须是字母数字下划线和$组成的字符序列,习惯上,$只用在机器自动产生的源代码中
不能以数字开头,
不能是保留字,
不可以是true,false,null,
可以为任意长度
区分大小写
4
定名常量 named constant
final datatype CONSTANTNAME = value;
必须在同一条语句中声明和赋值
5
overflow: int value = 2147483647 + 1; int value2 = -2147483648 - 1;
java不会报关于上溢的警告或错误
underflow: java近似认为是0
6
%: 只有当被除数是负数时,余数是负数
7
数值直接量 literal
整型直接量
long 加L或l
浮点型直接量
double 加D或d
float F或f
科学计数法 e或E 12.3e+2 == 12.3e2
8
long System.currentTimeMillis() 返回格林尼治时间GMT 1,1,1970 0:00(UNIX时间戳)到当前时间的毫秒数
9
简介赋值运算符
10
数值类型转换
拓宽类型 widening a type
缩窄类型 narrowing a type
11
Math.pow(base,times)
12
encoding
encoding scheme
char 16
整型转换成char型发生截断
byte需显式转换
Unicode
Unicode Consortium
supplementary character
\u0000-\uFFFF,必须提供4个16位进制数位
如果没有安装中文字体看不到中文字符
13
Escape character 转义字符
14
不要在nextByte(),nextint()等后面使用nextLine()
15
java文档注释
/**开始 */结尾
二元运算符两边应各加一个空格
16
块的风格:
次行 next-line
行尾 end-of-line
17
java 不能从编译错误检测到除0
调试工具
18
javax.swing.JOptionPane.showInputDialog(null,title,message,ircon);
19
int intValue=Integer.parseInt(intString);
输入的如果不是数值或者点击了Cancel都会出现runtime error
Integer类和Double类都包含在java.lang包中
20
'a'-'c'=-2
显示int值
21
java -cp exercise8e.zip Exercise2_1
22
java.util.Scanner

Keyword:
algorithm
assignment operator
assignment statement
backslash(\)
byte type
casting
char type
constant
data type
debugger
debugging
declaration
decrement operator
double type
encoding
final
float type
floating-point number
expression
identifier
increment operator
incremental developing and testing
indentation
int type
literal
logic error
long type
narrowing
operator
overflow
pseudocode
primitive data type
runtime error
syntax error
supplementary Unicode
short type
underflow
Unicode
UNIX epoch
variable
widening
whitespace

习题
2.1
合法:applet,Applet,$4,apps,x,y,radius
关键字:class,public,int
2.2
double miles=100;
final double KILOMETERS_PER_MILE=1.09
double kilometers=miles*KILOMETERS_PER_MILE;
System.out.println(kilometers);
109
2.3
增加可读性,防止改变常量值,易于维护
final int SIZE=20;
2.4
5
15
50
1
6.5
-4.5
2.5
2
-2
-1
4
0
1
2.6
thursday
2.7
byte -128 - 127 8
short -32768 - 32767 16
int -2147483648 - 2147483647 32
long -9,223,372,036,854,775,808 - 92233720369547758807
float +-(1.4E-45 - 3.4028235E+38) 32
double +-(4.9E-324 - 1.797 693 134 862 315 7E+308)
2.8
6
25.0/4
2.9
从计算机的角度都正确
2.10
4/3.0/(r+34)-9*(a+bc)+(double)(3+d*(2+a))/(a+b*d)
2.11
(double)(m*r*r)
m*Math.pow(r,2);
2.12
(2)(3)
2.13
12.3,12.3e+2,23.4e-2,-334.4,20,39F,40D
2.14
2:public static void
4:int k = 100;
7:and 改为 +
2.15
int currentMinute = (int)(System.currentMillis()%36000000/60000*60)
2.16
可以发生自动转换时可以,但是float和int,long和double运算时则需要显式转换
2.17
发生截断 truncation
改变
2.18
12.5
12
2.19
49
65
66
97
98
(
;
O
U
Z
@
Z
q
r
z
2.20
'1','\u3fFa','\b'
2.21
\\
\"
2.23
char c = 'A';
i = (int)c;//i=67
float f = 1000.34f;
int i = (int)f;//变量重复声明,1000

double d = 1000.34;
int i = (int)d;//1000

int i = 97;
char c = (char)i;//'c'
2.24
'b'
'c'
-2
2.25
11
11
111
12
111
2.26
1Welcome11
1Welcome2
1Welcome2
1Welcomea1
2.27
常量: MAX_VALUE
类或接口: Test
常量或方法名: read,readInt
2.28
.............
2.29
语法错误: 语法不合规范,编译器报错
运行错误: 运行过程中报出的错误,影响程序正常运行
逻辑错误: 编程内容出现错误,指令不能达到应有效果
2.30
JOptionPane 是 javax.swing包里的,不是默认导入的
Math类则是java.lang包内的,默认导入
2.31
int i = Integer.parseInt(javax.swing.JOptionPane.showInputDialog(null,"请输入一个整数"));

编程练习:
2.9

public class Exercise2-9 {

public static void main(String[] args) {
// TODO Auto-generated method stub
String money = javax.swing.JOptionPane.showInputDialog(null,"请输入钱数");
int ind=money.indexOf('.');
String penny = money.substring(ind+1);
money=money.substring(0, ind);
int i=Integer.parseUnsignedInt(money,10)*100+Integer.parseUnsignedInt(penny);
javax.swing.JOptionPane.showMessageDialog(null,"answer"+i+"penny","result",JOptionPane.INFORMATION_MESSAGE);
}
}
2.18

public class Exercise {
public static void print(String a){
System.out.printf("%-10s",a);
}
public static void main(String[] args){
print("a");print("b");print("pow(a,b)");System.out.println();
for(int i=1;i<6;i++){
String s = ""+i;
print(s);
s = String.valueOf(i+1);
print(s);
s = ""+(int)Math.pow(i, i+1);
print(s);System.out.println();
}
}
}
2.25
import java.util.Scanner;
public class Exercise {
public static void main(String[] args){
System.out.print("Enter the time zone offset to GMT:");
Scanner scanner = new Scanner(System.in);
int i=scanner.nextInt();
long second=System.currentTimeMillis()/1000-3600*i;
int sec = (int)(second%60);
second/=60;
int min = (int)second%60;
second/=60;
int hour = (int)second%24;
System.out.print("The current time is "+hour+":"+min+":"+sec);

}
}

java程序设计基础篇 复习笔记 第二单元的更多相关文章

  1. java程序设计基础篇 复习笔记 第一单元

    java语言程序设计基础篇笔记1. 几种有名的语言COBOL:商业应用FORTRAN:数学运算BASIC:易学易用Visual Basic,Delphi:图形用户界面C:汇编语言的强大功能和易学性,可 ...

  2. java程序设计基础篇 复习笔记 第七单元&&第八单元

    7.1 int[][] triArray{ {1}, {1,2}, {1,2,3}, }; 7.2 array[2].length 8.1 Unified Modeling Language:UML ...

  3. java程序设计基础篇 复习笔记 第六单元

    第六章 一维数组 1 数组初始化语法 array initializer 2 for each loop 3 off-by-one error 通常是在循环中该使用<的地方使用了<= 4 ...

  4. java程序设计基础篇 复习笔记 第五单元

    1. method header: modifier, return value type, method signature(method name, parameter) method body ...

  5. java程序设计基础篇 复习笔记 第三单元

    1 单向if语句 双向if语句 dangling else switch:char,byte,short,int 2 javax.swing.JOptionPane.showConfirmDialog ...

  6. java程序设计基础篇 复习笔记 第四单元

    1 think before coding code incrementally 2 sentinel value sentinel-controlled loop 3 输入输出重定向 > &l ...

  7. Java程序设计基础作业目录(作业笔记)

    持续更新中............. Java程序设计基础笔记 • [目录] 我的大学笔记>>> 第1章 初识Java>>> 1.1.4 学生成绩等级流程图练习 1 ...

  8. Java程序设计基础笔记 • 【目录】

    持续更新中- 我的大学笔记>>> 章节 内容 实践练习 Java程序设计基础作业目录(作业笔记) 第1章 Java程序设计基础笔记 • [第1章 初识Java] 第2章 Java程序 ...

  9. 20145322第九周JAVA程序设计基础学习总结

    20145322第九周JAVA程序设计基础学习总结 JDBC简介 JDBC全名Java DataBase Connectivity,是java联机数据库的标准规范.它定义一组标准类与接口,应用程序需要 ...

随机推荐

  1. 714. Best Time to Buy and Sell Stock with Transaction Fee

    问题 给定一个数组,第i个元素表示第i天股票的价格,可执行多次"买一次卖一次",每次执行完(卖出后)需要小费,求最大利润 Input: prices = [1, 3, 2, 8, ...

  2. redis 慢查询日志

    说明:针对慢查询日志,可以设置两个参数,一个是执行时长,单位为微秒,另一个是慢查询日志的长度.如果超过该长度,当一个新的命令被写入日志时,最老的一条会从命令日志队列中被移除. 编辑配置文件redis. ...

  3. Linux各目录缩写含义

    Unix已经有35年历史了.许多人认为它开始于中世纪,这个中世纪是相对于计算机技术的产生和发展来说的.在过去的时间里,Unix和它的子分支Linux收集有许多的历史和一些完全古老的语言.在这篇技巧文章 ...

  4. 什么时候使用namespace

    #include<iostream.h> 不用using namespace std; #include<iostream>要用using namespace std;

  5. MR案例:定制InputFormat

    数据输入格式 InputFormat类用于描述MR作业的输入规范,主要功能:输入规范检查(比如输入文件目录的检查).对数据文件进行输入切分和从输入分块中将数据记录逐一读取出来.并转化为Map的输入键值 ...

  6. cygwin下烧写文件到sd卡中

    在cygwin下将firmware_sdcard.bin写入到sd卡中(cygwin需要以管理员身份启动) 1查看sd分区情况 cat /proc/partitions  (为了找到sd卡的标记) 2 ...

  7. springMVC三种处理器映射器

    1.配置处理器映射器,springmvc默认的处理器映射器BeanNameUrlHandlerMapping <bean class="org.springframework.web. ...

  8. jQuery基本筛选选择器

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. geoserver源码学习与扩展——restAPI访问

    产生这篇文章的想法是在前端通过js调用restAPI时,总是不成功,发送ajax请求时还总是出现类似跨域的问题,后来查找才发现,默认情况下restAPI的访问都需要管理员权限,而通过ajax请求传输用 ...

  10. spring 及 spring boot 资源文件配置

    Spring配置文件引入xml文件: <import resource=" " />标签使用总结 https://www.cnblogs.com/javahr/p/83 ...