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
相关文档:
class Node
{
private Object obj;
private Node next;
//用数据域构造一个节点对象
public Node(Object obj)
{
this.obj=obj;
}
//返回下一节点的对象
public Node getNext()
{
return this.next;
}
//设置本节点的链域
public void setNext(Node next)
{
this.next=next;
}
//返回节点的数 ......
SCJP5学习笔记
线程交互是比较复杂的问题,SCJP要求不很基础:给定一个场景,编写代码来恰当使用等待、通知和通知所有线程。
一、线程交互的基础知识
SCJP所要求的线程交互知识点需要从java.lang.Object
的类的三个方法来学习:
void notify()
  ......
Java线程调度是Java多线程的核心,只有良好的调度,才能充分发挥系统的性能,提高程序的执行效率。
这里要明确的一点,不管程序员怎么编写调度,只能最大限度的影响线程执行的次序,而不能做到精准控制。
线程休眠的目的是使线程让出CPU的最简单的做法之一,线程休眠时候,会将CPU资源交给其他线程,以便 ......
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) ......
.net代码如下,
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class SysService : System.Web.Services.Web ......