|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
windows系统样,他们做了什么事或者留了一些后门程序,谁都不知道,二,java开发是跨平台,任何系统上都可以运行,对于保密型系统和大型系统开发这是必要的数据|数据布局|数组我没看过其他言语版的数据布局,但以为java的完成办法很奇妙--用类和对象来完成.基于数组的表,头脑很复杂就是界说一个类用来存储一组数据,我界说的是ArrayListClass类,在类中界说用来操纵数组的办法.实在就是这么复杂,但详细操纵起来就会碰到良多贫苦了!
我们这个ArrayListClass类中起首应当包含一个数组型的域list,用来寄存数据,如许放在统一数组中数据之间就发生了地位上的接洽,使对数据的操纵便的复杂.但是这个数组究竟是甚么数据范例的,我们希冀这个表能用于一切的数据范例,我们不克不及将他纯真的流动成某一种.以是我们必需将这个数据大众化,办理的举措就是界说一个类,作为一切数据范例的超类.看这个DataElement:
publicabstractclassDataElement{
publicabstractbooleanequals(DataElementotherElement);
publicabstractintcompareTo(DataElementotherElement);
publicabstractvoidmakeCopy(DataElementotherElement);
publicabstractDataElementgetCopy();
}
将他界说成为笼统的,再在界说其他数据范例时承继并完成它,我界说了两个数据范例IntElement和StringElement:
IntElement:
publicclassIntElementextendsDataElement{
protectedintnum;
//constructors
publicIntElement(){
num=0;
}
publicIntElement(intnumber){
num=number;
}
publicIntElement(IntElementotherElement){
num=otherElement.num;
}
///get-setMethods
publicvoidsetNum(intnumber){
num=number;
}
publicintgetNum(){
returnnum;
}
/*(non-Javadoc)
*@seeDataElement#equals(DataElement)
*/
publicbooleanequals(DataElementotherElement){
//TODOAuto-generatedmethodstub
IntElementnewe=(IntElement)otherElement;
return(this.num==newe.num);
}
/*(non-Javadoc)
*@seeDataElement#compareTo(DataElement)
*/
publicintcompareTo(DataElementotherElement){
//TODOAuto-generatedmethodstub
IntElementnewe=(IntElement)otherElement;
if(this.num==newe.num)
return0;
elseif(this.num>newe.num)
return1;
else
return-1;
}
/*(non-Javadoc)
*@seeDataElement#makeCopy(DataElement)
*/
publicvoidmakeCopy(DataElementotherElement){
//TODOAuto-generatedmethodstub
IntElementnewe=(IntElement)otherElement;
this.num=newe.num;
}
/*(non-Javadoc)
*@seeDataElement#getCopy()
*/
publicDataElementgetCopy(){
//TODOAuto-generatedmethodstub
IntElementnewElement=newIntElement();
newElement.num=this.num;
returnnewElement;
}
publicStringtoString(){
returnString.valueOf(num);
}
}
StringElement:
publicclassStringElementextendsDataElement{
/**
*
*/
privateStringstr;
//constructors
publicStringElement(){
str=null;
}
publicStringElement(Stringstring){
str=string;
}
publicStringElement(StringElementotherElement){
str=otherElement.str;
}
//get-setMethods
publicvoidsetStr(Stringstring){
str=string;
}
publicStringgetStr(){
returnstr;
}
/*(non-Javadoc)
*@seeDataElement#equals(DataElement)
*/
publicbooleanequals(DataElementotherElement){
//TODOAuto-generatedmethodstub
StringElementnewe=(StringElement)otherElement;
return(str==newe.str);
}
/*(non-Javadoc)
*@seeDataElement#compareTo(DataElement)
*/
publicintcompareTo(DataElementotherElement){
//TODOAuto-generatedmethodstub
StringElementnewe=(StringElement)otherElement;
return(str.compareTo(newe.str));
}
/*(non-Javadoc)
*@seeDataElement#makeCopy(DataElement)
*/
publicvoidmakeCopy(DataElementotherElement){
//TODOAuto-generatedmethodstub
StringElementnewe=(StringElement)otherElement;
str=newe.str;
}
/*(non-Javadoc)
*@seeDataElement#getCopy()
*/
publicDataElementgetCopy(){
//TODOAuto-generatedmethodstub
StringElementothere=newStringElement();
othere.str=str;
returnothere;
}
publicStringtoString(){
returnstr;
}
}
已界说好了数据范例,以是list的数据范例我们就能够界说为DateElement[]了,如许就能够包含以是你想要的了,只需你在用的时分界说一个DataElement的子类就好了,这恰是java承继的精华地点.我们接着界说ArrayListClass类:
protectedintlength;
protectedintmaxSize;
protectedDataElement[]list;这就是它的一切域了.
接上去就是它的办法了,我们对表的操纵应当有良多种,好比拔出、查询、删减等等,我们要逐一的完成,详细办法不再赘述,且看最初完成代码
publicabstractclassArrayListClass{
//fields
protectedintlength;
protectedintmaxSize;
protectedDataElement[]list;
//defaltconstructors
publicArrayListClass(){
length=0;
maxSize=100;
list=newDataElement[maxSize];
}
//constructors
publicArrayListClass(intsize){
if(size<=0){
System.err.println("Thearrysizemustbepositive.Creatinganarrayofsize100.");
maxSize=100;
}
else
maxSize=size;
length=0;
list=newDataElement[maxSize];
}
publicArrayListClass(ArrayListClassotherList){
maxSize=otherList.maxSize;
length=otherList.length;
list=newDataElement[maxSize];
for(inti=0;i<length;i++){
list[i]=otherList.list[i].getCopy();
}
}
//methods
publicbooleanisEmpty(){
return(length==0);
}
publicbooleanisFull(){
return(length==maxSize);
}
publicintlistSize(){
returnlength;
}
publicintmaxListSize(){
returnmaxSize;
}
publicvoidprint(){
for(inti=0;i<length;i++){
System.out.print(list[i]+"");
}
System.out.println();
}
publicbooleanisItemAtEqual(intlocation,DataElementitem){
return(list[location].equals(item));
}
publicvoidinsrtAt(intlocation,DataElementinsertItem){
if(location<0||location>+maxSize){
System.out.println("Thepositionoftheitemtobeinsertedisoutofrange!!");
}
else
if(length>=maxSize)
System.err.println("Cantinsertinafulllist!!");
else{
for(inti=length;i>location;i--){
list[i]=list[i-1];
}
list[location]=insertItem.getCopy();
length++;
}
}
publicvoidinsertEnd(DataElementinsertItem){
if(length>=maxSize){
System.err.println("Cantinsertinafulllist!!");
}
else{
list[length]=insertItem.getCopy();
length++;
}
}
publicvoidremoveAt(intlocation){
if(location<0||location>=length){
System.err.println("Thelocationyouwanttoremoveisoutofrange!!");
}
else{
for(inti=location;i<length-1;i++){
list[i]=list[i+1];
}
list[length]=null;
length--;
}
}
publicDataElementretrieveAt(intlocation){
if(location<0||location>=length){
System.err.println("Thelocationofitemtoberetrievedisoutofrange!!");
returnnull;
}
else{
returnlist[location].getCopy();
}
}
publicvoidreplacAt(intlocation,DataElementrepItem){
if(location<0||location>=length)
System.out.println("Thepositionofitemtobereplacedisoutofrange!!");
else
list[location]=repItem.getCopy();
}
publicvoidclearList(){
for(inti=0;i<length;i++){
list[i]=null;
}
length=0;
System.gc();
}
publicvoidcopyList(ArrayListClassotherList){
if(this!=otherList){
for(inti=0;i<length;i++)
list[i]=null;
System.gc();
maxSize=otherList.maxSize;
length=otherList.length;
list=newDataElement[maxSize];
for(intj=0;j<length;j++)
list[j]=otherList.list[j].getCopy();
}
}
publicabstractintseqSearch(DataElementseqItem);
publicabstractvoidinsert(DataElementinsertItem);
publicabstractvoidremove(DataElementremoveItem);
}
看到代码的最初你回发明这个类实际上是一个笼统类,为何要如许界说呢?之以是如许我们是为了针对分歧是范例:按次表和非按次表.不难设想他们的一些办法是存在差别的,先看一下非按次表:
publicclassUnorderedArrayListextendsArrayListClass{
/**
*
*/
publicUnorderedArrayList(){
super();
//TODOAuto-generatedconstructorstub
}
/*(non-Javadoc)
*@seeArrayListClass#seqSearch(DataElement)
*/
publicintseqSearch(DataElementseqItem){
//TODOAuto-generatedmethodstub
intloc;
booleanfound=false;
for(loc=0;loc<length;loc++)
if(list[loc].equals(seqItem))
{
found=true;
break;
}
if(found)
returnloc;
else
return-1;
}
/*(non-Javadoc)
*@seeArrayListClass#insert(DataElement)
*/
publicvoidinsert(DataElementinsertItem){
//TODOAuto-generatedmethodstub
intloc;
if(length==0)
list[length++]=insertItem.getCopy();
else
if(length==maxSize)
System.err.println("Cantinsertinafulllist!!");
else{
loc=seqSearch(insertItem);
if(loc==-1)
list[length++]=insertItem.getCopy();
else
System.err.println("Theitemtobeinsertedisallreadyinthelist!!");
}
}
/*(non-Javadoc)
*@seeArrayListClass#remove(DataElement)
*/
publicvoidremove(DataElementremoveItem){
//TODOAuto-generatedmethodstub
intloc;
if(length==0)
System.err.println("Cantdeletefromaemptylist!!");
else{
loc=seqSearch(removeItem);
if(loc!=-1)
removeAt(loc);
else
System.err.println("Theitemtobedeletedisnotinthelist!!");
}
}
}
就是这么复杂!!信任按次表也能够轻松高顶了.
关于第二点:俺问问你,如果是企业级项目的话,诸如RMI,EJB,等一些关键技术,这些难道都不需要学么?如果光是使用jsp,servlet,javabean的话。 |
|