JAVA编程心得
计算机3班
窦金霞
20104773
最近几周一直在弄程序,说实话真的很累,但累中也有成功的快乐。我觉得学到了很多东西,这是只看课本知识所不能学到的。
说实话,以前我一直没学过JAVA虽然我也知道JAVA的重要性,可是即使上课听了,不实践还是掌握不了。因为种种原因,今年我没有买笔记本。没有机器,仅仅靠每周一次的上机练习是绝对不够的。所以我就插空调程序,在舍友们不用的时候自己再接她们的电脑调。
调上一个WEB版的通讯录程序时我已经感觉到学的很吃力,好多东西都不懂。这次做的这个学生成绩管理系统更复杂了,所以一开始调的时候感觉特别吃力.所以我告诉自己不能放弃,慢慢来,就这样我从最基本的sql语句session对象开始学起,我觉得我还有太多不懂得所以要比别人付出更多的努力。就这样我一点一点的学着??
说心里话,在做上一个web版的通讯录时,我就感觉到成功的喜悦。好多地方我都是一点一点的问的,在问的过程中,我也学会了很多,像:Servlet和jsp之间跳不过去时有两种解决办法,一是关闭底层类中的db.close;二是将Servlet中的throws Exception改成try catch以捕捉异常;我还学到了集中查找错误的方法,可以加上两个双斜杠“//”将具体的方法屏蔽掉,一检查是方法错误还是Servlet错误,还有就是写上System.out.println()将获得的数据输出,用来检查数据传输过程有没有错误等等
。
虽然在别人看来,这些方法可能都很常规,但是确实我自己学会的,我觉得很有成就感。我已经做好计划了,暑假的时候去买本本用自己的本本练习一下JAVA,虽然下学期不学JAVA了,但是我对JAVA的热情不会因为这个而削减的!
做完这个学生成绩管理系统后,我觉得我对JAVA的看法已经改变了。一前总以为JAVA很繁琐很难,听同学说JAVA不好学,开始又有一些听不懂,所以一直很畏惧JAVA。但真正做了这个系统以后我才感觉到其实任何事都没有难与不难之分,只要你肯努力的去做,世上无难事只怕有心人!
我现在对java学习充满了热情,我知道我还有很多的不足
还有很多需要努力的地方,所以我的JAVA之旅将继续进行??
第二篇:JAVA编程题型
定义、扩展和实现接口
(1) 定义一个接口Shape,包含两个方法:String getColor()和void
setColor(String c)。
public interface Shape {
}
(2) String getColor(); void setColor(String c); 定义一个扩展自Shape的接口Shape2D,包含两个新方法double area()
和void draw()。
public interface Shape2D extends Shape {
}
(3) double area(); void draw(); 定义一个类Circle实现Shape2D接口。其中area计算面积,draw打
印字符串表示自己是circle。
public class Circle implements Shape2D {
} int r; public void setRadius(int r){this.r=r;} public double area() {return r*r;} public void draw() { System.out.println("I'm a Circle!!!"); } public String getColor() {return null;} public void setColor(String c) {}
(4) 定义一个类Rectangle实现Shape2D接口。其中area计算面积,draw
打印字符串表示自己是rectangle。
public class Rectangle implements Shape2D
{
int x,y; public void setX(int x){this.x=x;} public void setY(int y){this.y=y;} public double area() {return x*y;}
public void draw() {
System.out.println("I'm a Rectangle!!!");
}
public String getColor() {return null;}
public void setColor(String c) {}
}
(5) 定义一个测试类ShapeTester,在main方法中创建一个Circle类型的
对象,向上塑形成Shape和Shape2D类型的引用变量sc和s2c,并调用sc.setcolor和s2c.area。同样,在main方法中创建一个Rectangle类型的对象,向上塑性成Shape和Shape2D类型的引用变量sr和s2r,并调用sr.setcolor和s2r.area。
public class ShapeTester {
public static void main(String[] args) {
}
} Circle c = new Circle(); Shape sc=(Shape)c; Shape2D s2c =(Shape2D)c; sc.setColor("Circle Color"); s2c.area(); Rectangle r =new Rectangle(); Shape sr=(Shape)r; Shape2D s2r =(Shape2D)r; sc.setColor("Rectangle Color"); s2r.area();
(6) 定义一个测试类ShapeTester2,在main方法中创建一个大小为10,
数据类型为Shape2D的数组shape2ds。随机产生10个circle或rectangle类型的变量,向上塑形后放入数组shape2ds中。遍历shape2ds中的每一个元素,并调用draw函数。
public class ShapeTester2 {
public static void main(String[] args) {
Shape2D shape2ds[]=new Shape2D[10]; for(int i=0;i<10;i++) { int random; random = (int)(Math.random()*2); if(random==0) {Circle c = new Circle(); shape2ds[i]=(Shape2D)c; } else {Rectangle r =new Rectangle(); shape2ds[i]=(Shape2D)r; };
}
} } shape2ds[i].draw();
内部类
(1) 编写一个类Parcel1,里面有两个内部类Content和Destination。为
Parcel1写一个方法void ship(String destination),这个方法调用内部类Content和Destination完成功能。
(2) 编写一个类Parcel2,里面有两个内部类Content和Destination。为
Parcel2写一个方法Destination to(String s)和Contents cont(),分别返回包裹的目的地和内容。
请写出程序和执行结果。
参考程序:
public class Parcel1 {
class Contents { //内部类
private int i = 11;
public int value() { return i; }
}
class Destination { //内部类
private String label;
Destination(String whereTo) { label = whereTo; }
String readLabel() { return label; }
}
public void ship(String dest) {
Contents c = new Contents();
Destination d = new Destination(dest);
System.out.println(d.readLabel());
}
public static void main(String[] args) {
Parcel1 p = new Parcel1();
p.ship("Tanzania");
}
}
public class Parcel2 {
class Contents {
private int i = 11;
public int value() { return i; }
}
class Destination {
private String label;
Destination(String whereTo) { label = whereTo; } String readLabel() { return label; }
}
public Destination to(String s)
{ return new Destination(s); }
public Contents cont() { return new Contents(); }
public void ship(String dest) {
Contents c = cont();
Destination d = to(dest);
System.out.println(d.readLabel());
}
public static void main(String[] args) {
Parcel2 p = new Parcel2();
p.ship("Tanzania");
Parcel2 q = new Parcel2();
Parcel2.Contents c = q.cont();
Parcel2.Destination d =q.to("Borneo"); }
}
图形用户界面
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
public class aFrame extends JFrame { int count=0;
JLabel l1;
JButton b1;
public aFrame()
{
this.setTitle("界面"); this.setLocation(300, 100); this.setSize(250, 100); this.setVisible(true); l1=new JLabel("我是个标签"); l1.setHorizontalAlignment(SwingConstants.CENTER); b1=new JButton("按钮"); this.add(l1,"North"); this.add(b1,"South"); b1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub count++;
l1.setText("按钮被按下"+count+"次."); }
});
}
public static void main(String[] args) {
new aFrame();
}
}