易截截图软件、单文件、免安装、纯绿色、仅160KB

Inner classes in Java, the mystery within.

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 {
code...
[modifiers] class InnerClassName {
code....
}
}
Inner Classes:
Following properties can be noted about Inner classes:
The outer class (the class containing the inner class) can instantiate as many number of inner class objects as it wishes, inside it’s code.
If the inner class is public & the containing class as well, then code in some other unrelated class can as well create an instance of the inner class.
In above case the inner class can be created as follows:
<OuterClassName> outerObj = new <OuterClassName>(arguments);
outerObj.<InnerClassName> innerObj = outerObj.new <InnerClassName>(arguments);
No inner class objects are automatically instantiated with an outer class object.
If the inner class is static, then static inner class can be instantiated without an outer class instance, otherwise, the inner class object must be associated with an instance of the outer class.
Inner class code has free access to


相关文档:

Java内部类(Inner Class)详解

简单的说,内部(inner)类指那些类定义代码被置于其它类定义中的类;而对于一般的、类定义代码不嵌套在其它类定义中的类,称为顶层(top-level)类。对于一个内部类,包含其定义代码的类称为它的外部(outer)类。
1          Static member class(静态成员类)
类声明中 ......

Java程序调用存储过程应用举例

Java程序调用存储过程验证用户登录
package com.yzy.jdbc.dao;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import oracle.jdbc.OracleTypes;
public class LoginDao {
 public boolean loginValidate(String username, Stri ......

第一个java applet小程序

趁着今天还有点精力,将刚刚学会的APPLET写出来。
感觉用记事本编辑程序太吃力,不过现在是处于学习阶段,先把基本的东西掌握了吧。
JAVA APPLET就是用JAVA语言编写的一些小应用程序,它们可以直接嵌入到网页中或者其他特定容器中,并产生特殊的效果。
JAVA APPLET程序不是将main方法作为入口。
第一个APPLET程序:
打 ......

慎用Java装箱与拆箱

转自http://xyiyy.javaeye.com/blog/358401
J2SE5.0后提供了自动装箱与拆箱的功能,此功能事实上是编译器来帮您的忙,编译器在编译时期依您所编写的方法,决定是否进行装箱或拆箱动作。例如:
                     ......

java四舍五入BigDecimal

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));
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号