闂傚倸鍊搁崐鎼佸磹瀹勬噴褰掑炊椤掆偓杩濋梺閫炲苯澧撮柡灞剧〒閳ь剨缍嗛崑鍛暦瀹€鍕厸鐎光偓閳ь剟宕伴弽顓溾偓浣糕槈濡嘲鐗氶梺鍛婂姉閸嬫挸袙婢跺绻嗛柣鎰典簻閳ь剚鍨垮畷鏇熺節濮橆剛顔嗛梺璺ㄥ櫐閹凤拷 (0) +1 闂傚倸鍊搁崐宄懊归崶褏鏆﹂柛顭戝亝閸欏繒鈧箍鍎遍幏瀣触鐎n喗鐓曢柍鈺佸枤濞堛垹霉绾攱瀚� (0) +1 闂傚倸鍊搁崐鎼佸磹閹间礁纾归柟闂撮檷閸嬫垿鎮楀☉娆嬬細妞も晜鐓¢弻锝夊箣閿濆棭妫勭紓浣哄閸ㄥ爼寮婚妸鈺傚亞闁稿本绋戦锟� (0) +1
闂傚倸鍊搁崐鎼佸磹瀹勬噴褰掑炊椤掆偓杩濋梺閫炲苯澧撮柡灞剧〒閳ь剨缍嗛崑鍛暦瀹€鍕厸鐎光偓閳ь剟宕伴弽顓溾偓浣糕槈濡嘲鐗氶梺鍛婂姉閸嬫挸袙婢跺绻嗛柣鎰典簻閳ь剚鍨垮畷鏇㈠蓟閵夈儱鐎梺绉嗗嫷娈旈柦鍐枛閺岋綁寮崶銉㈠亾閳ь剟鏌涚€n偅灏柍钘夘槸閳诲秹顢樿缁ㄥジ鏌熸笟鍨鐎规洘鍎奸ˇ顕€鏌¢埀顒勬嚍閵夛絼绨婚梺鍝勬川閸嬬偤藟閻愮儤鍊垫慨妯煎亾鐎氾拷闂傚倸鍊搁崐鎼佸磹妞嬪海鐭嗗〒姘e亾妤犵偞鐗犻、鏇㈠Χ閸℃ぞ绮℃俊鐐€栭崝褏绮婚幋鐘差棜闁秆勵殕閻撴洟鏌熼柇锕€鐏遍柛銈咁儔閺屻倝寮堕幐搴′淮闂佸搫鏈粙鎴﹀煡婢跺ň鏋庨柟閭﹀枤閳诲繒绱撻崒姘偓椋庢媼閺屻儱鐤鹃柣妯款嚙閽冪喖鏌i弮鍌楁嫛闁轰礁绉电换婵囩節閸屾碍鐏撻梺鍝勬-閸樺ジ鈥旈崘顔嘉ч柛鎰╁妼婵兘姊洪悷鏉挎闁瑰嚖鎷�>>

正在阅读:你能过关吗?J2EE面试题集锦(附答案)你能过关吗?J2EE面试题集锦(附答案)

2005-11-24 10:01 出处: 作者:metaphy 责任编辑:xietaoming

二、Java编程与程序运行结果

  1.Java编程,打印昨天的当前时刻

public class YesterdayCurrent{
  public void main(String[] args){
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -1);
    System.out.println(cal.getTime());
  }
}

  2.文件读写,实现一个计数器

  public int getNum(){
        int i = -1;
        try{
            String stri="";
            BufferedReader in = new BufferedReader(new FileReader(f));
            while((stri=in.readLine())!=null){
                i = Integer.parseInt(stri.trim());
            }
            in.close();
        }catch(Exception e){
            e.printStackTrace();
        }
        return i;
    }
    public void setNum(){
        int i = getNum();
        i++;       
        try{
            PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter(f,false))); 
            out.write(String.valueOf(i));            //可能是编码的原因,如果直接写入int的话,将出现java编码和windows编码的混乱,因此此处写入的是String
            out.close() ;
        }catch(Exception e){
            e.printStackTrace();
        }
    }

  3. 指出下面程序的运行结果:

class A{
    static{
        System.out.print("1");
    }
    public A(){
        System.out.print("2");
    }
}
class B extends A{
    static{
        System.out.print("a");
    }
    public B(){
        System.out.print("b");
    }  
}
public class Hello{
    public static void main(String[] ars){
        A ab = new B(); //执行到此处,结果: 1a2b
 ab = new B(); //执行到此处,结果: 1a2bab
    }
}

  注:类的static 代码段,可以看作是类首次加载(被虚拟机加载)执行的代码,而对于类的加载,首先要执行其基类的构造,再执行其本身的构造

  4.写一个Singleton模式的例子

public class Singleton{
 private static Singleton single = new Singleton();
 private Singleton(){}
 public Singleton getInstance(){
  return single;
 }
}

三、数据库

  1.删除表的重复记录

  如果记录完全相同才算重复记录,那么:  (sql server2000下测试通过)

select distinct * into #tmpp from tid
delete from tid    
insert into tid select * from #tmpp
drop table #tmpp

  如果有id主键(数字,自增1的那种),那么:(sql server2000下测试通过)

delete from tableA where id not in
(select id = min(id) from tableA group by name)

  2.delete from tablea & truncate table tablea的区别

  truncate 语句执行速度快,占资源少,并且只记录页删除的日志;
  delete 对每条记录的删除均需要记录日志

键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品
闂傚倸鍊搁崐鎼佸磹妞嬪海鐭嗗ù锝堟缁€濠傗攽閻樻彃鈧绱撳杈ㄥ枑闁哄啫鐗勯埀顑跨窔瀵粙顢橀悙鑼垛偓鍨攽閿涘嫬浠х紒顕呭灦瀵偊鎮╃紒妯锋嫼闂備緡鍋嗛崑娑㈡嚐椤栨稒娅犻柟缁㈠枟閻撴瑦銇勯弮鈧娆忈缚閹扮増鐓欑€瑰嫮澧楅崵鍥┾偓瑙勬磸閸斿秶鎹㈠┑瀣<婵炲棙鍔栭埢鏇熺節閻㈤潧啸妞わ綀妫勫嵄闁告稒娼欑壕濠氭煙閹规劦鍤欑紒鐙€鍨堕弻銊╂偆閸屾稑顏�闂傚倸鍊搁崐鎼佸磹閻戣姤鍊块柨鏇炲€哥粻鏍煕椤愶絾绀€缁炬儳娼¢弻鐔煎箚閻楀牜妫勭紒鎯у⒔缁垳鎹㈠☉銏犵婵炲棗绻掓禒濂告⒑閸濆嫬顏ラ柛搴f暬楠炲啫顫滈埀顒勫箖濞嗘挸绾ч柛顭戝枤瑜版垵鈹戦悙鑼憼缂侇喖绉堕崚鎺楀箻鐠囪尪鎽曞┑鐐村灟閸╁嫰寮崘顔界叆婵犻潧妫欓ˉ鐘炽亜閿斿搫鍔︽慨濠冩そ瀹曘劍绻濋崘鐐棝闂備胶鎳撻崵鏍箯閿燂拷