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. 廖雪峰Java11多线程编程-3高级concurrent包-2ReadWriteLock

    ReentrantLock保证单一线程执行 ReentrantLock保证了只有一个线程可以执行临界区代码: 临界区代码:任何时候只有1个线程可以执行的代码块. 临界区指的是一个访问共用资源(例如:共 ...

  2. springboot与任务(定时任务)

    描述: 项目开发中经常需要执行一些定时任务,比如需要在每天凌晨时候,分析一次前一天的日志信息.Spring为我们提供了异步执行任务调度的方式,提供TaskExecutor .TaskScheduler ...

  3. 2019/10/24 CSP-S 模拟

    T1 tom 题意: 考虑一定是属于\(a\)的在一坨,属于\(b\)的在一坨,找到这条连接\(a\)和\(b\)的边,然后分别直接按\(dfs\)序染色即可 注意属于\(a\)的连通块或属于\(b\ ...

  4. Spring注解驱动(下)

    9.@PropertySource 加载配置文件 在xml中 我们加载property配置文件,是使用 <context:property-placeholder location=" ...

  5. TensorFlow实战Google深度学习框架-人工智能教程-自学人工智能的第二天-深度学习

    自学人工智能的第一天 "TensorFlow 是谷歌 2015 年开源的主流深度学习框架,目前已得到广泛应用.本书为 TensorFlow 入门参考书,旨在帮助读者以快速.有效的方式上手 T ...

  6. stylus实现边框1px

    //1px的实现 border($border-width = 1px, $border-color = #ccc, $border-style = solid, $radius = ) // 为边框 ...

  7. iBatis 代码自动生成工具 iBator 及 Example 使用

    iBator的下载和安装 官方下载地址:http://people.apache.org/builds/ibatis/ibator/ 安装:见<Eclipse 插件安装> 安装完成后,“F ...

  8. 周期串Uva455 P37 3-4

    A character string is said to have period k if it can be formed by concatenating one or more repetit ...

  9. python中defaultdict方法的使用

    默认值可以很方便 众所周知,在Python中如果访问字典中不存在的键,会引发KeyError异常(JavaScript中如果对象中不存在某个属性,则返回undefined).但是有时候,字典中的每个键 ...

  10. 基于宜搭的《T恤尺码收集》应用搭建

    简介: 在阿里,T恤是程序员必不可少的元素.每逢公司或者BU(部门)的重大节庆日,比如双11 .年会.新BU成立仪式.大型活动等,都会给员工定制发放统一的T恤或者POLO衫服装.而我们每次发放T恤之前 ...