1、jdk就是j2se,jdk1.1.8版本以后改成为j2se,
下载地址:http://java.sun.com/j2se/downloads.html
2、jre是java运行时环境(jdk1.3版本以后都包含jre)不用单独下载
3、设置环境变量
安装了jdk以后,要配置环境变量
我的电脑->属性->高级->环境变量
添加以下环境变量(假定你的java安装在c:\jdk1.3)
java_home=c:\jdk1.3
classpath=.;c:\jdk1.3\lib\dt.jar;c:\jdk1.3\lib\tools.jar;(.;已经不能少,因为它代表当前路径)
path = c:\jdk1.3\bin
新开一个dos窗口,键入java和javac测试一下
4、简单测试程序
代码:--------------------------------------------------------------------------------
public class Test{
public static void main(String args[]){
System.out.println("Hello world!");
}
}
--------------------------------------------------------------------------------
javac Test.java
java Test
import java.applet.*;import java.awt.*;
public class Hello extends Applet
{
String tom;
public void init()
{
tom = "2201223";
}
public void paint(Graphics g)
{
if(tom.startsWith("220"))
g.drawString("tom",10,19);
}
}
/Files/zitiger/JEDPlus20.zip
五笔加加Plus 2.6
http://www.wbfans.net/Soft_Down.asp?UrlID=1&SoftID=26
/Files/zitiger/WallpaperTiger.rar
http://192.18.97.52/ECom/EComTicketServlet/BEGIN5C63504EA758E9ABC692C8FEE213D527/-2147483648/1100977263/1/636050/635870/1100977263/2ts+/westCoastFSEND/j2sdk-1.4.2_09-oth-JPR/j2sdk-1.4.2_09-oth-JPR:2/j2sdk-1_4_2_09-windows-i586-p.exe
import java.util.*;
class Hello
{
public static void main(String args[])
{
String s = "i am a good boy";
s = s.toLowerCase();
StringTokenizer t = new StringTokenizer(s);
System.out.print(t.countTokens());
while(t.hasMoreTokens())
{
String str = t.nextToken();
System.out.println(str);
System.out.println(t.countTokens());
}
}
}
import java.util.*;
class Hello
{
public static void main(String args[])
{
String s = "I am a good boy";
char a[] = s.toCharArray();
for(int i = 0; i < a.length; i++)
{
if(Character.isLowerCase(a[i]))
{
a[i] = Character.toUpperCase(a[i]);
}
else
{
a[i] = Character.toLowerCase(a[i]);
}
}
s = new String(a);
System.out.println(s);
}
}
import java.text.NumberFormat;
class Hello
{
public static void main(String args[])
{
double a = 1123.234;
NumberFormat f = NumberFormat.getInstance();
f.setMaximumFractionDigits(10);
f.setMinimumIntegerDigits(3);
String s = f.format(a);
System.out.println(s);
}
}
import java.io.*;
class Hello
{
public static void main(String args[])
{
File f1 = new File("C:\\Documents and Settings\\Admin\\桌面\\Java","Hello.java");
File f2 = new File("C:\\Documents and Settings\\Admin\\桌面\\Java");
System.out.println(f1.canRead());
System.out.println(f1.length());
System.out.println(f1.getAbsolutePath());
System.out.println(f2.isDirectory());
}
}
import java.io.*;
class FA implements FilenameFilter
{
String str = "";
FA(String s)
{
str += "." + s;
}
public boolean accept(File dir, String name)
{
return name.endsWith(str);
}
}
class Hello
{
public static void main(String args[])
{
File f2 = new File("C:\\Documents and Settings\\Admin\\桌面\\Java");
FA fa = new FA("java");
String fileName[] = f2.list(fa);
for(int i = 0; i<fileName.length; i++)
{
System.out.println(fileName[i]);
}
}
}
import java.io.*;
class Hello
{
public static void main(String args[])
{
try
{
File f = new File("C:\\Documents and Settings\\Admin\\桌面\\Java","a.txt");
FileWriter out = new FileWriter(f);
out.write("aa");
out.close();
}
catch(IOException e)
{
System.out.println("IO error");
}
}
}
import java.io.*;
import java.awt.*;
import java.awt.event.*;
class EWindow extends Frame implements ActionListener
{
TextArea text;
Button buttonRead,buttonWrite;
BufferedReader bufferIn;
FileReader in;
BufferedWriter bufferOut;
FileWriter out;
EWindow()
{
super("流的读取");
text = new TextArea(10,10);
text.setBackground(Color.cyan);
buttonRead = new Button("Read");
buttonRead.addActionListener(this);
buttonWrite = new Button("Write");
buttonWrite .addActionListener(this);
setLayout(new BorderLayout());
setSize(340,340);
setVisible(true);
add(text,BorderLayout.CENTER);
Panel pNorth = new Panel();
pNorth.add(buttonRead);
pNorth.add(buttonWrite);
pNorth.validate();
add(BorderLayout.NORTH,pNorth);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
String s;
if(e.getSource() == buttonRead)
{
try
{
text.setText(null);
File f = new File("C:\\Documents and Settings\\Admin\\桌面\\Java","Hello.txt");
in = new FileReader(f);
bufferIn = new BufferedReader(in);
while((s = bufferIn.readLine()) != null)
{
text.append(s + '\n');
}
bufferIn.close();
in.close();
}
catch(IOException exp)
{
System.out.println(exp);
}
}
else if(e.getSource() == buttonWrite)
{
try
{
File f = new File("C:\\Documents and Settings\\Admin\\桌面\\Java","Hello.txt");
FileWriter out = new FileWriter(f);
BufferedWriter bufferOut = new BufferedWriter(out);
bufferOut.write(text.getText(),0,(text.getText()).length());
bufferOut.flush();
bufferOut.close();
out.close();
}
catch(IOException exp)
{
System.out.println(exp);
}
}
}
}
class Hello
{
public static void main(String args[])
{
EWindow w = new EWindow();
w.validate();
}
}
import java.io.*;
class Hello2
{
public static void main(String args[])
{
try
{
Runtime ce = Runtime.getRuntime();
ce.exec("java Hello");
File f = new File("C://WINDOWS","NOTEPAD.exe");
ce.exec(f.getAbsolutePath());
}
catch(Exception e)
{}
}
}
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import javax.swing.JOptionPane;
class InputArea extends Panel implements ActionListener
{
File f = null;
RandomAccessFile out;
Box baseBox,boxV1,boxV2;
TextField name,email,phone;
Button button;
InputArea(File f)
{
setBackground(Color.cyan);
this.f = f;
name = new TextField(12);
email = new TextField(12);
phone = new TextField(12);
button = new Button("录入");
button.addActionListener(this);
boxV1 = Box.createVerticalBox();
boxV1.add(new Label("name"));
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(new Label("email"));
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(new Label("phone"));
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(new Label("submit"));
boxV1.add(Box.createVerticalStrut(8));
boxV2 = Box.createVerticalBox();
boxV2.add(name);
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(email);
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(phone);
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(button);
boxV2.add(Box.createVerticalStrut(8));
baseBox = Box.createHorizontalBox();
baseBox.add(boxV1);
baseBox.add(Box.createHorizontalStrut(8));
baseBox.add(boxV2);
add(baseBox);
}
public void actionPerformed(ActionEvent e)
{
try
{
RandomAccessFile out = new RandomAccessFile(f,"rw");
if(f.exists())
{
long length = f.length();
out.seek(length);
}
out.writeUTF("Name" + name.getText());
// System.out.println(name.getText());
// JOptionPane.showMessageDialog(this,name.getText(),name.getText(),JOptionPane.WARNING_MESSAGE);
out.writeUTF("Email" + email.getText());
out.writeUTF("Phone" + phone.getText());
out.close();
}
catch(IOException ee)
{}
}
}
public class Hello extends Frame implements ActionListener
{
File file = null;
MenuBar bar;
Menu fileMenu;
MenuItem 录入,显示;
TextArea show;
InputArea inputMessage;
CardLayout card = null;
Panel pCenter;
Hello()
{
file = new File("Hello.txt");
录入 = new MenuItem("录入");
显示 = new MenuItem("显示");
bar = new MenuBar();
fileMenu = new Menu("选项");
fileMenu.add(录入);
fileMenu.add(显示);
bar.add(fileMenu);
setMenuBar(bar);
录入.addActionListener(this);
显示.addActionListener(this);
inputMessage = new InputArea(file);
show = new TextArea(12,20);
card = new CardLayout();
pCenter = new Panel();
pCenter.setLayout(card);
pCenter.add("录入",inputMessage);
pCenter.add("显示",show);
add(pCenter,BorderLayout.CENTER);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
setVisible(true);
setBounds(100,50,420,380);
validate();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == 录入)
{
card.show(pCenter,"录入");
}
else if(e.getSource() == 显示)
{
int number =1 ;
card.show(pCenter,"显示");
try
{
RandomAccessFile in = new RandomAccessFile(file,"r");
show.append("\n" + number );
String 姓名 = null;
while((姓名 = in.readUTF()) != null)
{
// show.append("\n" + number + " "+ 姓名);
// show.append(in.readUTF());
// show.append(in.readUTF());
show.append("\n------------------");
number++;
}
show.append("\n" + number );
in.close();
}
catch(Exception ee)
{
// JOptionPane.showMessageDialog(this,ee.,name.getText(),JOptionPane.WARNING_MESSAGE);
}
}
}
public static void main(String args[])
{
new Hello();
}
}
import java.sql.*;
public class Hello
{
public static void main(String args[])
{
Connection con;
Statement sql;
ResultSet rs;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
System.out.println(""+e);
}
try
{
con = DriverManager.getConnection("jdbc:odbc:java","","");
sql = con.createStatement();
rs = sql.executeQuery("SELECT * FROM Customers");
while(rs.next())
{
String number = rs.getString(1);//getInt,getDate
System.out.println(number);
}
con.close();
}
catch(SQLException el)
{
System.out.println(""+el);
}
}
}