Java学习1

1.Java分为三个体系,分别为Java SE(J2SE,Java2 Platform Standard Edition,标准版),JavaEE(J2EE,Java 2 Platform, Enterprise Edition,企业版),Java ME(J2ME,Java 2 Platform Micro Edition,微型版)。

2.练手的代码:

package ar;

public class Student {
	private String sno,sname;
	private int score;
	
	public Student(String sno,String sname,int score)
	{
		super();
		this.sno=sno;
		this.sname=sname;
		this.score=score;
	}
	
	public Student()
	{
		
	}
	
	public String getSno()
	{
		return this.sno;
	}
	
	public void setSno(String sno)
	{
		this.sno=sno;
	}
	
	public String getSname()
	{
		return this.sname;
	}
	
	public void setSname(String sname)
	{
		this.sname=sname;
	}
	
	public int  getScore()
	{
		return this.score;
	}
	
	public void setScore(int score)
	{
		this.score=score;
	}
	
	public String toString()
	{
		return "学号:"+sno+" 姓名:"+sname+" 分数:"+score;
	}

}

package ar;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ArrayListDemo {
	
	public static void main(String args[])
	{
		List list=new ArrayList();//默认list是object类型
		Student s1=new Student("1","shidadiao",25);
		Student s2=new Student("2","dickstar",22);
		Student s3=new Student("3","chenhong",23);
		Student s4=new Student("4","daijianhua",22);
		list.add(s1);
		list.add(s2);
		list.add(s3);
		list.add(s4);
		Iterator it=list.iterator();
		while(it.hasNext())
		{
			System.out.println(it.next());
		}
		for(int i=0;i<list.size();i++)
		{
			Student s=(Student)list.get(i);
			System.out.println(s.getSno()+" "+s.getSname()+" "+s.getScore());
		}
	}

}

package ar;

import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;

public class ArrayListGeneric {
	
	public static void main(String args[])
	{
		List<Student> list=new ArrayList<Student>();
		Student s1=new Student("1","chenhong",2);
		Student s2=new Student("2","tom",3);
		Student s3=new Student("3","alice",3);
		list.add(s1);
		list.add(s2);
		list.add(s3);
		Iterator it=list.iterator();
		while(it.hasNext())
		{
			System.out.println(it.next());//System.out.println("----------------");
		}
		for(int i=0;i<list.size();i++)
		{
			Student s=list.get(i);
			System.out.println(s.getSno()+" "+s.getSname()+" "+s.getScore());
		}
	}

}


你可能感兴趣的:(Java学习1)