Compare commits
	
		
			4 Commits
		
	
	
		
			fe9964116e
			...
			f80521d4a5
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| f80521d4a5 | |||
| a6c121d9a1 | |||
| 886c549976 | |||
| 730e6a8592 | 
@ -1,5 +1,9 @@
 | 
				
			|||||||
package chapter5;
 | 
					package chapter5;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 获取当前时间
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class Example11 {
 | 
					public class Example11 {
 | 
				
			||||||
    public static void main(String[] args) {
 | 
					    public static void main(String[] args) {
 | 
				
			||||||
        long startTime = System.currentTimeMillis();
 | 
					        long startTime = System.currentTimeMillis();
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										21
									
								
								src/chapter5/Example12.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/chapter5/Example12.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					package chapter5;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.Enumeration;
 | 
				
			||||||
 | 
					import java.util.Properties;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 获取系统信息
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public class Example12 {
 | 
				
			||||||
 | 
					    public static void main(String[] args) {
 | 
				
			||||||
 | 
					        // 获取当前系统信息
 | 
				
			||||||
 | 
					        Properties prop = System.getProperties();
 | 
				
			||||||
 | 
					        Enumeration names = prop.propertyNames();
 | 
				
			||||||
 | 
					        while (names.hasMoreElements()) {
 | 
				
			||||||
 | 
					            String key = (String) names.nextElement();
 | 
				
			||||||
 | 
					            String value = prop.getProperty(key);
 | 
				
			||||||
 | 
					            System.out.println(key + "=" + value);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										28
									
								
								src/chapter5/Example13.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/chapter5/Example13.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					package chapter5;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Person implements AutoCloseable {
 | 
				
			||||||
 | 
					    String name;
 | 
				
			||||||
 | 
					    public Person(String name) {
 | 
				
			||||||
 | 
					        this.name = name;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void close() {
 | 
				
			||||||
 | 
					        System.out.println( name + " 要被回收啦!");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class Example13 {
 | 
				
			||||||
 | 
					    public static void main(String[] args) {
 | 
				
			||||||
 | 
					        Person p1 = new Person("小明");
 | 
				
			||||||
 | 
					        Person p2 = new Person("大王");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        p1 = null;
 | 
				
			||||||
 | 
					        p2 = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        System.gc();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (int i = 0; i < 1000000; i ++) {
 | 
				
			||||||
 | 
					            // 为了延长程序运行的时间
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										15
									
								
								src/chapter5/Example14.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/chapter5/Example14.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					package chapter5;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 获取当前虚拟机信息
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class Example14 {
 | 
				
			||||||
 | 
					    public static void main(String[] args) {
 | 
				
			||||||
 | 
					        Runtime rt = Runtime.getRuntime();
 | 
				
			||||||
 | 
					        System.out.println("处理器个数:" + rt.availableProcessors());
 | 
				
			||||||
 | 
					        System.out.println("空闲内存:" + rt.freeMemory()/1024/1024 + "MB");
 | 
				
			||||||
 | 
					        System.out.println("虚拟机中的内存总量:" + rt.totalMemory()/1024/1024 + "MB");
 | 
				
			||||||
 | 
					        System.out.println("最大可用内存:" + rt.maxMemory()/1024/1024 + "MB");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user