javastuffs的简单介绍
本篇文章给大家谈谈javastuffs,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、求JAVA大佬
- 2、Java.util包简介 如何开发应用之一
- 3、求教翻译
- 4、哪位亲知道1993-2000年加拿大发明的所有东西(all kinds of inventions and innovation)
求JAVA大佬
/**
* @author 徒有琴 扣:574549426
*/
class Test{
public static void main(String[] args) {
Stuff[]stuffs=new Stuff[10];
for (int i = 0; i stuffs.length; i++) {
if(i%2==0){
stuffs[i]=new Book("book"+i,"press"+i);
}else{
stuffs[i]=new Cloth("Nick"+i,"Color"+i);
}
}
Bag luggage=new Luggage(5);
Bag schoolBag=new SchoolBag(5);
for (int i = 0; i stuffs.length; i++) {
luggage.putStuff(stuffs[i]);
schoolBag.putStuff(stuffs[i]);
}
luggage.printAllStuffs();
schoolBag.printAllStuffs();
}
}
public class Bag {
Stuff[] stuffs;
int size;
int currentSize;
public Bag(int size) {
this.size = size;
this.currentSize = 0;
this.stuffs = new Stuff[size];
}
void putStuff(Stuff stuff) {
if (currentSize = size) {
System.out.println("满了");
return;
}
stuffs[currentSize] = stuff;
currentSize++;
}
Stuff getStuff(int index) {
if (index = currentSize) {
System.out.println("没有");
return null;
}
return stuffs[index];
}
void printAllStuffs() {
for (Stuff stuff : stuffs) {
System.out.println(stuff);
}
}
}
class Luggage extends Bag {
public Luggage(int size) {
super(size);
}
}
class SchoolBag extends Bag {
public SchoolBag(int size) {
super(size);
}
}
class Stuff {
}
class Book extends Stuff {
String bookName;
String press;
public Book(String bookName, String press) {
this.bookName = bookName;
this.press = press;
}
@Override
public String toString() {
return "Book{" +
"bookName='" + bookName + '\'' +
", press='" + press + '\'' +
'}';
}
}
class Cloth extends Stuff {
String brand;
String color;
public Cloth(String brand, String color) {
this.brand = brand;
this.color = color;
}
@Override
public String toString() {
return "Cloth{" +
"brand='" + brand + '\'' +
", color='" + color + '\'' +
'}';
}
}
Java.util包简介 如何开发应用之一
ArrayList是List接口的一个可变长数组实现 实现了所有List接口的操作 并允许存储null值 除了没有进行同步 ArrayList基本等同于Vector 在Vector中几乎对所有的方法都进行了同步 但ArrayList仅对writeObject和readObject进行了同步 其它比如add(Object) remove(int)等都没有同步 存储 ArrayList使用一个Object的数组存储元素 private transient Object elementData[];ArrayList实现了java io Serializable接口 这儿的transient标示这个属性不需要自动序列化 下面会在writeObject()方法中详细讲解为什么要这样作 add和remove public boolean add(Object o){ensureCapacity(size + );// Increments modCount!!elementData[size++] = o;return true;}注意这儿的ensureCapacity()方法 它的作用是保证elementData数组的长度可以容纳一个新元素 在 自动变长机制 中将详细讲解 public Object remove(int index){RangeCheck(index);modCount++;Object oldValue = elementData[index];int numMoved = size index ;if (numMoved )System arraycopy(elementData index+ elementData index numMoved);elementData[ size] = null;// Let gc do its workreturn oldValue;}RangeCheck()的作用是进行边界检查 由于ArrayList采用一个对象数组存储元素 所以在删除一个元素时需要把后面的元素前移 删除一个元素时只是把该元素在elementData数组中的引用置为null 具体的对象的销毁由垃圾收集器负责 modCount的作用将在下面的 iterator()中的同步 中说明 注 在前移时使用了System提供的一个实用方法 arraycopy() 在本例中可以看出System arraycopy()方法可以对同一个数组进行操作 这个方法是一个native方法 如果对同一个数组进行操作时 会首先把从源部分拷贝到一个临时数组 在把临时数组的元素拷贝到目标位置 自动变长机制 在实例化一个ArrayList时 你可以指定一个初始容量 这个容量就是elementData数组的初始长度 如果你使用 ArrayList list = new ArrayList();则使用缺省的容量 public ArrayList(){this( );}ArrayList提供了四种add()方法 public boolean add(Object o)public void add(int index Object element)public boolean addAll(Collection c)public boolean addAll(int index Collection c)在每一种add()方法中 都首先调用了一个ensureCapacity(int miniCapacity)方法 这个方法保证elementData数组的长度不小于miniCapacity ArrayList的自动变长机制就是在这个方法中实现的 public void ensureCapacity(int minCapacity){modCount++;int oldCapacity = elementData length;if (minCapacity oldCapacity){Object oldData[] = elementData;int newCapacity =(oldCapacity * )/ + ;if (newCapacity minCapacity)newCapacity = minCapacity;elementData = new Object[newCapacity];System arraycopy(oldData elementData size);}}从这个方法实现中可以看出ArrayList每次扩容 都扩大到原来大小的 倍 每种add()方法的实现都大同小异 下面给出add(Object)方法的实现 public boolean add(Object o){ensureCapacity(size + );// Increments modCount!!elementData[size++] = o;return true;} iterator()中的同步 在父类AbstractList中定义了一个int型的属性 modCount 记录了ArrayList结构性变化的次数 protected transient int modCount = ;在ArrayList的所有涉及结构变化的方法中都增加modCount的值 包括 add() remove() addAll() removeRange()及clear()方法 这些方法每调用一次 modCount的值就加 注 add()及addAll()方法的modCount的值是在其中调用的ensureCapacity()方法中增加的 AbstractList中的iterator()方法(ArrayList直接继承了这个方法)使用了一个私有内部成员类Itr 生成一个Itr对象(Iterator接口)返回 public Iterator iterator(){return new Itr();}Itr实现了Iterator()接口 其中也定义了一个int型的属性 expectedModCount 这个属性在Itr类初始化时被赋予ArrayList对象的modCount属性的值 int expectedModCount = modCount;注 内部成员类Itr也是ArrayList类的一个成员 它可以访问所有的AbstractList的属性和方法 理解了这一点 Itr类的实现就容易理解了 在Itr hasNext()方法中 public boolean hasNext(){return cursor != size();}调用了AbstractList的size()方法 比较当前光标位置是否越界 在Itr next()方法中 Itr也调用了定义在AbstractList中的get(int)方法 返回当前光标处的元素 public Object next() {try {Object next = get(cursor);checkForComodification();lastRet = cursor++;return next;} catch(IndexOutOfBoundsException e) {checkForComodification();throw new NoSuchElementException();}}注意 在next()方法中调用了checkForComodification()方法 进行对修改的同步检查 final void checkForComodification(){if (modCount != expectedModCount)throw newConcurrentModificationException();}现在对modCount和expectedModCount的作用应该非常清楚了 在对一个集合对象进行跌代操作的同时 并不限制对集合对象的元素进行操作 这些操作包括一些可能引起跌代错误的add()或remove()等危险操作 在AbstractList中 使用了一个简单的机制来规避这些风险 这就是modCount和expectedModCount的作用所在 序列化支持 ArrayList实现了java io Serializable接口 所以ArrayList对象可以序列化到持久存储介质中 ArrayList的主要属性定义如下 private static final longserialVersionUID = L;private transient Object elementData[];private int size;可以看出serialVersionUID和size都将自动序列化到介质中 但elementData数组对象却定义为transient了 也就是说ArrayList中的所有这些元素都不会自动系列化到介质中 为什么要这样实现?因为elementData数组中存储的 元素 其实仅是对这些元素的一个引用 并不是真正的对象 序列化一个对象的引用是毫无意义的 因为序列化是为了反序列化 当你反序列化时 这些对象的引用已经不可能指向原来的对象了 所以在这儿需要手工的对ArrayList的元素进行序列化操作 这就是writeObject()的作用 private synchronized void writeObject(java io ObjectOutputStream s)throws java io IOException{// Write out element count and any hidden stuffs defaultWriteObject();// Write out array lengths writeInt(elementData length);// Write out all elementsin the proper order for (int i= ; isize; i++)s writeObject(elementData[i]);}这样元素数组elementData中的所以元素对象就可以正确地序列化到存储介质了 对应的readObject()也按照writeObject()方法的顺序从输入流中读取 private synchronized void readObject(java io ObjectInputStream s)throws java io IOException ClassNotFoundException{// Read in size and anyhidden stuffs defaultReadObject();// Read in array lengthand allocate arrayint arrayLength = s readInt();elementData =new Object[arrayLength];// Read in all elementsin the proper order for (int i= ; isize; i++)elementData[i] = s readObject();} lishixinzhi/Article/program/Java/hx/201311/27063
求教翻译
100%正确 非机器翻译
In today's society, the development of the network times, with the maturation of network technology, network communication has plays a pivotal role, more and more people indoors can make friend, a network of all the stuffs communication tools.
Based on network communication tool to use the development of relevant technology simply introduced, through the analysis of the system, discusses the necessity and feasibility of developing subject function and design topic, and the realization of the function of the structure and the relationship between database tables, through the Eclipse, Java development tools, and Access based on C/S model of the development of network communication tools. Through the test of the subject, to further improve the verification and beautification, finally can realize user register, login, check the online user, check chat logs, save chat logs, group chat and a private chat function.
哪位亲知道1993-2000年加拿大发明的所有东西(all kinds of inventions and innovation)
1993年 “奔腾”处理器面世。1994年 研制出HIV(艾滋病)蛋白酶抑制剂。1995年 新型计算机语言Java被发明。
1993年,在与世隔绝的“生物圈2号”中生活了两年之久的8位科学家,平安地走出这一人造小世界,标志着美国“生物圈2号”计划首次试
验结束;
1993年,美国将信息高速公路列入政府建设计划,一时间信息高速公路在全世界成为人们最感兴趣的话题;
1994年,与英吉利海峡隧道工程、香港新机场工程、中东和平管道引水工程等一起入选世界超级工程的长江三峡工程正式开工;
1995年6月,美国“亚特兰蒂斯”号航天飞机与俄罗斯和平号空间站对接成功,标志着人类在空间活动中的国际合作正在成为一种趋势;
1997年2月24日,多利羊问世,克隆
javastuffs的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、javastuffs的信息别忘了在本站进行查找喔。
发布于:2022-12-29,除非注明,否则均为
原创文章,转载请注明出处。