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. 解决Spring Boot Configuration Annotation Processor not found in classpath

    问题截图: 解决方式: 在pom.xml文件中添加这些依赖 <dependency> <groupId>org.springframework.boot</groupId ...

  2. 深入浅出 Java Concurrency (33): 线程池 part 6 线程池的实现及原理 (1)[转]

    线程池数据结构与线程构造方法 由于已经看到了ThreadPoolExecutor的源码,因此很容易就看到了ThreadPoolExecutor线程池的数据结构.图1描述了这种数据结构. 图1 Thre ...

  3. PAT甲级——【牛客练习A1004】

    题目描述 An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For ex ...

  4. IntelliJ IDEA community 安装教程

    jetbrains官网下载 IntelliJ IDEA安装包 https://www.jetbrains.com/idea/download/#section=windows 此处选择社区版的zip文 ...

  5. hexo_localhost:4000_无法访问

    title: 'hexo_localhost:4000_无法访问' date: 2016-05-02 09:38:51 categories: blog tags: [hexo] 问题描述 安装完成h ...

  6. Ubuntu 卸载nvidia驱动

    1.切换为集成显卡 如果没有,那么先切换到字符界面 2.卸载驱动 sudo apt-get --purge remove nvidia* sudo apt autoremove To remove C ...

  7. 2019-6-14-WPF-shows-that-some-windows-in-multithreading-will-be-locked-in-the-PenThreadWorker-constr...

    title author date CreateTime categories WPF shows that some windows in multithreading will be locked ...

  8. 如何做系列(4)-微博URL短网址生成算法原理(java版、php版实现实例)

    短网址(Short URL),顾名思义就是在形式上比较短的网址.通常用的是asp或者php转向,在Web 2.0的今天,不得不说,这是一个潮流.目前已经有许多类似服务,借助短网址您可以用简短的网址替代 ...

  9. [CQOI2009]叶子的染色【性质+树形Dp】

    Online Judge:Bzoj1304,Luogu P3155 Label:无根树,树形Dp 题目描述 给定一棵\(N\)个节点的无根树,它一共有\(K\)个叶子节点.你可以选择一个度数大于1的节 ...

  10. ODOO 新API修饰符

    Odoo8中,API接口分为traditaional style和record style两种类型: traditional style指的就是我们在7.0中使用的类型,def(self,cr,uid ...