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

Java变长参数

在Java5中提供了变长参数,也就是在方法定义中可以使用个数不确定的参数,对于同一方法可以使用不同个数的参数调用,例如:print("hello");print("hello","lisi");print("hello","张三");下面介绍如何定义可变长参数以及如何使用可变长参数。
1、可变长参数方法的定义
使用...表示可变长参数,例如
print(String... args){
   ...
}
在具有可变长参数的方法中可以把参数当成数组使用,例如可以循环输出所有的参数值。
print(String... args){
   for(String temp:args)
      System.out.println(temp);
}
2、可变长参数的方法的调用
调用的时候可以给出任意多个参数,例如:
print("hello");
print("hello","lisi");
print("hello","张三");
3、注意事项
3.1 在调用方法的时候,如果能够和固定参数的方法匹配,也能够与可变长参数的方法匹配,则选择固定参数的方法。看下面代码的输出:
package ch6;
import static java.lang.System.out;
public class VarArgsTest {
 public static void main(String[] args) {
  VarArgsTest test = new VarArgsTest();
  test.print("hello");
  test.print("hello","zhangsan");
 }
 
 public void print(String... args){
  for(int i=0;i<args.length;i++){
   out.println(args[i]);
  }
 }
 
 public void print(String test){
  out.println("----------");
 }
}
3.2 如果要调用的方法可以和两个可变参数匹配,则出现错误,例如下面的代码:
package ch6;
import static java.lang.System.out;
public class VarArgsTest {
 public static void main(String[] args) {
  VarArgsTest test = new VarArgsTest();
  test.print("hello");
  test.print("hello","zhangsan");
 }
 
 public void print(String... args){
  for(int i=0;i<args.length;i++){
   out.println(args[i]);
  }
 }
 
 public void print(String test,String...args ){
  out.println("----------");
 }
}
对于上面的代码,main方法中的两个调用都不能编译通过。
3.3 一


相关文档:

JNA实现Java调用Fortran

在成功实现Java调用C++之后,接下来想到能否通过JNA实现Java调用Fortran,今天试验了一下,还是比较容易的。
网上有一个Java调用F95的例子,但是我考虑不仅要实现F95的调用,还要实现F77的调用,所以费了一些周折。
问题的关键在于F77为过程名自动添加了一个尾部的下划线,所以sub1这个过程,到Java一端,就变成了sub1_, ......

郭克华老师java视频教程下载地址(J2ME 和J2EE)


1.j2ee
http://0444.xue8xue8.com/computer/program/java/j2eeshuren/00.wmv
http://0444.xue8xue8.com/computer/program/java/j2eeshuren/01.wmv
http://0444.xue8xue8.com/computer/program/java/j2eeshuren/02.wmv
http://0444.xue8xue8.com/computer/program/java/j2eeshuren/03.wmv
http://0444.xue8xue8.com/c ......

JAVA日期格式问题 SimpleDateFormat方法

1、必须引入:java.text.SimpleDateFormat
2、设置显示方式,调用format格式。
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日");
     String date=sdf.format(blog.getCreatedTime());
    
     sdf=new  Simp ......

Java调用Sybase存储过程

摘至Sybase官网:
The caller( ) method calls the stored procedure inoutproc:
create proc inoutproc @id int, @newname varchar(50), @newhome Address,
@oldname varchar(50) output, @oldhome Address output as

select @oldname = name, @oldhome = home from xmp where id=@id
update xmp set name ......

java 反射

下面参考别人的文章和自己的一点改动和总结并加以注释
  JAVA反射机制主要提供了以下功能:
      1.在运行时判断任意一个对象所属的类。
      2.在运行时构造任意一个类的对象。
      3.在运行时判断任意一个类所具有的成员变量和 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号