上海张江笔试题

1.

public class A
{
	public static void main(String[] args)
	{
		Float f = new Float(0.9f);
		Float g = new Float(0.9f);
		Double d = new Double(0.9);
		System.out.println(f == g);
		System.out.println(f.equals(d));
		System.out.println(f.equals(g));
		System.out.println(f.equals(new Float(0.9f)));
		System.out.println("result:" + (6 + 6));
		int i = 6 + 6;
		System.out.println(i);
		System.out.println(i + 6);
		System.out.println("result is:" + i + 6);
		System.out.println("result is:" + 6 + 6);
		short a = 128;
		byte b = (byte) a;
		System.out.println("result is:" + a);
		System.out.println("result is:" + b);
		short c = 132;
		byte d1 = (byte) c;
		System.out.println("result is:" + c);
		System.out.println("result is:" + d1);
run result:
 false
 false
 true
 true
 result:12
 12
 18
 result is:126
 result is:66
 result is:128
 result is:-128
 result is:132
 result is:-124
String a="hello";
  String b="hello";
  String d="hello";
  char[] c={'h','e','l','l','o'};
  String s1="hello" +"1";
  String s2 ="hello"+"1";
  String s3 = new String("hello1");
  System.out.println(a==b);
  System.out.println(a.equals(b));
  System.out.println(a.equals(c));
  System.out.println(a.equals(new String("hello")));
  System.out.println(s1==s2);
  System.out.println(s1==s3);
  System.out.println(s1.equals(s3));
	}
}

true
true
false
true
true
false
true


f==d incompatible operand types Float and Double
System.out.println("result is:" + 6 +++ 6); invalid argument to operation ++/--
2.
抽象类不能是final
抽象方法也不能是final,在接口中报显示:Illegal modifier for the interface method getMethod; only public & abstract are permitted
在抽象类中显示:The abstract method getMethod in type AbstractTest can only set a visibility modifier, one of public or protected
抽象方法不可以是private
抽象方法不可以是static,在抽象类中显示:The abstract method getMethod in type AbstractTest can only set a visibility modifier, one of public or protected.在接口中显示Remove invalid parameters
抽象方法只能放在抽象类中是错误的,还可以放在接口中
抽象方法在接口和类中都可以抛出异常,但子类或实现类要对异常进行处理
public abstract class AbstractTest {
public abstract int getMethod()throws Exception;
public abstract int getInt();
}
public interface InterfaceTest {
public int getMethod()throws Exception;
}
map and hashmap difference
map是接口,不能用new出对象
hashmap是继承map接口的实现类,可以new出对象,HashMap实现了接口Map,就是说HashMap实现了Map所有的方法

具体介绍
Map提供key到value的映射。一个Map中不能包含相同的key,每个key只能映射一个 value。HashMap是实现了Map接口的具体类.HashMap是采用key的hashCode分组而实现的一种Map。
HashMap的特点是查找速度快,缺点是不能保证迭代的顺序
3.
look at the following code, one variable "x" given, write a code segment;if the result is that x equals an even number,javaScript code will hide following HTML table
<div id="testVisiblitity">
<table border="1">
<tr>
<td>row 1,cell 1</td>
<td>row 2,cell 2</td>
</tr>
</table>
</div>

answer:
<script src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
if(x % 2 == 1){
$("#testVisiblitity").hide();
}else{
$("#testVisiblitity").show();
}
});
</script>

 

4.look at the following snippet,write code to perform the following 3 validations

make sure these two fields are required ,otherwise alert user message and stop

make sure these two fields are date format(such as'mm/dd/yyyy"), otherwise alert user message and stop

make sure "to_date" is larger than "from_date"

<html>
<form method="POST" name="form1" action="action1">
From Date <input type="text" name="from_date" size="10"/></br>
To Date <input type="text" name="to_date" size="10"/></br>
</form>
</html>

 

the second dont know how to validate, others validate as follow, any issue, please inform me

<script type="text/javascript src="jquery-1.7.2.min.js"/>
<script type="text/javascript">
$(document).ready(function(){
var fromDateParam = document.getElementById("from_date");
var fromDate = $.trim(fromDateParam.value);
var toDateParam = document.getElementById("to_date");
var toDate = $.trim(toDateParam.value);
if(fromDate==null||fromDate==''){
alert("input from date is null");
return;
}
if(toDate==null||toDate==''){
alert("input to date is null");
return;
}
Pattern pattern = new Pattern();
java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("MM/dd/yyyy");
Date fromDateFormat = dateFormat.parse(form.get("from_date"));
Date toDateFormat = dateFormat.parse(form.get("to_date"));
Boolean isNotPastDate = toDateFormat.compareTo(fromDateFormat)>=0;
if(!isNotPastDate){
alert("to date must be larger than from date, please full it again");
return;
}
});
</script>

 

5.InputStream in = new InputStream(); wrong, because Cannot instantiate the type InputStream

6.float a1 =1.0f;
double a2=1.0;

float a3=1.0;编译出错Type mismatch: cannot convert from double to float

Float a4= new Float(1.0);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值