- 博客(37)
- 资源 (4)
- 收藏
- 关注
原创 使用JAVA编程实现多人聊天室(多线程实践)
程序可以实现多人聊天,并且效果和性能还算可以。而且每个客户端连接进服务器时,都会随机产生一个随机数作为自身的标志,避免通话过程中,分辨不清彼此,而导致交流效果不好。测试过程中一共连入了10个客户端进行程序稳定性的测试,程序运行结果稳定,符合实验预期结果,充分说明了程序的鲁棒性较强。
2017-11-30 19:19:59 33965 35
原创 Java多线程同步程序
编写一个Java 多线程程序,完成三个售票窗口同时出售20张票(如下图所示) 程序分析: 1.票数要使用同一个静态值; 2.为保证不会出现卖出同一个票数,要java多线程同步锁。 设计思路: 1.创建一个站台类Station,继承Thread,重写run方法,在run方法里面执行售票操作!售票要使用同步锁:即有一个站台卖这张票时,其他站台要等这张票卖完! 2.创建主方法调用类 程序源代
2017-11-30 19:10:23 454
原创 Java基础知识
说一下”==”和equals方法究竟有什么区别?非常经典的一个面试题?先说清楚一个,再来说另一个? ==用来判断两个变量之间的的值是否相等。变量就可以分为基本数据类型变量,引用类型。 如果是基本数据类型的变量直接比较值而引用类型要比较对应的引用的内存的首地址。 equals 用来比较两个对象长得是否一样。判断两个对象的某些特征是否一样。实际上就是调用对象的equals方法进行比较。
2017-11-30 20:03:44 155
转载 Java基础知识
简单讲一下java的跨平台原理由于各操作系统(windows,liunx等)支持的指令集,不是完全一致的。就会让我们的程序在不同的操作系统上要执行不同程序代码。Java开发了适用于不同操作系统及位数的java虚拟机来屏蔽个系统之间的差异,提供统一的接口。对于我们java开发者而言,你只需要在不同的系统上安装对应的不同java虚拟机、这时你的java程序只要遵循java规范,就可以在所有的操作系统上
2017-11-29 21:13:08 155
原创 int类型数组压缩为char类型数组存储
本文以C++语言实现int数组压缩存储以及解压缩取出的例子。 原理:int类型数占16位,char类型占8位。int转为char默认保留低八位。#include<iostream>using namespace std;#include<cstdlib>#include<ctime>void pack(int a[], unsigned char b[], int n);void
2017-11-28 20:53:42 1704
原创 分布式系统
Zookeeper让服务配置变得更简单 zookeeper是Hadoop下的一个子项目,它是一个针对大型分布式系统的可靠的协调系统,提供的功能包括:配置维护、名字服务、分布式同步、组服务等。zookeeper是可以集群复制的,集群间通过Zab(Zookeeper Atomic Broadcast)协议来保持数据的一致性。 基于zookeeper的持久和非持久节点,我们能够近乎实时的感知到后端服务
2017-11-27 21:49:57 217
原创 JVM知识点总结
JVM运行流程JVM基本结构 Class File->ClassLoader->运行时数据区->执行引擎,本地库接口->本地方法库 类的装载先执行public static int tmp=1; 然后再执行static块,初始化Demo成功后,再执行main()函数先执行static块; 再执行public static int tmp=1;
2017-11-27 13:37:11 178
原创 ssh无密登录机制
HDFS实现分布式集群系统免密登录步骤: 配置ssh免登陆 #生成ssh免登陆密钥 #进入到我的home目录 cd ~/.ssh ssh-keygen -t rsa (四个回车) 执行完这个命令后,会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥) 将公钥拷贝到要免登陆的机器上 ssh-copy-id localh
2017-11-24 00:21:12 237
原创 HDFS原理及应用场景设想
Hadoop 实现了一个分布式文件系统(Hadoop Distributed File System),简称HDFS。 Hadoop是Apache Lucene创始人Doug Cutting开发的使用广泛的文本搜索库。它起源于Apache Nutch,后者是一个开源的网络搜索引擎,本身也是Luene项目的一部分。Aapche Hadoop架构是MapReduce算法的一种开源应用,是Google开创
2017-11-23 23:09:31 303
原创 Spring技术内幕2
BeanFactory和ApplicationContext都可以看成是容器(IoC)的具体表现形式。 IoC容器的接口设计图 BeanDefinition BeanFactory接口定义 XmlBeanFactory设计的类继承关系 XMLBeanFactory继承自DefaultListableBeanFactory这个类(IoC容器的实现),实际上包含了基本IoC
2017-11-23 23:06:19 217
原创 Spring技术内幕1
Spring Framework(Core):这是我们熟知的Spring项目的核心。 Spring BlazeDS Integration、Spring Security(Acegi)、Spring Security OAuth、Spring Dynamic Modules、Spring Batch、Spring Integration、Spring AMQP、Spring.NET。
2017-11-21 21:52:57 426
原创 JVM运行机制
JVM的启动流程 JVM的基本结构 PC寄存器 方法区 Java堆 Java栈 操作数栈 Java没有寄存器,所有参数传递使用操作数栈。 C++的堆上分配和栈上分配的比较 Java栈上分配的好处 栈堆方法区 可见性
2017-11-18 23:40:16 153
原创 学习笔记
1、System.out.println(015)的结果是13。 2、一个数组中能够存储不同类型的数据。(可以,eg:Object object = new Object()。 3、在Java的基本数据类型中,char型采用Unicode编码方案,每个Unicode码占用2字节内存空间,这样,无论是中文字符还是英文字符,都是占用2字节内存空间。 4、spring提供了AOP方式的日志系统。
2017-11-18 15:58:49 176
原创 像素翻转Java实现
有一副由NxN矩阵表示的图像,这里每个像素用一个int表示,请编写一个算法,在不占用额外内存空间的情况下(即不使用缓存矩阵),将图像顺时针旋转90度。 给定一个NxN的矩阵,和矩阵的阶数N,请返回旋转后的NxN矩阵,保证N小于等于500,图像元素小于等于256。 测试样例: [[1,2,3],[4,5,6],[7,8,9]],3 返回:[[7,4,1],[8,5,2],[9,
2017-11-08 13:29:30 214
原创 基本字符串压缩Java实现
利用字符重复出现的次数,编写一个方法,实现基本的字符串压缩功能。比如,字符串“aabcccccaaa”经压缩会变成“a2b1c5a3”。若压缩后的字符串没有变短,则返回原先的字符串。 给定一个string iniString为待压缩的串(长度小于等于10000),保证串内字符均由大小写英文字母组成,返回一个string,为所求的压缩后或未变化的串。 测试样例 “aabcccccaa
2017-11-08 13:16:39 8069 4
原创 空格替换Java实现
请编写一个方法,将字符串中的空格全部替换为“%20”。假定该字符串有足够的空间存放新增的字符,并且知道字符串的真实长度(小于等于1000),同时保证字符串由大小写的英文字母组成。 给定一个string iniString 为原始的串,以及串的长度 int len, 返回替换后的string。 测试样例: “Mr John Smith”,13 返回:”Mr%20John%20S
2017-11-07 13:09:16 245
原创 确定两串乱序同构Java实现
给定两个字符串,请编写程序,确定其中一个字符串的字符重新排列后,能否变成另一个字符串。这里规定大小写为不同字符,且考虑字符串重点空格。 给定一个string stringA和一个string stringB,请返回一个bool,代表两串是否重新排列后可相同。保证两串的长度都小于等于5000。 测试样例: “This is nowcoder”,”is This nowcoder”
2017-11-07 12:28:36 272
原创 原串翻转Java实现
请实现一个算法,在不使用额外数据结构和储存空间的情况下,翻转一个给定的字符串(可以使用单个过程变量)。 给定一个string iniString,请返回一个string,为翻转后的字符串。保证字符串的长度小于等于5000。 测试样例: “This is nowcoder” 返回:”redocwon si sihT”import java.util.*;public clas
2017-11-06 14:05:56 257
原创 确定字符互异Java实现
请实现一个算法,确定一个字符串的所有字符是否全都不同。这里我们要求不允许使用额外的存储结构。 给定一个string iniString,请返回一个bool值,True代表所有字符全都不同,False代表存在相同的字符。保证字符串中的字符为ASCII字符。字符串的长度小于等于3000。 测试样例: “aeiou” 返回:True “BarackObama” 返回:F
2017-11-06 13:50:03 258
原创 remove-duplicates-from-sorted-list Java code
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given1->2->3->3->4->4->5, return1->2->5. Given1->1-
2017-11-05 10:12:19 175
原创 largest-rectangle-in-histogram Java code
Given n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram where width of each
2017-11-05 10:05:55 282
原创 maximal-rectangle Java code
Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing all ones and return its area.import java.io.*;import java.util.*;public class Solution { public int maxima
2017-11-05 09:50:36 318
原创 partition-list Java code
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of
2017-11-04 12:52:07 175
原创 scramble-string Java code
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 =”great”: great / \
2017-11-04 12:45:00 238
原创 merge-sorted-array Java code
Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A has enough space to hold additional elements from B. The number of elements initialized i
2017-11-04 12:05:30 204
原创 gray-code Java code
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of g
2017-11-03 11:28:26 193
原创 decode-ways Java code
A message containing letters fromA-Zis being encoded to numbers using the following mapping: ‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -> 26 Given an encoded message containing digits, determine the total
2017-11-03 11:10:00 245
原创 reverse-linked-list Java code
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given1->2->3->4->5->NULL, m = 2 and n = 4, return1->4->3->2->5->NULL. Note: Given m, n satisfy t
2017-11-02 21:39:45 213
原创 restore-ip-addresses Java code
Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example: Given”25525511135”, return[“255.255.11.135”, “255.255.111.35”]. (Order d
2017-11-02 21:03:49 183
原创 binary-tree-inorder-traversal Java code
Given a binary tree, return the inorder traversal of its nodes’ values. For example: Given binary tree{1,#,2,3}, 1 \ 2 / 3 return[1,3,2]. Note: Recursive s
2017-11-01 13:29:06 152
原创 unique-binary-search-trees Java code
Given n, how many structurally unique BST’s (binary search trees) that store values 1…n? For example, Given n = 3, there are a total of 5 unique BST’s. 1 3 3 2 1
2017-11-01 13:23:56 169
原创 unique-binary-search-trees Java code
Given n, generate all structurally unique BST’s (binary search trees) that store values 1…n. For example, Given n = 3, your program should return all 5 unique BST’s shown below. 1 3
2017-11-01 12:39:31 153
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人