Muwednesday's Note

  • Home

  • About

  • Tags

  • Categories

  • Archives

Java 垃圾回收机制

Posted on 2018-01-16 Edited on 2020-03-18 In Java

Java Memory Management, with its built-in garbage collection, is one of the language’s finest achievements. It allows developers to create new objects without worrying explicitly about memory allocation and deallocation, because the garbage collector automatically reclaims memory for reuse. This enables faster development with less boilerplate code, while eliminating memory leaks and other memory-related problems. At least in theory.

Java Memory ManagementHow Garbage Collection Works

Java 语言的一大特点就是可以进行自动垃圾回收。对 Java 程序员来说,在虚拟机(JVM)自动内存管理机制的帮助下,不再需要为每一个 new 操作去写配对的 delete/free 代码,不容易出现内存泄漏和内存溢出的问题。不过也正是因为这种便利,一旦出现内存泄漏和溢出方面的问题,如果不了解虚拟机是怎样使用内存的,那么排查错误将会成为一项异常艰难的任务。

本文是对周志明先生的《 深入理解 Java 虚拟机(第二版)》第二部分—— 自动内存管理机制 做的读书笔记,想要了解更详细的内容,请阅读原著。

Java 内存区域

在介绍垃圾回收(Garbage Collection,GC)之前,首先来了解一下 JVM 运行时数据区。根据 《The Java® Virtual
Machine Specification _Java SE 8 Edition_》
的规定,Java 虚拟机所管理的内存将会包括以下几个运行时数据区域:

Read more »

Git 命令

Posted on 2018-01-14 Edited on 2020-03-18 In Tools

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Documentationgit-scm.com

Git 是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。它是由 Linux 之父 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。本文介绍了 Git 的常用命令。

三种状态

在学习 Git 命令之前,首先要理解它的三种状态:已提交(committed)、已修改(modified)和已暂存(staged)。已提交表示数据已经安全的保存在本地数据库中;已修改表示修改了文件,但还没保存到数据库中,增加、删除文件也相当于已修改;已暂存表示对一个已修改文件的当前版本做了标记,使之包含在下次提交的快照中。

由此引入 Git 项目的三个工作区域的概念:Git 仓库、工作目录以及暂存区域。

Working tree, staging area, and Git directory

Read more »

HashMap 源码分析

Posted on 2018-01-03 Edited on 2020-03-18 In Java

Hash table based implementation of the Map interface. This implementation provides all of the optional map operations, and permits null values and the null key. (The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.) This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.

DocumentationJava Platform SE 8

HashMap 是基于散列表的 Map 接口的非同步实现,用于处理映射(键值对)。本文以 JDK 8 的源码为基础,深入分析了 HashMap 的 get&put 方法、扩容机制以及遍历等内容。

HashMap 简介

链表和数组可以按照人们的意愿排列元素的次序,但当查找某个元素时,使用这两种数据结构效率较低。如果不在意元素的顺序,可以用散列表来快速查找所需要的对象。散列表(Hash table,也叫哈希表),是根据键而直接访问在内存存储位置的数据结构。也就是说,它通过计算一个关于键值的函数,将所需查询的数据映射到表中一个位置来访问记录,这加快了查找速度。这个映射函数称为散列函数,存放记录的数字称为散列表。

有时我们知道某些键的信息,并想要查找与之对应的元素,这就需要用到映射(map)。映射用来存放键值对,如果提供了键, 就能够查找到值。HashMap 是散列映射的一种实现,对 key 进行散列,且只能作用于 key,与之关联的 value 不能进行散列。

Read more »

ArrayList 源码分析

Posted on 2018-01-02 Edited on 2020-03-18 In Java

Resizable-array implementation of the List interface. Implements all optional list operations, and permits all elements, including null. In addition to implementing the List interface, this class provides methods to manipulate the size of the array that is used internally to store the list. (This class is roughly equivalent to Vector, except that it is unsynchronized.)

DocumentationJava Platform SE 8

这篇 note 介绍一下 Java 集合框架中的 ArrayList,并从源码的角度分析其扩容机制、迭代方法和序列化等内容。

ArrayList 简介

想要深入学习某个 class,还是要看其源码。我这里使用 IntelliJ IDEA 这一款出色的 IDE 来研究 ArrayList。

ArrayList 是一个动态数组,它继承自 AbstractList 这个抽象类,并实现了 List、RandomAccess、Cloneable 以及 Serializable 接口。

1
2
public class ArrayList<E> extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, java.io.Serializable

为了避免对链表的随机访问操作,Java SE 1.4 引入了一个标记接口 RandomAccess。这个接口不包含任何方法,不过可以用它来测试一个特定的集合是否支持高效的随机访问。显然,ArrayList 支持。

1
2
3
4
5
if (list instanceof RandomAccess) {
// use random access algorithm
} else {
// use sequential access algorithm
}
Read more »

Hexo + GitHub Pages 搭建个人博客

Posted on 2017-12-15 Edited on 2019-10-15 In Tools

Hexo is a fast, simple and powerful blog framework. You write posts in Markdown (or other languages) and Hexo generates static files with a beautiful theme in seconds.

Documentationhexo.io

这一篇 note 讲解如何使用 Hexo + Github Pages 搭建个人博客,并用 GitHub 进行版本控制。其中源文件位于 hexo 分支,静态文件位于 master 分支。

准备

  • 安装最新版的 Git。在命令行输入 git version 检查 git 是否安装成功。

  • 安装 LTS 版的 Node.js。同样在命令行输入 node -v 和 npm -v以检查 node.js 是否安装成功。

  • 注册 GitHub 账号,新建一个 repository,一般命名为 username.github.io,这样 GitHub 会自动开启 GitHub Pages 功能。勾选 Initialize this repository with a README 的话即可访问个人主页,否则需要添加内容才能访问,建议暂时不要勾选。

  • GitHub 添加 SSH(推荐),可参考 Connecting to GitHub with SSH。

Read more »

Markdown 语法

Posted on 2017-12-05 Edited on 2019-10-15 In Tools

Markdown is a lightweight markup language with plain text formatting syntax. It is designed so that it can be converted to HTML and many other formats using a tool by the same name.

WikipediaMarkdown

最近在学习如何使用 Hexo + Github Pages 搭建个人博客(其实是学习笔记)。Hexo 是使用 Markdown 解析文章,而自己还没怎么接触过 Markdown 的语法,于是,就有了这第一篇 note。

Windows 上可选择 MarkdownPad 编辑器,不过我使用的是 Visual Studio Code,配合 Markdownlint 插件,感觉还不错!

标题

# 一级标题
## 二级标题
### 三级标题
#### 四级标题
##### 五级标题
###### 六级标题
一级标题和二级标题还有一种写法,不推荐使用:
Alt-H1
======(长度随意,下同)
Alt-H2
------

一些规则:比如标题不能跨级,标题上下要有空行等等,具体可参考 Markdownlint Rules。

Read more »
12

Muwednesday

16 posts
4 categories
11 tags
GitHub E-Mail
© 2020 Muwednesday
Powered by Hexo v3.9.0
|
Theme – NexT.Gemini v7.2.0
|