Think in Java笔记
sutonline
这个作者很懒,什么都没留下…
展开
-
面向对象编程特点
面向对象编程特点Everything is an object . Think of an object as a fancy variable; it stores data, but you can “make requests” to that object, asking it to perform operations on itself. In theory, you can原创 2016-06-01 11:06:40 · 408 阅读 · 0 评论 -
think in java笔记: java.util.concurrent.CyclicBarrier
示例程序:import java.util.ArrayList;import java.util.List;import java.util.Random;import java.util.concurrent.BrokenBarrierException;import java.util.concurrent.CyclicBarrier;import java.util.concurre原创 2016-10-26 15:10:07 · 586 阅读 · 0 评论 -
think in java笔记:java.util.concurrent.Semaphore
think in java笔记:java.util.concurrent.Semaphore WHAT’SSemaphore是一个计数锁,很像Linux的Limit. 这个一般会结合资源一起使用,本身是包含了synchronization的,但是不能保证资源的取和释放与acquire()/release()是同步的。 所以还是需要在get和release Item的时候,加上同步操作。接受一个原创 2016-10-27 11:25:41 · 346 阅读 · 0 评论 -
Think in java笔记: Annotation
Think in java笔记: AnnotationAnnotation是什么? Annotation是一种元数据信息,很奇怪的想起来了AspectJ的AOP,就是在方法、package等元素上加上一些标记,然后再自定负责自己的annotation,实现功能。和interface差不多,但是可以有默认值。如何定义一个annotation@Target(ElementType.METHOD)原创 2016-10-18 11:23:35 · 500 阅读 · 0 评论 -
Thinking in java笔记: 关于thread group
Thinking in java笔记: 关于thread group Thread groups are best viewed as an unsuccessful experiment , and you may simply ignore their existence.Thread groups最好被看作是一个没有成功的实验品,最好忽略它。Why:在Effective Java 2原创 2016-10-20 09:55:53 · 385 阅读 · 0 评论 -
think in java笔记: synchronized
think in java笔记: synchronized使用synchronized关键字的作用 * 加锁方法,加锁的是object的实例。如果还有这个实例所属对象还有其他的synchronized方法,那么也会被锁上。如果是不同的对象,那么两个线程不会互斥。 * 加锁block,也是class级别的锁。也是实例级别上的所,不论是方法还是块儿都是一样的只能一个线程访问。如果是不同的对象,那么两原创 2016-10-20 14:19:39 · 304 阅读 · 0 评论 -
think in java笔记 upcasting
Think in java笔记 upcastingupcast本身的意思是从子类向父类转型,然后就会失去了本身特有的属性及方法。但是当转型成功之后,调用的方法是父类还是子类?First, you must understand, that by casting you are not actually changing the object itself, you are just labeling翻译 2016-06-27 14:13:20 · 419 阅读 · 0 评论 -
think in java笔记:RTTI-Runtime type information
RTTI-Runtime type information To understand how RTTI works in Java, you must first know how type information is represented at run time. This is accomplished through a special kind of object cal原创 2016-08-15 19:35:23 · 365 阅读 · 0 评论 -
什么时候该用成员变量、什么时候用方法变量?
Use class level field or method variable?(什么时候该用成员变量、什么时候用方法变量?)If it’s strongly associated with the class, make it static.If it’s strongly associated with an instance, make it a non–static member.I转载 2016-07-04 08:45:20 · 700 阅读 · 0 评论 -
每个Java文件自动导入的library
每个Java文件自动导入的library At the beginning of each program file, you must place any necessary import statements to bring in extra classes you’ll need for the code in that file. Note that I say “ext翻译 2016-06-12 14:38:14 · 736 阅读 · 0 评论 -
think in java笔记: Thread的interrupt()方法
think in java笔记: Thread的interrupt()方法interrupt()是什么?Thread.interrupt()设置目标线程的中断状态,或者说标识。在目标线程中运行的code 可能 会拉出来这个标识,然后处理它。一些方法比如object.wait()是可以处理这个标识的,并且跑出来一个合适的异常,通常是InterruptedException.哪些可以中断?Objec原创 2016-10-26 17:07:21 · 285 阅读 · 0 评论 -
使用wait的时候,什么要使用while
使用wait的时候,什么要使用while:你或许有多个任务为同样的原因等待同样的锁, 并且第一个唤醒的任务或许已经改变了情况(甚至你不这么做,但是继承你的类可以这么做)。如果是这种情况,那么这个task就应该被暂停,直到满足条件。当这个任务从它的等待状态中唤醒的时候,可能其他的任务已经改变了状态,以致于这个任务不能运行。只能继续等待。还有情况是你的object lock可能被多种原因在等待(在原创 2016-10-26 17:05:51 · 728 阅读 · 0 评论 -
think in java笔记:Dynamic Proxy
think in java笔记:Dynamic Proxyproxy是什么? Proxy is one of the basic design patterns. It is an object that you insert in place of the “real” object in order to provide additional or different opera原创 2016-08-17 22:06:44 · 334 阅读 · 0 评论 -
Inheritance
InheritanceQ:为什么要继承 You have two ways to differentiate your new derived class from the original base class. The first is quite straightforward: You simply add brand new methods to the derived class原创 2016-06-01 14:09:46 · 291 阅读 · 0 评论 -
Order of initialization
Order of initialization Within a class, the order of initialization is determined by the order that the variables are defined within the class. The variable definitions may be scattered throughout an翻译 2016-06-23 10:14:23 · 434 阅读 · 0 评论 -
Think in java笔记 final
Think in java笔记 final Many programming languages have a way to tell the compiler that a piece of data is “constant.” A constant is useful for two reasons: 1. It can be a compile-time constant翻译 2016-06-27 16:58:25 · 277 阅读 · 0 评论 -
think in java笔记 为什么用内部类
think in java笔记 why inner class? A question that cuts to the heart of inner classes is this: If I just need a reference to an interface, why don’t I just make the outer class implement that interface翻译 2016-07-04 08:33:17 · 430 阅读 · 0 评论 -
Rethowing Exception
Rethowing Excetpion在catch的block中可以使用throw继续向上抛,会忽略以后的catch块儿,不会捕获已捕捉的这个Exception。 在这种情况下,在更高的调用的时候捕获到的exception还是原来的,但是有两种情况可以改变exception的来源:1.调用e.fillInStackTrace() 2.使用throw,但是抛的是不同的exceptionpackage原创 2016-07-07 15:18:27 · 373 阅读 · 0 评论 -
think in java笔记:Throwable及Exception的分类
think in java笔记:ThrowableThrowable的定义: The Java class Throwable describes anything that can be thrown as an exception. Throwable的组成: There are two general types of Throwable objects (“types翻译 2016-07-07 18:06:16 · 568 阅读 · 0 评论 -
think in java笔记:this关键字
think in java笔记:this关键字 The this keyword—which can be used only inside a non-static method—produces the reference to the object that the method has been called for. You can treat the refere翻译 2016-06-22 11:14:26 · 415 阅读 · 0 评论 -
think in java笔记:How a garbage collector works
think in java笔记:How a garbage collector works If you come from a programming language where allocating objects on the heap is expensive, you may naturally assume that Java’s scheme of allocating翻译 2016-06-22 18:43:16 · 778 阅读 · 0 评论 -
think in java笔记:Lost Exception
think in java笔记:Lost Exception有特定的情况下会发生exception根本报不出来. 1. try{}中报exception,但是不catch,然后finally抛另外一个exception,这时候try中的exception就会完全看不到了 2. try{}抛exception,但是finally中是return,这种情况下也是完全报不出来具体代码如下:packag翻译 2016-07-08 10:24:59 · 396 阅读 · 0 评论 -
Vuex到底是什么
Vuex到底是什么现在在学习写一个工程的时候看到很多样例都用到了vuex,那么vuex究竟是什么? 从官网上说, Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式。它采用集中式存储管理应用的所有组件的状态.这个其实蛮难看懂。于是作者做了如下例子来说明,分别用纯vue和vue+vuex进行说明。需求是,一个数字,然后两个按钮+/-。纯vue的实现是:<script src="https:转载 2017-07-10 15:37:07 · 1360 阅读 · 0 评论