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

java默认包的使用

最近在写java测试程序的时候突然遇到了一个问题:java默认包中的public类是不能在其他包中直接调用的
      首先,总结一下默认包中类的使用范围,java默认包中的类可以实例化其它包中的public类,但是其它包中的类是不能显式实例化默认包中的类这个特性在JDK1.4以后的版本成立;
      其次,可以通过反射来访问默认包中的类,例如下面代码
public class Hello {
 private String codeing;
 public String getCodeing() {
  return codeing + " Hello!";
 }
 public void setCodeing(String codeing) {
  this.codeing = codeing;
 }
}
package junit;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import junit.framework.Assert;
import junit.framework.TestCase;
public class TestHello extends TestCase{
 
 public void testDplit() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException{
  
  Class c = Class.forName("Hello");
  Method m1 = c.getDeclaredMethod("setCodeing", String.class);
  Object ins = c.newInstance();
  m1.invoke(ins, "qh");
  
  Method m2 = c.getDeclaredMethod("getCodeing");
  Assert.assertEquals((String)m2.invoke(ins),"qh Hello!");
 }
}


相关文档:

java语句备忘

代码如下:
List <?> lines = FileUtils.readLines(new File(fileName));
for(Object line : lines){
}
问题:
1.List <?> 表示什么意思?
2.for括号内部的表达式是什么意思?
1、范型。表示lines中可保存任意类型
2、for-each 语句,作为for(int i=0;i<lines.length;i++){
Object line=lines.get(i ......

【奋斗第三天】菜鸟学Java之异常处理

今天一天学了异常处理这一章。
首先异常是Java程序在运行期出现的错误,非编译期(javac)出现的错误。
然后再给异常分类,异常分为三种,第一为error,这种异常不可以处理,是系统的内部错误,第二为Exception,这种可以被处理,Exception里面又有个RuntimeException的类,而RuntimeException又是可以不被捕获处理的,因 ......

初学java从这里开始

这是我个人归纳的一些知识点,我觉得初学java首先需要重以下的知识开始
(1)JAVA程序开发步骤:
   源代码-->编译成*.class-->执行(将.class交给JVM)
   jvm--java虚拟机(解释器)
(2)
   JDK -- java开发工具包(编译器、解释器、类库)
   JSDK -- java标准开发工具包 ......

Cavaj Java Decompiler 反编译器

Cavaj Java Decompiler is a graphical freeware utility that reconstructs Java source code from CLASS files. You can decompile Java applets, JAR and ZIP files, producing accurate Java source code. Browse the reconstructed source code with the Class View for instant access to methods and fields. The pr ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号