Ò»¡¢Ð´³öjava´¦ÀíÒì³£µÄ»ù±¾Óï·¨¸ñʽ
try{ }catch(exception e){ }finally{};
¶þ¡¢Ð´³ö¶Á³öÏà¶Ô·¾¶¡±\deppon\depponIT.txt¡±ÎļþµÄÁ÷£¬ÔÚ±ØÒªµÄµØ·½×ö²¶»ñÒì³£µÄ´¦Àí
fileInputStream fis;
Public void readTXT(){
Try{
Fis= new FileInputStream(¡°\deppon\depponIT.txt¡±);
}catch(IOException e){
/Òì³£´¦Àí
}
}
Èý¡¢Ð´³ÌÐò½¨Á¢map¼¯ºÏ£¬²¢ÔÚmapÖн¨Á¢IT²¿£¬±à¼²¿£¬ÈËÁ¦×ÊÔ´²¿ÓëµÂ°îÎïÁ÷µÄ¶ÔÓ¦¹Øϵ¡£²¢Ð´³öÅжÏÓï¾ä£¬Èç¹ûmapÖаüº¬IT²¿£¬ÔòÊä³ö×Ö·û´®¡°good department¡±¡£
´ð°¸
Map map= new Map();
map.put(¡°ÈËÁ¦×ÊÔ´²¿¡±£¬¡°µÂ°îÎïÁ÷¡±)£»
map.put(¡°IT²¿¡±£¬¡°µÂ°îÎïÁ÷¡±)£»
map.put(¡°±à¼²¿¡±£¬¡°µÂ°îÎïÁ÷¡±)£»
if£¨map.contans£¨¡°IT²¿¡±£©£©{
system.out.print(¡°good department¡±)£»
}
ËÄ¡¢ÓÐÒ»¸öclass A £¬ËüÓÐÒ»¸öĬÈϵĹ¹Ôì·½·¨£¬Çëдһ¶Ë´úÂëʵÏÖ A µÄ¶¯Ì¬¼ÓÔØ£¿£¨4·Ö£©
¿ÉÒÔÀûÓ÷´ÉäʵÏÖÀàµÄ¶¯Ì¬¼ÓÔØ:
ÒòΪÀàAµÄ¹¹ÔìÆ÷ÊÇÎ޲εÄ,ËùÒÔʵÏÖAµÄ¶¯Ì¬µÄ¼ÓÔصĴúÂëÈçÏÂ:
public class B{
public static void main(String[] args){
try{
A a = (A)Class.forName(¡°A¡±).newInstance();
}catch(Exception e){
e.printStackTrace();
}
}
}
Îå¡¢Çëдһ¸ö£¨µ¥Àý£©SingletonµÄÀý×Ó£¬ÓÐЧ´úÂë²»µÃ³¬¹ý10ÐС££¨5·Ö£©
class Husband{
private static Husband instance=new Husband();
public static Husband newInstance(){
return instance;
}
private Husband(){}
}
Áù ·¢ÆË¿ËÅÆ£ºÓÐ52ÕÅÆË¿ËÅÆ£¨´Ó1µ½52£©£¬ÒªËæ»ú·Ö·¢µ½Êý×éCard[52]ÖУ¬Çëдһ¶Î³ÌÐò
±í´ï¡££¨6·Ö£©
import java.util.*;
public class E{
public static void main(String[] args){
int Card[] = new int[52];
boolean ishave = true;
Set s = new HashSet();
for(int j = 0;j<52;j++){
Integer in = new Integer(j);
s.add(in);
}
int k = 0;
while(ishave){
if(!s.isEmpty()){
int ra = Math.round((float)Math.random()*100);
Integer rai = new Integer(ra);
if(s.contains(rai)){
s.remove(rai);
Card[k] = ra;
k++;
}
}else{ishave = false;}
}
for(int m =0;m<52;m++){
System.out.println(Card[m]);
}
}
}
Æß¡¢ ÇëÍê³É³ÌÐò,²éѯtable1±íÖÐfield1×ֶεÄÖµÊÇ1µÄ¼Í¼,²¢½«²éѯ½á¹û¶¨Î»µ½²éѯ½á¹ûÖеĵÚÈýÐв¢´òÓ¡µÚÈýÐеÄvcFieldµÄÖµ,field1×Ö¶ÎÀàÐÍÊÇnumber£¨ÓÃjava´úÂëʵÏÖ£©¡£ £¨5£©
Connection con = ¡ ;
String sql = ¡±select vcField from table1 where field1 = ¡±;
Connection con = null;
String sql = ¡±select vcField from table1 where field1 = ¡±;
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1,1);
ResultSet rs = ps.executeQuery();
rs.next();
rs.next();
rs.next();
String vcField = rs.getString(¡°vcField¡±);
System.out.println(vcField);
°Ë¡¢¿½±´c:\temp.txtÎļþΪc:\temp2.txtÎļþ
import java.io.*;
public class FileCopyTest {
public static void main(String[] args) {
try{
FileReader fr = new FileReader(¡°c:\\temp.txt¡±);
BufferedReader br = new BufferedReader(fr);
FileWriter fw = new FileWriter(¡°c:\\temp2.txt¡±);
PrintWriter pw = new PrintWriter(fw,true);
String line ;
while ((line = br.readLine()) != null){
pw.println(line);
}
}catch(Exception e) {e.printStackTrace();}
}
}
¾Å.ÇëÍê³É³ÌÐò,²éѯtable1±íÖÐfield1×ֶεÄÖµÊÇ1µÄ¼Í¼,²¢½«²éѯ½á¹û¶¨Î»µ½²éѯ½á¹ûÖеÄ
µÚÈýÐв¢´òÓ¡µÚÈýÐеÄvcFieldµÄÖµ,field1×Ö¶ÎÀàÐÍÊÇnumber.
Connection con = ¡ ;
String sql = ¡±select vcField from table1 where field1 = ¡±;
Connection con = null;
String sql = ¡±select vcField from table1 where field1 = ¡±;
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1,1);
ResultSet rs = ps.executeQuery();
rs.next();
rs.next();
rs.next();
String vcField = rs.getString(¡°vcField¡±);
System.out.println(vcField);
Ê®¡¢ÄÚ²¿ÀàµÄʵÏÖ·½Ê½
ʾÀý´úÂëÈçÏ£º
package test;
public class OuterClass
{
private class InterClass
{
public InterClass()
{
System.out.println(¡°InterClass Create¡±);
}
}
public OuterClass()
{
InterClass ic = new InterClass();
System.out.println(¡°OuterClass Create¡±);
}
public static void main(String[] args)
{
OuterClass oc = new OuterClass();
}
}
Êä³ö½á¹û:
C