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. ng-zorro-mobile中遇到的问题

    一.Modal(弹出框)使用上的问题 在官方文档中,Modal是这样使用的: 这里需要注意的一点就是,看到上方代码中只用了Modal的全局方式,所以个人认为下面这段注入初始化的东西是没有用的便去掉: ...

  2. JavaSE_11_File类、递归

    1.1 概述File类 java.io.File 类是文件和目录路径名的抽象表示,主要用于文件和目录的创建.查找和删除等操作. 1.2 构造方法 public File(String pathname ...

  3. 洛谷P4550 【收集邮票】

    题目链接: 神仙题QAQ 题目分析: 概率期望题是不可能会的,一辈子都不可能会的QAQ 这个题也太仙了 首先明确一下题意里面我感觉没太说清楚的地方,这里是抽到第\(i\)次要\(i\)元钱,不是抽到第 ...

  4. Installer - win10安装及卸载SQL Server2008数据库

    一.数据库安装环境 操作系统:win10 SQL server:SQL server 2008 R2 二.全新数据库安装 1.安装扩展文件 双击安装文件,弹出如下窗体:                 ...

  5. 服务器迁移部署PosEdi

    绑定 基本配置 高级配置

  6. Everything-启用http服务器(公网IP)会导致共享文件被搜索引擎搜索

    1. 漏洞利用成功的前提 公网ip 启用http服务器 2.产生原因 启用http服务器功能点:让用户在本地或局域网上的其他电脑使用浏览器进行搜索,并支持文件下载.若拥有公网IP的用户启用此功能,就是 ...

  7. 常用的函数:atoi,itoa,atof,_ttoi等

    出自http://blog.csdn.net/zzyoucan/article/details/10260093 atoi---ASCII to integer,将字符串转换成整形,从数字或正负号开始 ...

  8. MapReduce 图解流程

    Anatomy of a MapReduce Job In MapReduce, a YARN application is called a Job. The implementation of t ...

  9. Windows API 23 篇 WTSQuerySessionInformation

    函数原型:BOOLWINAPIWTSQuerySessionInformationW(                                                      IN ...

  10. watch、tail联合使用

    因为用了tmux,不想调整窗格大小,只想输出命令结果的最后几行,所以就想出了这个方法. watch.tail联合用法 watch 'echo "`nvidia-smi`" | ta ...