Java review-basic1
1. Dependency Injection Answer:
Any application is composed of many objects that collaborate with each other to perform some useful stuff. Traditionally each object is responsible for obtaining its own references to the dependent objects (dependencies) it collaborate with. When using Dependency Injection, objects are given their dependencies at run time rather than compile time (car manufacturing time). The Dependency (Wheel) can be injected into Car at run time. Inversion of Control (IoC) is a general concept, and it can be expressed in many different ways and Dependency Injection is merely one concrete example of Inversion of Control. This concept says that you do not create your objects but describe how they should be created. You don't directly connect your components and services together in code but describe which services are needed by which components in a configuration file. A container is then responsible for hooking it all up.
个人理解:
An application is composed by many objects and they collaborate with each others. Tranditionally, each object colaborate with others need to obtain reference from dependent objects. For Dependency Injection, objects are given thier dependency at run time rather than complie time. IOC inverson of control is an example of Dependency Injection. it doesn't need create reference object by ourself instead of descire how to create them. components and services, we don't need create connection between components and services in code but also descibe who to create connection between componetns and services in a configuration file.
三句话:
应用是对象与对象组成的,传统的对象之间需要自己建立引用并且管理他们。
在依赖注入中,对象在运行时获得他们的依赖而不是在编译时
IOC是DI的一种实现方式,不需要在代码中实现依赖,而是描述如何建立依赖,不要自己亲自建立组件与服务之间的关系,只需要在配置文件中描述如何建立。
2. How does Java HashMap or LinkedHashMap handles collisions?
Prior to Java 8, HashMap and all other hash table based Map implementation classes in Java handle collision by chaining, i.e. they use linked list to store map entries which ended in the same bucket due to a collision. If a key end up in same bucket location where an entry is already stored then this entry is just added at the head of the linked list there. In order to address this issue in the case of frequent HashMap collisions, Java8 has started using a balanced tree instead of linked list for storing collided entries
两句话,使用链表加上数组,当有相同元素因为碰撞放入了同一buket,就加在链表的前面,桶排列在数组中。
3. Reflection API
The name reflection is used to describe code which is able to inspect other code in the same system (or itself). For example, say you have an object of an unknown type in Java, and you would like to call a 'doSomething' method on it if one exists. Java's static typing system isn't really designed to support this unless the object conforms to a known interface, but using reflection, your code can look at the object and find out if it has a method called 'doSomething' and then call it if you want to.So, to give you a code example of this in Java
(imagine the object in question is foo) :
Method method = foo.getClass().getMethod("doSomething", null);
method.invoke(foo, null);
反射:如果我们不知道一个对象的类型,想确定调用一个方法,可以使用反射来调用这个方法并且使用。
4. Java 8 features - Lambda Expressions, Default Methods.
Lambda Expressions: parameter -> expression body Following are the important characteristics of a lambda expression − Optional type declaration − No need to declare the type of a parameter.
Default Methods: Java 8 introduces a new concept of default method implementation in interfaces. This capability is added for backward compatibility so that old interfaces can be used to leverage the lambda expression capability of Java 8.
5. Java Keywords - static, final, volatile, synchronized, transient, this, super etc.
Static: static members belong to the class instead of a specific instance. It means that only one instance of a static field exists even if you create a million instances of the class or you don't create any. It will be shared by all instances. Since static methods also do not belong to a specific instance, they can't refer to instance. static members can only refer to static members. Instance members can, of course access static members.
Volatile: the volatile keyword in Java is used as an indicator to Java compiler and Thread that do not cache value of this variable and always read it from main memory. So if you want to share any variable in which read and write operation is atomic by implementation e.g. read and write in an int or a boolean variable then you can declare them as volatile variable. The Java volatile keyword cannot be used with method or class and it can only be used with a variable.
transient: is a Java keyword which marks a member variable not to be serialized when it is persisted to streams of bytes. When an object is transferred through the network, the object needs to be 'serialized'. Serialization converts the object state to serial bytes. Those bytes are sent over the network and the object is recreated from those bytes. Member variables marked by the java transient keyword are not transferred; they are lost intentionally.
6. What is immutable, Implement an immutable class (e.g. myDateTime)?
As said earlier, Immutable classes are those class, whose object can not be modified once created, it means any modification on immutable object will result in another immutable object. Implements: best example to understand immutable and mutable objects are, String and StringBuffer. Since String is immutable class, any change on existing string object will result in another string e.g. replacing a character into String, creating substring from String, all result in a new objects. While in case of mutable object like StringBuffer, any modification is done on object itself and no new objects are created. Some times this immutability of String can also cause security hole, and that the reason why password should be stored on char array instead of String.
7. Atomic: is a toolkit of variable java.util.concurrent.atomic package classes, which assist in writing lock and wait-free algorithms with the Java language. An algorithm requiring only partial threads for constant progress is lock-free. Lock and wait-free algorithms are also known as nonblocking algorithms. Nonblocking algorithms are used for process and thread scheduling at the operating system and Java virtual machine levels.
Java review-basic1的更多相关文章
- Java Review (一、Java开发环境)
@ 目录 Java程序运行机制 高级语言运行机制 编译型语言 解释型语言 Java运行机制和JVM 编写 编译 运行 Java开发工具包 JDK JRE JDK.JRE与JVM HelloWord 编 ...
- java:Review(Oracle-HTML-CSS)
20170708_review: 1.oracle: 对表的操作: 使用命令行建立一张表:create table 表名 (列名 列名的类型 primarty key, ....); alter ta ...
- [Java 教程 01] Hello,Java!
前言 从事编程已经有一段时间了,突然发现,Java作为我的第一编程语言,自己似乎对她并有一个系统的思想.当下Java依旧保持着超高的热度,新特性也不断出现,从当初学习的java6版本到最近刚出的jav ...
- Java Algorithm Problems
Java Algorithm Problems 程序员的一天 从开始这个Github已经有将近两年时间, 很高兴这个repo可以帮到有需要的人. 我一直认为, 知识本身是无价的, 因此每逢闲暇, 我就 ...
- [Java 教程 00] 计算机基础
前言 我想,来到这的朋友肯定是想学习JAVA或者想要进入IT这个行业的.考虑到大家的基础可能不一样,有些人可能还是用着新买的电脑,为了让大家在后续的学习中更加顺畅.在学习一门全新的计算机语言之前,我需 ...
- [Java 教程 04] Java基础语法
在上一篇文章中我们已经运行了个简单的java程序,但是没有给大家讲解代码部分的内容与含义.学习,我们要做到知其然而知其所以然,所以本篇文章我们就来讲解java程序的基本语法,学完这篇文章你再回头看上篇 ...
- [Java 教程 03] 我的第一个Java程序
现在,大家应该都已经安装好jdk环境了吧!是不是已经跃跃欲试,按耐不住心中的小激动了?那我们现在就来写我们java学习生涯中的第一个java程序. 文件相关设置 为了方便后面大家的学习呢?有一点大家还 ...
- [Java 教程 02] 开发环境搭建
在上一篇文章对Java做了一个简单介绍之后,我想大家都已经对她有一个初步的认识了吧!那踏入正式学习使用Java之前,我们有一步是不得不做的,它是什么呢?没有错,就是我们本篇文章的标题所说,搭建Java ...
- Java时间格式字符串与Date的相互转化
目录 将Date转化为格式化字符串 时间格式字符串转化为Date @ 将Date转化为格式化字符串 将Date转化为格式化字符串是利用SimpleDateFormat类继承自 java.text.Da ...
- 一些常见JAVA问题
原文:https://blog.csdn.net/weiyongxuan/article/details/45920765 一.Java的异常的基类是java.lang.Throwable 二.守护线 ...
随机推荐
- [转]WPF的BitmapImage的文件无法释放及内存泄露的问题
相信用过WPF的BitmapImage的,都在用类似这样的代码来解决文件无法删除的问题! 如果看看msdn上简单的描述,可以看到这样的说明: 如果 StreamSource 和 UriSource 均 ...
- leetccode-130-被围绕的区域
题目描述: 方法一:dfs class Solution: def solve(self, board: List[List[str]]) -> None: """ ...
- Idea安装Mevn
1.下载mevn安装包. 下载地址:http://maven.apache.org/ 点击Download 2.下面这两个选哪个都可以,取决于你用什么方式解压 3.把下载好的安装包解压到一个没有中文的 ...
- 爬虫——python——百度地图经纬度查询——经纬度查看地点地名——利用百度API获取地名经纬度——爬取所有的中国地址
import requests address = '40.8587960,86.866991' url = 'http://api.map.baidu.com/geocoder?output=jso ...
- 线段树分治初步学习&洛谷P5227[AHOI2013]连通图
线段树分治 其实思想说起来是比较简单的,我们把这个题里的所有操作(比如连边删边查询balabala)全部拍到一棵线段树上,然后对着整棵树dfs一下求解答案,顺便把操作做一下,回溯的时候撤销一下即可.虽 ...
- PAT甲级——A1070 Mooncake
Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types ...
- 虚拟机vm安装黑群晖6.2
操作系统选择
- python 描述器
语法简析 一般来说,描述器(descriptor)是一个有”绑定行为”的对象属性(object attribute),它的属性访问被描述器协议方法重写.这些方法是 __get__(). __set__ ...
- Access数据库连接字符串
<connectionStrings> <add name="connStr" connectionString="server=.;uid=home; ...
- STL与泛型编程-学习2-GeekBand
9, 容器 Deque 双向队列 和vector类似, 新增加: push_front 在头部插入一个元素 pop_front 在头部弹出一个元素 Deque和vector内存管理不同: 大块分配内存 ...