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 二.守护线 ...
随机推荐
- jmeter做bbs作业时提示404错误
在用jemter做bbs作业时候,注册成功后会跳转到主页,在写主页的脚本的时候,将fiddler抓到的url复制到路径下方“/bbs/forum.php”,但是第一次复制的时候在/bbs/forum. ...
- HTML - 图片标签相关
<html> <head></head> <body> <!-- src : 图片的路径 (本地资源路径, 网络资源路径) title : 图片的 ...
- 0907NOIP模拟测试赛后总结
120分rank26.我又被打回原型了…… 下午考的.中午由于种种原因并没有睡好.于是状态很差. 第一眼看题感觉T1是一道XX题.部分分竟然给这么肥 然后看T2.T3好像都还不是特别恶心的题目,挺常规 ...
- Laravel移除Cache-Control
碰到一个问题,网站上线后,需要移除Cache-Control,就是下面这个东西 方案1 失败 参考网址:https://stackoverflow.com/questions/51821563/lar ...
- iOS之CGcontext.h方法和属性简介
/* CoreGraphics - CGContext.h Copyright (c) 2000-2012 Apple Inc. All rights reserved. */ #ifndef CGC ...
- ie浏览器下载附件中文乱码
String llq = request.getHeader( "USER-AGENT" ).toLowerCase();Boolean isIE = false;if (llq. ...
- Java学习之一(引用相关)
1.Java概述 首先,Java是一门面向对象的编程语言.相对于C/C++等语言,Java中没有指针,但是这不代表指针等知识不重要:Java中不存在多继承但是存在多接口.在我自己的学习过程之中,我偏向 ...
- java-学习网站推荐
技术博客: http://c.biancheng.net/view/1390.html (设计模式等等应有尽有,最全教程,强烈推荐!!!) hutool:http://hutool.mydoc.io/ ...
- nosql BASE
- No context type was found in the assembly
如果解决方法中有多个项目存在,记住要在默认项目中选择你需要的项目进行 enable-migrations add-migration 以及updatebase