Java 7的主要变化
Devoxx 大会结束在几天前结束了,一位与会者对此次大会的重要内容进行了总结,他提到Java 7的主要变化如下:
1.对collections的支持
Java代码
List<String> list = new ArrayList<String>();
list.add("item");
String item = list.get(0);
Set<String> set = new HashSet<String>();
set.add("item");
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("key", 1);
int value = map.get("key");
现在你还可以:
Java代码
List<String> list = ["item"];
String item = list[0];
Set<String> set = {"item"};
Map<String, Integer> map = {"key" : 1};
int value = map["key"];
2.自动资源管理
Java代码
BufferedReader br = new BufferedReader(new FileReader(path));
try {
return br.readLine();
} finally {
br.close();
}
becomes:
Java代码
try (BufferedReader br = new BufferedReader(new FileReader(path)) {
return br.readLine();
}
You can declare more than one resource to close:
try (
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dest))
{
// code
}
3.对通用实例创建(diamond)的type引用进行了改进
Java代码
Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
becomes:
Java代码
Map<String, List<String>> anagrams = new HashMap<>();
4.数值可加下划线
Java代码
int one_million = 1_000_000;&n
相关文档:
初始化的实际过程为:
在其它任何事物发生之前,将分配给对象的存储空间初始化成二进制的零。
父类static 块或变量
子类static块或变量
父类的显式初始化
父类构造函数
子类的显式初始化
子类的构造函数
此过程中若有父类构造体中调用方法可被子类重载,则JVM会从最低子类对象处寻找此方法,找到则执行,虽然此时对 ......
《Java就业培训教程》 作者:张孝祥 书中源码
《Java就业培训教程》P34源码
程序清单:Promote.java
class Promote
{
public static void main(String args[])
{
byte b = 50;
char c = 'a';
short s = 1024;
int i = 50000;
float ......
一、同步问题提出
线程的同步是为了防止多个线程访问一个数据对象时,对数据造成的破坏。
例如:两个线程ThreadA、ThreadB都操作同一个对象Foo对象,并修改Foo对象上的数据。
public
class
Foo {
private
int
x = 100;
public
int
get ......
Static Factory Methods
Four Advantages:
1) have names
2) not required to create a new object each time they are invoked
3) return an object of any subtype of their return type
4) reduce the verbosity of creating parameterized type instances.(for example: newInstance() method) ......
本文转载自李绪成老师的笔记,感谢李老师!
Web应用中必须在客户端对输入信息进行验证,如果发现错误可以及时对用户进行反馈,也不用等到服务器发现之后再反馈,一方面是减少了用户的等待时间,另一方面减少不必要的交互过程。本节内容介绍如何使用JavaScript完成客户端的验证。
JavaScript语言
在Web应用中需要在客户端 ......