AllenInWood's Blog

WritingAndCoding

  • Home
  • project
  • Categories
  • About
  • Archives
  • Tags
  • 公益404

HashSet's detail info/java

Posted on 2017-03-09   |   In code   |   0 comments   |   visitors

对于 HashSet 而言,它是基于 HashMap 实现的,HashSet 底层采用 HashMap 来保存所有元素,因此 HashSet 的实现比较简单
查看 HashSet 的源代码,可以看到如下代码:

Read more »

Java dynamic binding

Posted on 2016-12-30   |   In code   |   0 comments   |   visitors

1、Java动态绑定的内部实现机制

JAVA虚拟机调用一个类方法时,它会基于对象引用的类型(通常在编译时可知)来选择所调用的方法。相反,当虚拟机调用一个实例方法时,它会基于对象实际的类型(只能在运行时得知)来选择所调用的方法,这就是动态绑定,是多态的一种。动态绑定为解决实际的业务问题提供了很大的灵活性,是一种非常优美的机制。

JAVA对象模型

JAVA虚拟机规范并没有规定JAVA对象在堆里是如何表示的。对象的内部表示也影响着整个堆以及垃圾收集器的设计,它由虚拟机的实现者决定。

JAVA对象中包含的基本数据由它所属的类及其所有超类声明的实例变量组成。只要有一个对象引用,虚拟机就必须能够快速地定位对象实例的数据。另外,它也必须能通过该对象引用访问相应的类数据(存储于方法区的类型信息),因此在对象中通常会有一个指向方法区的指针。当程序在运行时需要转换某个对象引用为另外一种类型时,虚拟机必须要检查这种转换是否被允许,被转换的对象是否的确是被引用的对象或者它的超类型。当程序在执行instanceof操作时,虚拟机也进行了同样的检查。所以虚拟机都需要查看被引用的对象的类数据。

不管虚拟机的实现使用什么样的对象表示法,很可能每个对象都有一个方法表因为方法表加快了调用实例方法时的效率。但是JAVA虚拟机规范并未要求必须使用方法表,所以并不是所有实现中都会使用它。

下面是一种JAVA对象的内存表示(JAVA对象内存模型):
JAVA对象内存模型

方法数据存放在类的方法区中,包含一个方法的具体实现的字节码二进制。方法指针直接指向这个方法在内存中的起始位置,通过方法指针就可以找到这个方法。

Read more »

实例方法和类方法区别

Posted on 2016-12-30   |   In code   |   0 comments   |   visitors

Java中以static关键字修饰的方法称为类方法,实例化一个类,引用的普通方法称为实例方法

Read more »

generate Error

Posted on 2016-11-17   |   In code   |   0 comments   |   visitors

Python version: 2.7
nltk version: NLTK3.0.4
In version 3.0.4 of NLTK, there is an error when using the below code.

text3.generate()

After some searching, it is the version difference that contributes to this error.
In nltk 2.0.1, text has generate() this function. Just like below img:
version difference
text.py file in ..\Python\nltk-3.2.1\nltk do not have generate() this attribute

Solution: Change version

reference: http://blog.csdn.net/huludan/article/details/47375357

dispersion_plot ERROR

Posted on 2016-11-17   |   In code   |   0 comments   |   visitors

Python version: 2.7
Windows version: Windows 7 64-bit
Language of the system: Chinese
In Natural Language Processing with Python, I meet an error in using function dispersion_plot
My code is in the following

ValueError('The plot function requires matplotlib to be installed.')

So I install this module matplotlib with tool pip(pip tool can be installed in https://pypi.python.org/pypi/pip/)
Using code below:

python -m pip install matplotlib

In this way, I solve this problem, now let’s see the result:

text4.dispersion_plot(["citizens","democracy","freedom","duties","America"])

result

1234
AllenInWood

AllenInWood

imagination

18 posts
3 categories
30 tags
GitHub
© 2016 - 2019 AllenInWood