转自http://xyiyy.javaeye.com/blog/358401
J2SE5.0后提供了自动装箱与拆箱的功能,此功能事实上是编译器来帮您的忙,编译器在编译时期依您所编写的方法,决定是否进行装箱或拆箱动作。例如:
Integer i = 100;
相当于编译器为您作以下的语法编译:
Integer i = new Integer(100);
虽然此功能很方便,但在程序运行阶段您得了解Java的语义。如下面的程序能编译通过:
Integer i = null;
&n ......
1、java是跨平台的,是一门解释性语言,一条一条地执行,解释器就是jvm,所以可以跨平台;
C/C++是编译性语言,所有编译完后再执行,跨平台的时候需要重新编译一次,以适应新的平台。
2、向上转型,继承 白马非马
父类对象转化为子类必须强制(SonClass)fatherClass
子类当为父类 自动 func(FatherClass c) --〉 func(sonClass) ......
package com.google.i_sales.service.data;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.read.biff.BiffException;
import org.extremecomponents.table.limit.Limit;
import org.hibernate.Criteria;
import org.hibernate.JDBCException;
import org.hibernate.criterion.CriteriaSpecification;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projection;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.impl.CriteriaImpl;
import org.springframework.util.Assert;
import org.springside.core.dao.HibernateEntityDao;
import org.springside.core.dao.support.Page;
import org.sprin ......
package com.google.i_sales.service.data;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.read.biff.BiffException;
import org.extremecomponents.table.limit.Limit;
import org.hibernate.Criteria;
import org.hibernate.JDBCException;
import org.hibernate.criterion.CriteriaSpecification;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projection;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.impl.CriteriaImpl;
import org.springframework.util.Assert;
import org.springside.core.dao.HibernateEntityDao;
import org.springside.core.dao.support.Page;
import org.sprin ......
java四舍五入
package Test;
import java.math.BigDecimal; //引入这个包
public class Test {
public static void main(String[] args) {
double i = 3.856;
// 舍掉小数取整
System.out.println("舍掉小数取整:Math.floor(3.856)=" + (int) Math.floor(i));
// 四舍五入取整
System.out.println("四舍五入取整:(3.856)="
+ new BigDecimal(i).setScale(0, BigDecimal.ROUND_HALF_UP));
// 四舍五入保留两位小数
System.out.println("四舍五入取整:(3.856)="
+ new BigDecimal(i).setScale(2, BigDecimal.ROUND_HALF_UP));
// 凑整,取上限
System.out.println("凑整:Math.ceil(3.856)=" + (int) Math.ceil(i));
// 舍掉小数取整
System.out.println("舍掉小数取整:Math.floor(-3.856)=" + (int) Math.floor(-i));
// 四舍五入取整
System.out.println("四舍五入取整:(-3.856)="
......
Inner classes, also called Nested Classes, are nothing but classes that are defined within other classes. The nesting is a relationship between classes, not objects.
Inner classes have clearly two benefits, name control & access control. In Java, this benefit is not as important because Java packages give the name control.
Java inner classes have feature that makes them richer and more useful. An object of an inner class has an implicit reference to the outer class object that instantiated it. Through this pointer, it gains access to any variable of the outer object. Only static inner classes don’t have this pointer. It is actually invisible when we write the code, but compiler takes care of it. Inner classes are actually a phenomenon of the compiler and not the JVM.
Inner classes may be defined with following access modifiers : public, protected, private, or with default package access.
The syntax for inner class is as follows:
[modifiers] class OuterClassName {
co ......
第一,谈谈final, finally, finalize的区别。
final—修饰符(关键字)如果一个类被声明为final,意味着它不能再派生出新的子类,不能作为父类被继承。因此一个类不能既被声明为
abstract的,又被声明为final的。将变量或方法声明为final,可以保证它们在使用中不被改变。被声明为final的变量必须在声明时给定
初值,而在以后的引用中只能读取,不可修改。被声明为final的方法也同样只能使用,不能重载。
finally—再异常处理时提供 finally 块来执行任何清除操作。如果抛出一个异常,那么相匹配的 catch 子句就会执行,然后控制就会进入 finally 块(如果有的话)。
finalize—方法名。Java 技术允许使用 finalize()
方法在垃圾收集器将对象从内存中清除出去之前做必要的清理工作。这个方法是由垃圾收集器在确定这个对象没有被引用时对这个对象调用的。它是在
Object 类中定义的,因此所有的类都继承了它。子类覆盖 finalize ()
方法以整理系统资源或者执行其他清理工作。finalize() 方法是在垃圾收集器删除对象之前对这个对象调用的。
第二,Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以impleme ......