1. The diffrence between java.lang.StringBuffer and java.lang.StringBuilder?

java.lang.StringBuffer: thread-safe, synchronized and not so faster.

java.lang.StringBuilder: faster, performs no synchronization.

2. How to handle uncaught Exception for a thread?

@FunctionalInterface
public static interface Thread.UncaughtExceptionHandler

3. The difference between [checked exceptions] and [unchecked exceptions]?

The class Exception and any subclasses that are not also subclasses of RuntimeException are checked exceptions. Checked exceptions need to be declared in a method or constructor's throws clause if they can be thrown by the execution of the method or constructor and propagate outside the method or constructor boundary.

Checked Exceptions should be used for expected, but unpreventable errors that are reasonable to recover from.

4. How to use non static innner class and static inner class?

non static: Out.In in = new Out().new In();

static: Out.StaticIn in = new Out.StaticIn();

5. Anonymous Inner Class?

Anonymous inner class must extends a super class or implements an interface.

ClassA a = new ClassA();

a.test(new Product(){

  public double process() {

  }

});

6. How to create dynamic proxy class and dynamic proxy instance?

java.lang.reflect.Proxy
interface InvocationHandler

static Class<?> getProxyClass(ClassLoader loader, Class<?>... interfaces)
static Object newProxyInstance(ClassLoader loader, Class<?>[] interfaces, InvocationHandler h)

InvocationHandler handler = new MyInvocationHandler(...);

Class proxyClass = Proxy.getProxyClass(Foo.class.getClassLoader(), new Class[] { Foo.class });
Constructor ctor = proxyClass.getConstructor(new Class[] { InvocationHandler.class });
Foo f = (Foo)ctor.newInstance(new Object[] { handler });

Foo f = (Foo)Proxy.newProxyInstance(Foo.class.getClassLoader(), new Class[] { Foo.class }, handler);

7. What's the difference between 3 types of class loaders?

public abstract class ClassLoader extends Object

loadClass(String name, boolean resolve)

findClass(String name)

Bootstrap ClassLoader: load core classes of Java. (java.exe -Xbootclasspath can load additional class). Not a subclass of java.lang.ClassLoader.

jre/lib/*.jar

jre/classes

Extension ClassLoader: jre/lib/ext/* or defined by java.ext.dirs System Property.

System ClassLoader: java -classpath or defined by java.class.path

java.lang.Object
  java.lang.ClassLoader
    java.security.SecureClassLoader
      java.net.URLClassLoader

Parents of Extension ClassLoader and System ClassLoader.

8. How does interface Serializable works?

All subtypes of a serializable class are themselves serializable.

Classes that require special handling during the serialization and deserialization:

private void writeObject(java.io.ObjectOutputStream out) throws IOException
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException;
private void readObjectNoData() throws ObjectStreamException;

Designate an alternative object to be used when writing an object to the stream:

ANY-ACCESS-MODIFIER Object writeReplace() throws ObjectStreamException;

Designate a replacement when read from the stream:

ANY-ACCESS-MODIFIER Object readResolve() throws ObjectStreamException;

ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;

9. How does Buffer works?

java.nio.Buffer
capacity is the number of elements it contains.
limit is the index of the first element that should not be read or written.
position is the index of the next element to be read or written.
mark is the index to which its position will be reset when the reset method is invoked.

0 <= mark <= position <= limit <= capacity

clear() sets the limit to the capacity and the position to zero.

flip() sets the limit to the current position and then sets the position to zero.

rewind() leaves the limit unchanged and sets the position to zero.

Buffers are not safe for use by multiple concurrent threads.

b.flip().position(23).limit(42);

10. The difference between interfaces of runnable and callable<v>?

callable can have return value.

11. The difference between java.util.Collections and interface Map<K,V>?

Collections contains only items while Map contains key-value pairs.

12. The difference between interface Set<E> (java.util.HashSet<E>) and interface List<E> (java.util.ArrayList<E>)?

Unordered and No-duplicated for Set<E>, Ordered and duplicated for List<E>.

13. The difference between HashSet, TreeSet and EnumSet?

14. The difference between HashTable, HashMap, EnumMap and TreeMap?

Non thread safe, key and value can be null for HashMap.

Thread safe, key and value can't be null for HashTable.

Java面试题(1)- 高级特性的更多相关文章

  1. 《深入理解Java虚拟机:JVM高级特性与最佳实践》【PDF】下载

    <深入理解Java虚拟机:JVM高级特性与最佳实践>[PDF]下载链接: https://u253469.pipipan.com/fs/253469-230062566 内容简介 作为一位 ...

  2. 《Java核心技术 卷II 高级特性(原书第9版)》

    <Java核心技术 卷II 高级特性(原书第9版)> 基本信息 原书名:Core Java Volume II—Advanced Features(Ninth Edition) 作者: ( ...

  3. 读书笔记-《深入理解Java虚拟机:JVM高级特性与最佳实践》

    目录 概述 第一章: 走进Java 第二章: Java内存区域与内存溢出异常 第三章: 垃圾收集器与内存分配策略 第四章: 虚拟机性能监控与故障处理 第五章: 调优案例分析与实战 第六章: 类文件结构 ...

  4. Java面试题之高级篇研读

    1.List和Set比较,各自的子类比较 对比一:ArrayList与LinkedList比较 1.ArrayList是实现了基于动态数组的数据结构,因为地址连续,一旦数据存储好了,查询操作效率会比较 ...

  5. 《深入理解Java虚拟机:JVM高级特性与最佳实践》读书笔记

    第一部分 走进Java 一.走进Java 1.概述 java广泛应用于嵌入式系统.移动终端.企业服务器.大型机等各种场合,摆脱了硬件平台的束缚,实现了“一次编写,到处运行”的理想 2.java技术体系 ...

  6. 2018.4.23 《深入理解Java虚拟机:JVM高级特性与最佳实践》笔记

    一.Java内存区域与内存溢出 1.程序计数器是一块较小的内存空间,它可看作是当前线程所执行的字节码的行号指示器.字节码解释器工作时就是通过改变这个计数器的值来选取下一条需要执行的字节码指令.各条线程 ...

  7. java程序-类的高级特性

    创建Employee类,在类中定义三个属性:编号,姓名,年龄,然后在构造方法里初始化这三个属性,最后在实现接口中的定义的CompareTo方法,将对象按编号升序排列. 代码如下:(程序可能有些错误,方 ...

  8. 深入理解Java虚拟机:JVM高级特性与最佳实践

    第一部分走近Java第1章走近Java21.1概述21.2Java技术体系31.3Java发展史51.4Java虚拟机发展史91.4.1SunClassicExactVM91.4.2SunHotSpo ...

  9. 深入理解Java虚拟机:JVM高级特性与最佳实践(第3版)请自取

    最近在读,附上网盘链接 复制这段内容后打开百度网盘手机App,操作更方便哦 链接:https://pan.baidu.com/s/1U6yFeZxz9uD6sSiu-Br06g 提取码:3Wt4

  10. 各大互联网企业Java面试题汇总,看我如何成功拿到百度的offer

    前言 本人Java开发,5年经验,7月初来到帝都,开启面试经历,前后20天左右,主面互联网公司,一二线大公司或者是融资中的创业公司都面试过,拿了一些offer,其中包括奇虎360,最后综合决定还是去百 ...

随机推荐

  1. 小C的故事(快速学C语言,,,极速版!)

    前几天这篇博客写了太多废话! 删啦~~. 本篇博客只是为chd A协的全嫩小鲜肉入门C语言的预科, 如果你在此处学习C语言, 不幸走火入魔, 小弱概不负责. //请直接随便找个C语言编译器,抄一下下面 ...

  2. yii-mail yii 发送邮件

    参考网址:http://shoukii0721.iteye.com/blog/1576225 有很多时候我们需要给用户发送邮件,作留言,或者是激活邮件.等用途. 需要注意的是,设置发送的邮件得有SMT ...

  3. asp.netMVC4(基础知识----传值问题分析)

    (1)一般在数据交互的时候,都会涉及到前后台间的相互传值,一般的情况下,方法也有多种,下面就后台定义变量往前台传值: 以下是后台代码: /// <summary> /// 展示举报信息 / ...

  4. 设计js通用库

    设计js通用库的四个步骤: 1.需求分析:分析库需要完成的所有功能. 2.编程接口:根据需求设计需要用到的接口及参数.返回值. 3.调用方法:支持链式调用,我们期望以动词方式描述接口. (ps:设计链 ...

  5. linux设备驱动编写_tasklet机制(转)

    在编写设备驱动时, tasklet 机制是一种比较常见的机制,通常用于减少中断处理的时间,将本应该是在中断服务程序中完成的任务转化成软中断完成. 为了最大程度的避免中断处理时间过长而导致中断丢失,有时 ...

  6. Java Socket编程----通信是这样炼成的

    Java最初是作为网络编程语言出现的,其对网络提供了高度的支持,使得客户端和服务器的沟通变成了现实,而在网络编程中,使用最多的就是Socket.像大家熟悉的QQ.MSN都使用了Socket相关的技术. ...

  7. maven install 报错Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project*****

    [ERROR]Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-co ...

  8. 转!论if else与switch的效率高低问题

    转 下面来详细描述switch与ifelse的区别. switch...case与if...else的根本区别在于,switch...case会生成一个跳转表来指示实际的case分支的地址,而这个跳转 ...

  9. LF CRLF

    在git提交的时候 有时候会提示这个 LF will be replaced by CRLF 这是因为window的结束符是:回车和换行 crlfmac和linux的结束符是 lf, 于是当代码在这两 ...

  10. ajax views

    https://julian.pustkuchen.com/en/drupal-7-api-trigger-views-ajax-refresh-javascript-or-php-using-aja ...