javaweb记录

一、java使用

1.在一个数组中查询指定元素是否存在。

String[]   list ={"www","sd"};

Arrays.sort(list);

Arrays.binarySearch(list,"ss");

2.提升字符串连接性能

   2.1  StringBuffer 

var buffer = new StringBuffer ();
buffer.append("hello ");
buffer.append("world");
var result = buffer.toString();
2.2  Array
 
 
var arr = new Array();
arr[0] = "hello ";
arr[1] = "world";
var str = arr.join("");


二、js学习记录(js与java的不同之处)

在js中

1.函数是函数(Function)的实例。

2.this关键字代表的是调用函数的对象。它用在对象的方法中关键字 this 总是指向调用该方法的对象

3.属性可以在创建对象后动态创建。

4.函数变量和构造函数的区别,构造函数的首字母需要大写。比如说下面的Car,而如果是函数变量则不需要大写。注意区分

function Car(sColor,iDoors,iMpg) {
  this.color = sColor;
  this.doors = iDoors;
  this.mpg = iMpg;
  this.showColor = function() {
    alert(this.color);
  };
}

var oCar1 = new Car("red",4,23);
var oCar2 = new Car("blue",3,25);
5.原型方式定义属性( 该方式利用了对象的 prototype 属性)使用 混合的构造函数/原型方式创建类

function Car(sColor,iDoors,iMpg) {
  this.color = sColor;
  this.doors = iDoors;
  this.mpg = iMpg;
  this.drivers = new Array("Mike","John");
}
//使用原型方式,不能通过给构造函数传递参数来初始化属性的值
Car.prototype.showColor = function() {
  alert(this.color);
};

var oCar1 = new Car("red",4,23);
var oCar2 = new Car("blue",3,25);

oCar1.drivers.push("Bill");

alert(oCar1.drivers);	//输出 "Mike,John,Bill"
alert(oCar2.drivers);	//输出 "Mike,John"

6.提高连接多个字符串的性能

<html>
<body>
<script type="text/javascript">
function StringBuffer () {
  this._strings_ = new Array();
}
StringBuffer.prototype.append = function(str) {
  this._strings_.push(str);
};
StringBuffer.prototype.toString = function() {
  return this._strings_.join("");
};
var d1 = new Date();
var str = "";
for (var i=0; i < 100000; i++) {
    str += "text";
}
var d2 = new Date();
document.write("Concatenation with plus: "
 + (d2.getTime() - d1.getTime()) + " milliseconds");
var buffer = new StringBuffer();
d1 = new Date();
for (var i=0; i < 100000; i++) {
    buffer.append("text");
}
var result = buffer.toString();
d2 = new Date();
document.write("<br />Concatenation with StringBuffer: "
 + (d2.getTime() - d1.getTime()) + " milliseconds");
</script>
</body>
</html>


猜你喜欢

转载自blog.csdn.net/weiqingsong150/article/details/51849137