19年毕业,本科是软件工程,喜欢写作,小时候曾幻想以后写一本爆火的小说。大三开源 JavaGuide 并一直完善至今。
关于作者:
联系我:
「Java学习+面试指南」一份涵盖大部分 Java 程序员所需要掌握的核心知识。准备 Java 面试,首选 JavaGuide!
Home Page: https://javaguide.cn
License: Apache License 2.0
19年毕业,本科是软件工程,喜欢写作,小时候曾幻想以后写一本爆火的小说。大三开源 JavaGuide 并一直完善至今。
关于作者:
联系我:
如题。
面试必备/最最最常见的Java面试题总结/第一周(2018-8-7)里,
发现一个错别字:
加载进局部变量表弟一个slot中
在看Java集合框架源码的时候发现部分代码有细微差别,能麻烦注明一下Java的版本号吗?
看完操作系统的了,顺便看了下博客,为什么我 fork 会少了呢?
就会实现没过一秒自动刷新本页面一次
每
cat 命令是用来查看显示文件内容,是所有的内容并不是最后一屏内容
java中没有引用传递,只有值传递。作者最好改一下,以免误导新人。具体关于什么是引用传递,可以去复习下C语言的指针,对比着看。PS:java的引用不可简单的与C的指针划等号
对于ArrayList添加大量元素,最好调用ensureCapacity方法进行提前扩容,为啥不直接用有参构造方法呢,这个方法存在的意义在哪呢?
Hi! First of all, I just want to say that this is an amazing resource for learning Java. You have done a very good job.
I'm just wondering if an English version will ever be available? Or if translated versions of the pictures and diagrams would be available? I've currently been using Google translate and it works, but I'm just asking :)
Thank you for this!
大佬:
你若盛开 蝴蝶自来 表意 吸引
你若盛开 清风自来 吹落一地花片, 是要招恨么?
Here --> 面试必备/程序员的简历之道.md
Originally posted by @lovexi in #56 (comment)
感谢提供如此详尽的材料~
在 hasmmap源码分析这一节中,我觉得有几处不妥,请大佬们指教
内部结构分析-->JDK1.8之前--> JDK1.8之前HashMap底层是数组和链表结合在一起使用也就是链表散列。HashMap通过key的hashCode来计算hash值,当hashCode相同时,通过“拉链法”解决冲突。
这里我觉得表述不是很妥当,"HashMap通过key的hashCode来计算hash值,当hashCode相同时,通过“拉链法”解决冲突" hashmap 通过key的hashCode经过扰动函数处理过后得到hash值,当hash值相同时,通过拉链法解决冲突,不是hashCode相同时。因为不同的hashCode也可能扰动处理成相同的hash值。
下面一段:简单来说,JDK1.8之前HashMap由数组+链表组成的,数组是HashMap的主体,链表则是主要为了解决哈希冲突而存在的,如果定位到的数组位置不含链表(当前entry的next指向null),那么对于查找,添加等操作很快,仅需一次寻址即可;如果定位到的数组包含链表,对于添加操作,其时间复杂度依然为O(1),因为最新的Entry会插入链表头部,急需要简单改变引用链即可,而对于查找操作来讲,此时就需要遍历链表,然后通过key对象的equals方法逐一比对查找.
这里 "如果定位到的数组位置不含链表(当前entry的next指向null)" 括号里“当前entry的next指向null”描述不当,如下源码,for循环进入的条件是e!=null ,即判断数组有没有元素,只要有,就会开始链表的判断,不管链表有多长。
这里 "如果定位到的数组包含链表,对于添加操作,其时间复杂度依然为O(1)" 这个表述不太合理,因为不管插入,删除还是查询,都是先遍历一遍链表,所以复杂度应该是一样的。具体可以看下面的源码~~
public V put(K key, V value)
if (table == EMPTY_TABLE) {
inflateTable(threshold);
}
if (key == null)
return putForNullKey(value);
int hash = hash(key);
int i = indexFor(hash, table.length);
for (Entry<K,V> e = table[i]; e != null; e = e.next) { // 先遍历
Object k;
if (e.hash == hash && ((k = e.key) == key || key.equals(k))) {
V oldValue = e.value;
e.value = value;
e.recordAccess(this);
return oldValue;
}
}
modCount++;
addEntry(hash, key, value, i); // 再插入
return null;
}
再次感谢,希望不要把我当杠精~。~
在 搞定JVM垃圾回收就是这么简单 中 标记-清除法的描述为:
首先标记出所有需要回收的对象,在标记完成后统一回收所有被标记的对象
我在网上搜索了一些资料,有的写的是 标记可回收对象,有的写的是 标记不可回收对象。
之后找到一个issues可供参考:
参考维基百科里的说法:
The first stage is the mark stage which does a tree traversal of the entire 'root set' and marks each object that is pointed to by a root as being 'in-use'.
被标记的应为 在用(不可回收)对象
https://en.wikipedia.org/wiki/Tracing_garbage_collection#Na.C3.AFve_mark-and-sweep
在CMS收集器这部分内容中描述有前后矛盾的地方:
初始标记: 暂停所有的其他线程,并记录下直接与root相连的对象,速度很快 ;
并发标记: 同时开启GC和用户线程,用一个闭包结构去记录可达对象。但在这个阶段结束,这个闭包结构并不能保证包含当前所有的可达对象。因为用户线程可能会不断的更新引用域,所以GC线程无法保证可达性分析的实时性。所以这个算法里会跟踪记录这些发生引用更新的地方。
重新标记: 重新标记阶段就是为了修正并发标记期间因为用户程序继续运行而导致标记产生变动的那一部分对象的标记记录,这个阶段的停顿时间一般会比初始标记阶段的时间稍长,远远比并发标记阶段时间短
并发清除: 开启用户线程,同时GC线程开始对为标记的区域做清扫。
标记阶段对不可回收对象标记,在清除时对标记区域清扫。不就是把不可回收对象清除掉了?
A core knowledge that most Java programmers need to master https://github.com/Snailclimb/JavaGuide
请务必将这里改对
感觉看到基础问题无法表述完整,完全记不住啊
最后一行"fianl"应该为"final"
有了JVM的讲解,但是感觉对类的加载过程还是不是很清楚,希望能够整理一篇关于类加载的讲解。最后感谢作者们的贡献,谢谢。
Java基础知识18.4
原文:成员变量如果没有被赋初值,则会自动以类型的默认值而赋值(一种情况例外被 final 修饰但没有被 static 修饰的成员变量必须显示地赋值);而局部变量则不会自动赋值。
我试了一下 同时被final 和 static修饰的变量也需要被显示地赋值?这里是作者笔误吗?还是我理解的不对?
https://github.com/Snailclimb/JavaGuide/blob/master/Java%E7%9B%B8%E5%85%B3/Java%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86.md
在第8点字符型常量和字符串常量的区别中,字符似乎是占2个字节的空间。
最近做项目比较忙,提交次数变少了。大家如果有想法可以帮忙完善哦,我也会抽时间继续完善的!
你好:
/**
*默认构造函数,其默认初始容量为10
*/
public ArrayList() {
this.elementData = DEFAULTCAPACITY_EMPTY_ELEMENTDATA;
}
DEFAULTCAPACITY_EMPTY_ELEMENTDATA 为0
初始化为10,是在首次add() 的时候进行的
《这几道Java集合框架面试题几乎必问》中“ConcurrentHashMap 和 Hashtable 的区别”关于“默认分配16个Segment,比Hashtable效率提高16倍。”的疑问。
ConcurrentHashMap默认将hash表分为16个桶,诸如get、put、remove等常用操作只锁住当前需要用到的桶。这样,原来只能一个线程进入,现在却能同时有16个写线程执行,并发性能的提升是显而易见的。但此处并不能说效率就是提高了16倍。
ConcurrentHashMap是由Segment数组结构和HashEntry数组结构组成。Segment是一个可重入锁(ReentrantLock),在ConcurrentHashMap里扮演锁的角色;HashEntry则用于存储键值对数据。一个ConcurrentHashMap里包含一个Segment数组。Segment的结构和HashMap类似,是一种数组和链表结构。一个Segment里包含一个HashEntry数组,每个HashEntry是一个链表结构的元素,每个Segment守护着一个HashEntry数组里的元素。当对HashEntry数组的数据进行修改时,必须首先获得与它对应的segment锁。
因为一个Segment里包含一个HashEntry数组,故锁住一个Segment时即锁住了该Segment下的HashEntry数组。
详情参照 中文文案排版指北(简体中文版)
非常感谢。
Disclaimer: This is a bot
It looks like your repo is trending. The github_trending_videos Instgram account automatically shows the demo gifs of trending repos in Github.
Your README doesn't seem to have any demo gifs. Add one and the next time the parser runs it will pick it up and post it on its Instagram feed. If you don't want to just close this issue we won't bother you again.
// 当桶(bucket)上的结点数大于这个值时会转成红黑树
static final int TREEIFY_THRESHOLD = 8;
// 当桶(bucket)上的结点数小于这个值时树转链表
static final int UNTREEIFY_THRESHOLD = 6;
这两个值大神知道是什么依据吗?
像这种文章篇幅较长的集合,想用kindle来看,所以想用gitbook的导出mobi功能,建议同步到gitbook上
欢迎大家提建议啊~~~
一个好的开源文档的诞生一个人的努力肯定是不够的,所以在这里希望能有人帮忙一起完善。
Java相关/这几道Java集合框架面试题几乎必问.md
里的
ArraysList 底层是数组,而 LinkedList 底层是链表。数组天然支持随机访问,时间复杂度为 O(1),所以称为快速随机访问。实际上链表也是支持的,不过需要遍历到特定位置才行,时间复杂度为 O(n)。
这句,链表也是支持的, 如果理解为 支持快速随机访问,那么则是错误的。需要遍历的就不叫快速随机访问了
我能把你这些文章转载到我的微信公众号和我的博客https://www.ydstudio.net/上么?虽然我暂时还没有申请公众号
这个文章很不错:https://www.jianshu.com/p/790bbce5f127。
图文表达很清晰,对概念的把握和理解很准确,建议添加到开发方法类别中。
你好!FreeBSD 不是 Linux 发行版。望更正。谢谢!
本来不想看的, 不知怎么了看着看着就看的差不多,感觉挺好的,就加个星吧! 哈哈
345345345
https://github.com/Snailclimb/JavaGuide/blob/master/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/%E6%90%9E%E5%AE%9ABAT%E9%9D%A2%E8%AF%95%E2%80%94%E2%80%94%E5%87%A0%E9%81%93%E5%B8%B8%E8%A7%81%E7%9A%84%E5%AD%90%E7%AC%A6%E4%B8%B2%E7%AE%97%E6%B3%95%E9%A2%98.md
把字符串转换成整数如果传入的字符串没有 + 或者 - 号则 flag=0,那样会默认返回负数结果。
int flag = 0;
if (chars[0] == '+')
flag = 1;
else if (chars[0] == '-')
flag = 2;
return flag == 1 ? res : -res;
如 “123” flag = 0 返回 -123
try {
cyclicBarrier.await(2000, TimeUnit.MILLISECONDS);
} catch (Exception e) {
e.printStackTrace();
//System.out.println("-----CyclicBarrierException------");
}
前边创建线程的时候是Thread.sleep(1000);
, 这里等待2000ms, 会报错
java.util.concurrent.BrokenBarrierException
at java.base/java.util.concurrent.CyclicBarrier.dowait(CyclicBarrier.java:251)
at java.base/java.util.concurrent.CyclicBarrier.await(CyclicBarrier.java:436)
at CyclicBarrierExample1.test(CyclicBarrierExample1.java:44)
at CyclicBarrierExample1.lambda$main$0(CyclicBarrierExample1.java:30)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
java.util.concurrent.BrokenBarrierException
threadnum:1is finish at java.base/java.util.concurrent.CyclicBarrier.dowait(CyclicBarrier.java:251)
at java.base/java.util.concurrent.CyclicBarrier.await(CyclicBarrier.java:436)
at CyclicBarrierExample1.test(CyclicBarrierExample1.java:44)
at CyclicBarrierExample1.lambda$main$0(CyclicBarrierExample1.java:30)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
java.util.concurrent.TimeoutException threadnum:2is finish
at java.base/java.util.concurrent.CyclicBarrier.dowait(CyclicBarrier.java:258)
at java.base/java.util.concurrent.CyclicBarrier.await(CyclicBarrier.java:436)
at CyclicBarrierExample1.test(CyclicBarrierExample1.java:44)
at CyclicBarrierExample1.lambda$main$0(CyclicBarrierExample1.java:30)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
cyclicBarrier.await(2000, TimeUnit.MILLISECONDS);
timeout改多一点, 比如5000, 就不会报错了
在文中讲述hashcode和equals的部分,作者说hashcode是内存地址,这个说法是不准确的.在jdk中Object类的注释中说到,
As much as is reasonably practical, the hashCode method defined by
class {@code Object} does return distinct integers for distinct
objects. (This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the
Java™ programming language.)
hashcode是内存地址转成了int,转换的方法是其他语言实现的,不能直接说是内存地址
楼主觉得呢?
jdk1.8中
/** * Links e as last element. */ void linkLast(E e) { final Node<E> l = last; final Node<E> newNode = new Node<>(l, e, null); last = newNode; if (l == null) first = newNode; else l.next = newNode; size++; modCount++; }
newNode的next并没有指向first而是null
LinkBefore方法中还用pred == null来判断是否插入到第一个node
/** * Inserts element e before non-null Node succ. */ void linkBefore(E e, Node<E> succ) { // assert succ != null; final Node<E> pred = succ.prev; final Node<E> newNode = new Node<>(pred, e, succ); succ.prev = newNode; if (pred == null) first = newNode; else pred.next = newNode; size++; modCount++; }
所以没看出来循环
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.