1.Implement a thread-safe (blocking) queue:

Class Producer implements Runable{
Private final BlockingQueue queue;
Producer (BlockingQueue q){queue=q;}
Public void run(){
try{
while(true){queue.put(produce());
}catch(InterruptedException ex){…handle…}
}
Object produce(){…..}
} Class consumer implements runnable{
Private final BlockingQueue queue;
Consumer(BlockingQueue q){queue=q;}
Public void run(){
Try{
While(true){consume(queue.take());}
}catch(InterruptedExpection ex){… handle …}
}
void consumer(Object x){…}
}

2. Memory consistency effects: As with other concurrent collections, actions in a thread prior to placing an object into a BlockingQueue happen-before actions subsequent to the access or removal of that element from the BlockingQueue in another thread.

3. What are some ways to implement a singleton in Java

(1)
Public class SingletonObject
{
private Singleton(){ } public static SingletonObject getSingletonObject(){
return ref;
}
} private static SingletonObject ref; (2)
Public class singletonObject{
Private singleton(){}
Public static singletonObject getSingletonObject(){
Return ref;
} }

4.Checked vs unchecked exceptions, finalize

1) Checked: are the exceptions that are checked at compile time. If some code within a method throws a checked exception, then the method must either handle the exception or it must specify the exception using throws keyword. like IOexpection

2) Unchecked are the exceptions that are not checked at compiled time instead of runtime. In C++, all exceptions are unchecked, so it is not forced by the compiler to either handle or specify the exception. It is up to the programmers to be civilized, and specify or catch the exceptions. In Java exceptions under Error and RuntimeException classes are unchecked exceptions, everything else under throwable is checked.

3) Finalize: Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. Also, the garbage collector is not guaranteed to run at any specific time. In general, what I'm trying to say is finalize() is probably not the best method to use in general unless there's something specific you need it for.

5. What is a queue, stack, heap

Queue: FIFO

Stack: FILO, system allocate space on memory

Heap: by using new keyword allocate

6. What happens in the system during a recursive call

Defining recursion is easy – any routine that calls itself is a recursive routine. A call stack is a data structure used by the program to store information about the active subroutines in a program. The main reason for having a call stack is so that the program can keep track of where a subroutine should return control to once it finishes executing. A stack frame is a part of the call stack, and a new stack frame is created every time a subroutine is called. The stack frame is used to store all of the variables for one invocation of a routine.

Java review-basic2的更多相关文章

  1. Java Review (一、Java开发环境)

    @ 目录 Java程序运行机制 高级语言运行机制 编译型语言 解释型语言 Java运行机制和JVM 编写 编译 运行 Java开发工具包 JDK JRE JDK.JRE与JVM HelloWord 编 ...

  2. java:Review(Oracle-HTML-CSS)

    20170708_review: 1.oracle: 对表的操作: 使用命令行建立一张表:create table 表名 (列名 列名的类型 primarty key, ....); alter ta ...

  3. [Java 教程 01] Hello,Java!

    前言 从事编程已经有一段时间了,突然发现,Java作为我的第一编程语言,自己似乎对她并有一个系统的思想.当下Java依旧保持着超高的热度,新特性也不断出现,从当初学习的java6版本到最近刚出的jav ...

  4. Java Algorithm Problems

    Java Algorithm Problems 程序员的一天 从开始这个Github已经有将近两年时间, 很高兴这个repo可以帮到有需要的人. 我一直认为, 知识本身是无价的, 因此每逢闲暇, 我就 ...

  5. [Java 教程 00] 计算机基础

    前言 我想,来到这的朋友肯定是想学习JAVA或者想要进入IT这个行业的.考虑到大家的基础可能不一样,有些人可能还是用着新买的电脑,为了让大家在后续的学习中更加顺畅.在学习一门全新的计算机语言之前,我需 ...

  6. [Java 教程 04] Java基础语法

    在上一篇文章中我们已经运行了个简单的java程序,但是没有给大家讲解代码部分的内容与含义.学习,我们要做到知其然而知其所以然,所以本篇文章我们就来讲解java程序的基本语法,学完这篇文章你再回头看上篇 ...

  7. [Java 教程 03] 我的第一个Java程序

    现在,大家应该都已经安装好jdk环境了吧!是不是已经跃跃欲试,按耐不住心中的小激动了?那我们现在就来写我们java学习生涯中的第一个java程序. 文件相关设置 为了方便后面大家的学习呢?有一点大家还 ...

  8. [Java 教程 02] 开发环境搭建

    在上一篇文章对Java做了一个简单介绍之后,我想大家都已经对她有一个初步的认识了吧!那踏入正式学习使用Java之前,我们有一步是不得不做的,它是什么呢?没有错,就是我们本篇文章的标题所说,搭建Java ...

  9. Java时间格式字符串与Date的相互转化

    目录 将Date转化为格式化字符串 时间格式字符串转化为Date @ 将Date转化为格式化字符串 将Date转化为格式化字符串是利用SimpleDateFormat类继承自 java.text.Da ...

  10. 一些常见JAVA问题

    原文:https://blog.csdn.net/weiyongxuan/article/details/45920765 一.Java的异常的基类是java.lang.Throwable 二.守护线 ...

随机推荐

  1. android 遍历控件

    做个笔记 androuid 遍历一个 view 下面的子view // 保存 btnSaveRout.setOnClickListener(new OnClickListener() { @Overr ...

  2. 2016.8.19上午初中部NOIP普及组比赛总结

    2016.8.19上午初中部NOIP普及组比赛总结 链接:https://jzoj.net/junior/#contest/home/1338 这次总结发得有点晚啊!我在这里解释一下, 因为浏览器的问 ...

  3. css过渡属性transition简单示例

    2.transition 简单实例 demo1→在线预览源代码 效果 demo2→在线预览源代码 效果 demo3→在线预览源代码 效果

  4. safari跨域cookie的问题

    最近做了一个项目,是将自己公司的H5页面嵌入到其他公司的pc和移动端,采用的方案是iframe,跨域数据传输用的postMessage,最后在联调过程中发现iPhone的微信中无法打开,在 Setti ...

  5. jeecms 代码生成 Tools

    本文作者: IIsKei 本文链接: http://www.iskei.cn/posts/50510.html 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议 ...

  6. Delphi遍历进程-Win32API

    本博客的Delphi代码使用的版本均为DelphiXE10.x 1.1 .枚举进程 通过进程名称获取指定的进程ID,代码很详细,不再赘述 unit Uuitls; interface uses TlH ...

  7. 使用scrapy框架来进行抓取的原因

    在python爬虫中:使用requests + selenium就可以解决将近90%的爬虫需求,那么scrapy就是解决剩下10%的吗? 这个显然不是这样的,scrapy框架是为了让我们的爬虫更强大. ...

  8. myeclipse中tomcat内存大小的设置

    刚刚安装了myeclipse9.0,又配置了tomcat7.0,想用ssh框架搭个项目试试tomcat7.0,没想到刚启动项目就会报错,在tomcat6.0中就不会有问题,上网查了那些都不起作用,后来 ...

  9. Linux常用知识

    1.Redhat 系统按如下系统启动:加载内核执行init程序/etc/rc.d/rc.sysinit #由init执行的第一个脚本/etc/rc.d/rc${RUNLEVEL}d/* #$RUNLE ...

  10. HandlerInterceptorAdapter或HandlerInterceptor的使用

    Spring拦截器 HandlerInterceptorAdapter需要继承,HandlerInterceptor需要实现 可以作为日志记录和登录校验来使用 建议使用HandlerIntercept ...