自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(92)
  • 资源 (1)
  • 收藏
  • 关注

原创 Socket编程

本文主要内容参考自此处,如有兴趣可自行查看(英文版),这里是本人对于该部分内容的理解和总结。1. 关于Socket通信Q1: socket是什么,该怎么理解? A1:这里引用JLS定义 java.net.Socket This class implements client sockets (also called just “sockets”). A socket is an en

2017-09-02 11:07:34 316

原创 实现最小栈

1. 要求 及思路 实现一个最小栈,主要实现包括以下方法,且满足操作的时间复杂度为O(1): void push(E val): 压入一个元素; E pop():从栈中弹出一个元素; E top():返回栈顶元素; E min():返回栈中最小元素;思路:这里考虑用2个栈实现,用内存换取效率。 其中一个栈用来存当前容器中的最小值;另一个栈用来存所有元素。2. Ja

2017-08-29 20:02:30 575

原创 工厂设计模式

1. 什么是工厂设计模式?本文部分内容参考自这2个地址,包括这里及这里,如有兴趣可自行前往查看。 Factory design pattern is used when we have a super class with multiple sub-classes and based on input, we need to return one of the sub-class. This p

2017-08-29 10:11:41 396

原创 Multi-Programming-17 Semaphore & CountDownLatch信号量和计数栓之间的关系

1. 信号量与计数栓Semaphore & CountdownLatch关于该问题的Q&A主要来自此处,可以自行查看。 信号量:Semaphore is used to control the number of concurrent threads that are using a resource. That resource can be something like a file, or

2017-08-27 18:40:11 451

原创 Multi-Programming-16 线程死锁实现方式

1. 简单实现:使用synchronized方法 Mutual exclusion:互斥访问 Hold and wait:拥有等待 Non-emptive:不可剥夺 Circular waiting:循环等待 package com.fqyuan._11deadlock;public class DeadLockOri { private static Objec

2017-08-27 15:16:58 282

原创 Multi-Programming-15 线程顺序执行

1. 问题 Q:假设有三个线程,假设为t1, t2, t3, 如何保证线程的顺序执行t1->t2->t3? A:首先,java语言多线程机制并没有执行顺序的属性;其次,设置线程的优先级并不能确保线程的准确执行顺序。所以,这里需要采用其他方式保证执行了。 本文提供了三种解决方式: 1). ReentrantLock: 重入锁方案。 2). Condition: 类似于wai

2017-08-27 12:19:34 362

原创 Comparable接口和Comparator接口

1. 关于2个接口文档说明1). Comparable: 实现了该接口的类可以直接进行排序,在调用Collections静态方法进行排序时无需指定Comparator, 因为实现了该类的对象本身是可比较的。 需实现方法:public int compareTo(Object o){} This interface imposes a total ordering on the obj

2017-08-23 11:33:34 222

原创 线程安全的单例模式

1. 单例模式这里有单例模式的wiki定义: In software engineering, the singleton pattern is a software design pattern that restricts the instantiation of a class to one object. This is useful when exactly one object is

2017-08-23 10:05:54 207

原创 数据结构--队列实现栈&栈实现队列

1. 两个栈实现栈 1.这里使用的是ArrayDequeue, 而不是使用Stack,因为Stack 集合是在Java Collection Framework被淘汰的集合。 2. 这里push操作增加的元素放在stack1中; 3. 这里pop操作作用集合为stack2, 如果stack2为空,则将stack1中元素push到stack2中,然后再stack2进行pop()操作。

2017-08-21 15:45:36 392

原创 10种排序算法总结

这里把常见的排序算法做个总结,包括 1). SelectSort–选择排序 2). InsertSort–插入排序 3). BubbleSort–冒泡排序 4). ShellSort–希尔排序 5). MergeSort–归并排序 6). QuickSort–快速排序 7). HeapSort–堆排序 8). CountSort–计数排序 9).

2017-08-17 10:54:20 360 1

原创 Algorithm-Arrays-8 Noble Integer

1. 题目描述 Given an integer array, find if an integer p exists in the array such that the number of integers greater than p in the array equals to p If such an integer is found return 1 else return

2017-08-13 11:48:49 254

原创 Algorithm-Arrays-7 Diagonals 对角线输出

1. 题目 Give a N*N square matrix, return an array of its anti-diagonals. Look at the example for more details. Example: Input: 1 2 3 4 5 6 7 8 9 Return the following :

2017-08-13 11:17:07 205

原创 Algorithm-Arrays-6 Kth pascal triangle

1. 题目: Kth Row of Pascal’s Triangle此处有关于该问题的类似解法。 Given an index k, return the kth row of the Pascal’s triangle. Pascal’s triangle : To generate A[C] in row R, sum up A’[C] and A’[C-1] from prev

2017-08-13 09:50:40 174

原创 关于Java中HashMap相关总结

1. 关于该问题的一些导入问题1.Immutable 和 final之间有什么不同? A: 关于该问题在StackOverflow上有相关解答,这里做了总结.//OkString name = "John";name = "Sam"; //Ok.//Errorfinal String name = "John";name = "Sam"; //Compile error fin

2017-07-31 17:40:13 396

原创 封装类为何是immutable 不可改变的

1. 问题引入demopackage com.fqyuan.Wrapper;import java.util.concurrent.atomic.AtomicInteger;public class TestWrapper { public static void main(String[] args) { Foo f1 = new Foo(); Foo f2

2017-07-31 11:13:38 596

原创 为何String对象是immutable或final的?

1. 问题引入本文内容主要参考自此处,感兴趣者可以自行移步查看。 另,StackOverflow上也有关于该问题的回答,这里贴出部分答案。 String is immutable for several reasons, here is a summary: Security: parameters are typically represented as String in

2017-07-31 10:33:19 308

原创 单例模式下的双重检验锁Double Checked Locking

1. 双重检验锁该部分内容引自维基百科。package com.fqyuan.con_singleton;public class SingletonClass { private static volatile SingletonClass INSTANCE; //private constructor. private SingletonClass() { }

2017-07-30 21:50:44 421

原创 为何Java 类不支持多继承?

1.问题由来本文部分内容引自此处,感兴趣者可以直接查看原链接。 Java语言特性之一是, 确切的说,其类对于多继承是不支持的(接口可以多继承),但是这是为什么呢?记得Thinking in Java中对于该问题有所阐述,单继承时,JVM的GC机制很好实现,有没有其他更深层次的原因呢?2.问题解释 A foo() / \ / \ B foo() C

2017-07-30 16:59:02 2845

原创 哲学家就餐问题 Java语言实现

1. 哲学家就餐问题描述本文部分内容来源于此,欲了解详细内容,自行点击查看。 为了不失一般性,我们假设有n个哲学家,围着餐桌思考宇宙、人生问题,每个哲学家面前有一个叉子与之对应,即:共有n个叉子;当哲学家思考一段时间后,他会拿起身边的2个叉子才能进食。进食完毕后,该哲学家放下叉子,继续思考人生、宇宙,如此往复,周而复始。2. 解决方案 在解决该类问题时,属于竞争资源情形,假设所有哲学家均同

2017-07-30 13:09:01 1920 1

原创 Data Structure-7 HashTable 哈希表

1. 哈希表部分理论内容参考自这里。 Hash Table is a data structure which stores data in an associative manner. In a hash table, data is stored in an array format, where each data value has its own unique index value.

2017-07-29 12:07:49 306

原创 搜索算法--线性搜索、二分搜索、内插搜索、剪枝搜索

线性搜索 二分搜索 内插搜索 剪枝搜索

2017-07-28 20:59:52 1580

原创 Shell排序和插入排序

Shell排序算法本人部分理论内容参考自这里,感兴趣者可以直接在此处查看。 Shell sort is a sorting algorithm that requires asymptotically fewer than O(n²) comparisons and exchanges in the worst case. Although it is easy to devel

2017-07-27 15:04:29 275

原创 简单排序算法总结

1. 选择排序、插入排序、冒泡排序选择排序 The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the beginning. The al

2017-07-27 11:12:16 195

原创 Data structure-6 红黑树(BlackRedTree)插入操作

1. 红黑树吐槽 在整理之前学过的数据结构知识(主要是应对找工作)时候,动手实现了栈、队列、单链表、双链表、二叉搜索树,上述列举的这些基础的数据结构实现起来还是挺简单的,稍微思考一下即可完成常见的insert/delete/search/traverse操作。 我承认,在红黑树的时候我遇到障碍了,大概花了一天的时间完成了这个版本的红黑树插入操作的代码。后来我反思了一下,之所以这样可能

2017-07-26 21:50:20 223

原创 Data structure-5 二叉搜索树 BST--Java语言实现

BST简介本文部分内容参考自此处。 Binary Tree : A data struc­ture in which we have nodes con­tain­ing data and two ref­er­ences to other nodes, one on the left and one on the right. Binary Tree con­sist of N

2017-07-22 13:04:14 399

原创 Data structure-4 双向链表 DoubleLinkedList--Java语言实现

1. 双向链表简介 Doubly Linked List is a variation of Linked list in which navigation is possible in both ways, either forward and backward easily as compared to Single Linked List. Following are the import

2017-07-21 10:05:11 2268

原创 Data structure-3 单链表LinkedList--Java语言实现

1. 链表特点 One disadvantage of using arrays to store data is that arrays are static structures and therefore cannot be easily extended or reduced to fit the data set. Arrays are also expensive to mainta

2017-07-20 20:53:55 324

原创 Data Structure-2 Queue 循环队列,用数组实现

1. 队列基础 Queue. A queue supports the insert and remove operations using a first-in first-out (FIFO) discipline. By convention, we name the queue insert operation enqueue and the remove operation deque

2017-07-20 09:18:56 354

原创 Datasture-1 Stack--用Java实现

1. 简单介绍 栈stack:是一种实现了后进先出的数据结构,LIFO(last in first out), 典型的方法是push()和pop()压栈和弹栈。2. 代码实现//Stack.javapackage com.fqyuan.stack;import java.lang.reflect.Array;public class Stack<T> { private int si

2017-07-19 15:34:17 229

原创 Algorithm-Arrays-5 Repeat and Missing Number Array

1. 问题 You are given a read only array of n integers from 1 to n. Each integer appears exactly once except A which appears twice and B which is missing. Return A and B. Note: Your al

2017-07-17 19:24:51 203

原创 Algorithm-Arrays-4 最大绝对距离Max Absolute Difference

1. 问题描述 You are given an array of N integers, A1, A2 ,…, AN. Return maximum value of f(i, j) for all 1 ≤ i, j ≤ N. f(i, j) is defined as |A[i] - A[j]| + |i - j|, where |x| denotes absolute value o

2017-07-17 16:56:03 494

原创 Thinking in java-39 序列化 Serialization

1. 对象序列化的意义本文详细内容参考自java_T_point && tutorialspoint. Java语言中的序列化:将对象状态写入字节流中的机制。 对象可以用一组包含该对象数据和信息(包含对象的类型、存储在对象中的数据)的字节所表示。在序列化对象写入到文件之后,该对象可以从文件中读出,并进行反向的解序列化过程。也就是说,类型信息、代表该对象的字节信息及相关数据可以用来在内存中重建

2017-07-17 10:38:11 248

原创 Thinking in java-38 Java 泛型Generics in java

1. Generics 泛型引入泛型是在Java 5 之后引入到java 语言中的,其目的是为了提供编译时类型检查,减少ClassCastException异常风险。容器参数化能力是当初Generic引入的一个主要动力,它将运行时异常ClassCastException在编译时就强制检查,如果类型不匹配将抛出一个编译时错误。2. Generic Class泛型类我们可以定义泛型类。泛型类型是一种具

2017-07-16 21:52:26 328

原创 Thinking in java-37 类加载器与RTTI

RTTI  ClassLoader Reflection

2017-07-16 12:12:32 191

原创 策略设计模式 Strategy Design Pattern

1. 策略设计模式初衷减少代码冗余,降低代码之间的耦合度。同时保证代码的可维护性。 Positive: - Often reduces long lists of conditions - Avoid duplicate code - Keep class changes from other class changes - Can hide complicated/ secret

2017-07-11 13:43:03 350

原创 Thinking in java-36 Regular expression正则表达式

1. 什么是正则表达式?部分内容整理自此,了解详细内容可以查看此处。 正则表达式定义了一种字符串查找的模式。 这种字符串search pattern可以是最简单的单字符、某个固定的字符串或者是某种特殊模式的复杂的表达式。 所以我们可以这样说:如果一个字符串符合了regular expression的模式,那么他就和我所要找的内容相匹配。(If a string has these things

2017-07-09 22:48:15 482

原创 Thinking in java-35 String 字符串

1. immutable不可改变特性String类对象都是不可修改的。如果我们去查阅JDK文档关于String类的信息,我们将发现所有看起来修改了String内容的方法其实是返回了一个全新的对象包含了这部分修改内容。原始的String字符串依然保持原封不动,未做过任何修改。这种设定保证了的代码很容易写,而且易于被人理解。 Objects of the String class are imm

2017-07-08 14:26:13 200

原创 Thinking in java-34 Exception异常处理

关于异常Exception引入异常处理的初衷:The basic philosophy of java is that ‘badly formed code will not be run! 在引入异常处理机制之前,我们一般是通过设置flag或者某些值的方式来判定某些组件是否有错的。 但是,许多年过去后,几乎所有程序猿都自命不凡,认为自己写的代码无可挑剔–“Yes, errors ma

2017-06-28 22:11:14 275

原创 Thinking in java-33 Collection & Map

Collection & Map 图示图示中,虚线包围的是interface,实线所包围的是具体的容器类。Comparable:对应于给定类对应元素实现int comparaTo(Object obj)。Comparator:Comparator对应的是int comparable(Object obj1, Object obj2)在使用Collections.sort(Collecti

2017-06-28 09:54:32 162

原创 Thinking in java-32 Iterable & Iterator Inteface

1. java中的Iterable & Iterator?Q1: What are the difference between Iterator VS Iterable? A1: The “Iterable” was introduced to be able to use in the ‘foreach’ loop. A class implementing the Iterable inte

2017-06-27 11:32:04 373

用户管理系统

韩顺平老师细说jsp中用户管理系统的完善版本,使用了JSP/Servlet分层设计技术,是理解MVC的简单案例,有问题请联系[email protected]

2016-06-02

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除