- 博客(19)
- 收藏
- 关注
转载 HashMap的实现原理
HashMap的实现原理参考文献引用文献:深入Java集合学习系列:HashMap的实现原理,大部分参考这篇博客,只对其中进行稍微修改自己曾经写过的:Hashmap实现原理1. HashMap概述: HashMap是基于哈希表的Map接口的非同步实现(Hashtable跟HashMap很像,唯一的区别是Hashtalbe中的方法是线程安全的,也就是同步
2016-02-28 17:49:34 673
原创 为什么jdk中把String类设计成final?
为什么jdk中把String类设计成final?个人认为有以下原因基于效率和安全这两点。效率1:因为String类被频繁的使用,申明为final可以提高程序的性能2:如果一个类申明为final的,那么它所有的方法都是final的,jvm编译的时候会寻找机会内联那些final的方法,可以提高效率安全1:防止String内被继承,和重写里面的方法2:因为java
2016-02-28 17:09:58 523
原创 (java)Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin
2016-02-24 00:52:12 231
原创 (java)Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?思路:本题的题意就是把一个n*n的矩阵,顺时针转90度,先关于主对角线交换,再将列对称交换比如
2016-02-24 00:35:21 1411
原创 (java)Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right whichminimizes the sum of all numbers along its path.Note: You can only move either down or right at
2016-02-24 00:25:32 375
原创 JVM学习笔记5—类加载器(classloader)
class装载验证流程1 加载· 取得类的二进制流,转为方法区数据结构,在堆中生成相应的java.lang.Class对象2 链接(1)验证(文件格式验证,元数据验证,字节码验证,符号引用验证)保证Claas流的格式是正确的,防止被恶意替换(2)准备分配内存,并为类设置初始值(在方法区中)注意 public static int a=1,在准备阶段,v=0,而不是1
2016-02-24 00:15:42 462
原创 JVM学习笔记4—GC参数
堆的回顾三种收集器1 串行收集器最古老,最稳定,效率高缺点:可能产生较长的停顿-XX:+UseSerialGC-------新生代,老年代使用串行回收-------新生代复制算法(因为新生代对象少)-------老年代标记-压缩(老年代对象多)2 并行收集器注意:并行不一定快!(1) ParNew --- -XX:+UseParNewGC
2016-02-23 00:58:02 740
原创 JVM学习笔记3—GC算法
GC的对象是堆空间与永久区,只要是对老年代进行操作GC算法种类1 引用计数法:思想:就是对对象进行引用计数,引用一次改对象的计数器就加1,减少一次引用该对象的计数器就减1,当该对象的引用计数器等于0的时候,垃圾收集器就将其回收缺陷:当根对象取消引用时,由于存在循环引用,GC无法回收2 标记清除法:思想:GC做清理分两步:1 先扫描,将被引用的标记 2 清理未标记的
2016-02-23 00:25:34 378
原创 JVM学习笔记2—常用JVM配置参数
Trace跟踪参数-XX:printGC 打印GC的简要信息-Xloggc:log/gc.log--- 指定GC log的位置,以文件输出--- 帮助开发人员分析问题-XX:+TraceClassLoading 监控类的加载堆的分配参数-Xmx 指定最大堆-Xms 指定最小堆优先装在最小堆,如果最小堆放不下,拓展最小堆,但是上限是最大堆-
2016-02-21 23:32:36 713
原创 JVM学习笔记1—JVM运行机制
JVM的基本结构对于PC寄存器有个注意点,当执行本地方法时,pc的值为undefined方法区保存类的信息java堆对象保存在堆中,new 出来的,是gc的主要工作区间java栈线程独有的栈由一系列帧组成,栈只进行帧的入栈出栈操作栈保存一个方法的局部变量,操作数栈,常量指针每一次的方法调用都进行一次要栈操作局部变量表包含参
2016-02-20 21:38:20 428
原创 (java) Bulb Switcher
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off
2016-02-17 00:48:55 465
原创 (java) Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O
2016-02-17 00:42:17 269
原创 (java) Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.思路,就是实现除法操作。注意点:1 除数为0 2 存在负数且是最小的负数这两种情况要特殊处理,其实除法就是用加法来实现的。普通
2016-02-17 00:02:01 505
原创 (java) Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the
2016-02-16 23:19:26 261
原创 (java) Pow(x, n)
Implement pow(x, n).思路:当n是正数时 当n是偶数等于half*half 当n是奇数时等于half*half*x;当n是负数时,处理成正数,用1除就行了,注意边界当n等于Integer.MINVALUE时要特殊处理代码如下(已通过leetcode)public class Solution { public double myPow(double x,
2016-02-16 22:41:23 506
原创 (java) Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.
2016-02-16 22:33:00 302
原创 (java) Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.思路:调用库函数math.sqrt代码如下(已通过leetcode)public class Solution { public int mySqrt(int x) { return (int)Math.sqrt(x)
2016-02-16 22:18:22 486
原创 (java) Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found
2016-02-16 22:07:45 318
原创 (java) Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each
2016-02-16 21:46:24 323
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人