我只是收集一下题目,检查一下自己。
京东平台产品研发部 - Java
背景:一年工作经验,做电子政务
- 一个数组 i[] = [-1000 ~ 1000] 中的任意一些数字,求乘积最大的三个数。
- static都能用在哪里?
- 1M 等于多少个1
- 面向对象的特性
- 写出两种单例模式
- HashMap有哪些方法
- HashMap的底层实现
- List和Set的区别
- 重载和重写的区别,多态如何体现
判断字符串是否含有此Url:www.jd.com
11.1
2
3
4
5
6
7
8
9Long l1 = new Long(1024L);
Long l2 = new Long(1024L);
System.out.println(l1 == l2);//false
Integer i1 = 100;
Integer i2 = 100;
System.out.println(i1 == i2);//true
i1 = 100;
i2 = 100;
System.out.println(i1 == i2);//trueSpring自定义注解、拦截器相关
- 为什么使用注解、有什么好处
- Spring中运用了哪些设计模式
- Sping和SpringBoot各有什么优缺点
- Spring的事物隔离机制
- 说说AOP、DI、IOC
- redis等用过没
- 缓存和memorycache
- http://www.jd.com/...username=... 为了防止sql注入,怎么写正则。
- mybatis如何防止sql注入
- mybatis使用变量时怎么表示
- 使用js遍历json数据
- 使用Map遍历json数据
- elasticsearch相关
- 你曾经在社区接触过的技术有哪些
- 项目相关:做了哪些部分、职责、用到哪些技术、设计了哪些
- 介绍一下RPC调用
谷歌淘来的一个总结
部分答案
一个数组 i[] = [-1000 ~ 1000] 中的任意一些数字,求乘积最大的三个数。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22/**
*
* 功能:求解一维无序数组中三个数字乘积最大值(正负零均存在)
*/
public void getMaxThreeNum() {
// 首先对数组进行升序排序
// 1. 数组左端是0,那么不存在负数,最大值为:i[-1]*i[-2]*i[-3]
// 2. 数组左端是正数,同上
// 3. 数组左端是负数,那么可能会负负得正,由于是升序,最大值为:i[0]*i[1]*i[-1]
// 4. 去上面两个的最大值即可
int[] i = {0,-10, -9, -8, 7, 6, 5, 4, 3, 2, 1};
Arrays.sort(i);
int length = i.length;
int a = i[0] * i[1] * i[length - 1];
int b = i[length - 1] * i[length - 2] * i[length - 3];
if (a > b) {//-10 * -9 * 7 = 630
System.out.println(i[0] + " * " + i[1] + " * " + i[length - 1] + " = " + a);
} else {
System.out.println(i[length - 1] + " * " + i[length - 2] + " * " + i[length - 3] + " = " + b);
}
}1M 等于多少个1
1
2
3
4
5
public void get1McanHoldInt(){
// int 占用4个字节 4Byte = 4 * 8bit
System.out.println(1*1024*1024/4);
}写出两种单例模式
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29//懒汉模式
public class LazySingleton {
private static LazySingleton instance = null;
private LazySingleton(){
super();
}
public static LazySingleton getInstance(){
if(instance == null){
// 静态方法,使用当前类本身充当进程锁
synchronized(LazySingleton.class){
instance = new LazySingleton();
}
}
return instance;
}
}
// 饿汉式单例模式
public class EagerSingleton {
private static EagerSingleton instance = new EagerSingleton();
private EagerSingleton(){
super();
}
// 不需要同步(类加载时已经初始化,不存在多线程的问题)
// 始终只有一个对象
public EagerSingleton getInstance(){
return instance;
}
}判断字符串是否含有此Url:www.jd.com
1
2
3
4
5
6
7
8
9
10
11
public void isHaveUrl(){
String url = "这是京东官网:www.jd.com";
Pattern pattern = Pattern.compile(".*www.jd.com.*");
Matcher matcher = pattern.matcher(url);
if (matcher.find()){
System.out.println(matcher.group());
}else {
System.out.println("未匹配");
}
}http://www.jd.com/...username=... 为了防止sql注入,怎么写正则。
1
2将包含有 单引号('),分号(;) 和 注释符号(--)的语句给替换掉来防止SQL注入
str.replaceAll("([';])+|(--)+","");mybatis如何防止sql注入
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30防护一:sql语句不在使用${}表达式,改为#{}
<select id="getBlogById" resultType="Blog" parameterType=”int”>
SELECT id,title,author,content
FROM blog
WHERE id=#{id}
</select>
编译后的SQL:SELECT id,title,author,content FROM blog WHERE id = ? (能避免sql注入)
<select id="getBlogById" resultType="Blog" parameterType=”int”>
SELECT id,title,author,content
FROM blog
WHERE id=${id} <!--假如id= 3 -->
</select>
编译后的SQL:SELECT id,title,author,content FROM blog WHERE id = 3 (无法避免sql注入)
SQL注入只能对编译过程起作用
#{}:相当于JDBC中的PreparedStatement
${}:是输出变量的值
#{}是经过预编译的,是安全的;
${}是未经过预编译的,仅仅是取变量的值,是非安全的,存在SQL注入。
防护二:采用阿里的druid数据连接池,添加如下配置
<!-- 配置监控统计拦截的filters,和防sql注入 -->
<property name="filters" value="stat,wall" />
防护三:使用正则表达式过滤输入参数mybatis使用变量时怎么表示
1
2
3
4
5
6
7#与$的区别
1.#是把传入的数据当作字符串,如#field#传入的是id,则sql语句生成是这样,order by "id",这当然会报错..
2.$传入的数据直接生成在sql里,如$field$传入的是id,则sql语句生成是这样,order by id, 这就对了.
3.#方式能够很大程度防止sql注入.
4.$方式无法防止sql注入.
5.$方式一般用于传入数据库对象.例如传入表名.
6.一般能用#的就别用$.使用js遍历json数据
1
2
3
4var data=[{name:"a",age:12},{name:"b",age:11},{name:"c",age:13},{name:"d",age:14}];
for(var o in data){
alert("text:"+data[o].name+" value:"+data[o].age );
}