java 编程细节 1.long 与Long 的instance of的关系:直接报错,说明不是一个继承类型的。2. double类型除法的问题:可以除,且返回值为double 3.关于new Long 与 Long.valueOf()的区别这个问题可以通过阅读源码来解决: 通过源码可以发现,使用valueof更具有效率的原因在于 java JDK提供一种类似线程池的cache...
Java lambda表达式实例解析 首先我们来看一下具体的实例: List<String> t = new ArrayList(); t.add("01A"); t.add("02D"); t.add("03C"); t.add("01A"); List<String>filleNames = t.stream().map(s -&
关于java异常e.toString是否存在安全泄露的问题 1.首先我们依旧看下e.toString()的API官方文档e.toString 的是否存在安全泄露的问题 String java.lang.Throwable.toString()Returns a short description of this throwable. The result is the concatenation of:the name of the cla...
JAVA Pattern.matches的使用 1.首先阅读Pattern.matches的API:boolean java.util.regex.Pattern.matches(String regex, CharSequence input)Compiles the given regular expression and attempts to match the given input against it. An in...
高级语言的编译:链接及装载过程介绍 ###引言随着越来越多功能强大的高级语言的出现,在服务器计算能力不是瓶颈的条件下,很多同学会选择开发效率高,功能强大的虚拟机支持的高级语言(Java),或者脚本语言(Python,Php)作为实现功能的首选,而不会选择开发效率低,而运行效率高的 C/C++ 作为开发语言。而这些语言一般情况下是运行在虚拟机或者解释器中,而不需要直接跟操作系统直接打交道。虚拟机和解释器相当于为高级语言或者
Linux Socket编程(不限Linux) Select在Socket编程中还是比较重要的,可是对于初学Socket的人来说都不太爱用Select写程序,他们只是习惯写诸如connect、accept、recv或recvfrom这样的阻塞程序(所谓阻塞方式block,顾名思义,就是进程或是线程执行到这些函数时必须等待某个事件的发生,如果事件没有发生,进程或线程就被阻塞,函数不能立即返回)。可是使用Select就可以完成非阻塞(所谓非阻塞方式
sqlsever2005语句 IF EXISTS (select * from dbo.sysobjects where Name = 'stuMarks')drop table stuMarkscreate table stuMarks( id int identity(1,1) primary key, name char(20) not null,s
leetcode 字符串的所有的真子集 Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For examp
leetcode Given two words word1 and word2, find the minimum number of steps required to convertword1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word:
动态规划 Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s. For example, given s ="aab", Return1
C# 读写txt文档 在做项目的时候经常要修改配置,所以不免要读取文件:下面以读写字典为例,读写tex文件: private void savefile() { string path="F:\\ak.txt"; FileStream fs = new FileStream(path, FileMode.Create);
经典递归 Given a string s and a dictionary of words dict, add spaces ins to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example, givens ="ca
中介者模式 中介者模式:如果设计的类之间不彼此直接通信,就可以用中介者模式,可以降低类与类之间的耦合。1.首先有n个基础功能类,这些类依靠中介者彼此通信,所以,这些基础功能类与中介者是依赖关系,具体类后者基础功能类的基类有中介者对象。2.首先有一个抽象的中介者,作为基类。3.有一个具体的抽象者,由于基础功能类的通信依靠中介者,所以中介者必须认识所有的基础功能类,所以中介者与基础功能类是聚合关系。
C++11多线程编程 call_once call_once 可以使他所修饰的函数在多线程环境中只执行一次,call_once((once_falg)x,y),他接受一个once_falg变量参数,另一个参数可以使函数,lambda表达式等。上代码:#include #include#includeusing namespace std;once_flag t;void fun1(){ cout<<"i an
C++11 多线程编程 原子变量 利用atomic关键字,来控制变量在多线程中的同步。代码是学习语言最好的方式,上代码:#include #include#include#include#includeusing namespace std;void fun(atomic&counter){ for(int i=0;i<100;i++) { ++counter;
C++11 多线程编程---条件变量 C++11条件变量condition_variable配合mutex操作,利用mutex在保持互斥,利用条件变量的wait与notify函数来保持线程的等待与互斥。上代码:#include #include#include#include#includeusing namespace std;class A{public: bool isfull()const{ r
C++11 多线程编程 1.利用C++11线程函数创建线程,#include#includeusing namespace std;void fun(int i){ cout<<"i="<<i<<endl;}int main(){ for(int i=0;i<4;i++) { thread t(fun,i);//创建线程函数,参数为函数地址,与函数参数。对
命令模式 命令模式就是:发送命令者和命令收集者,命令收集者把命令传递给命令执行者。那么:1.首先有一个类,抽象命令类,他是命令的基类2.各种具体的命令类来继承基类,命令类函数参数是命令执行者。3.命令收集者类,这个类有一个命令基类的数组,此外还有2个命令方法:通知命令执行者执行命令,取消命令。4.命令执行者类,也称命令的接受者,去执行命令。现在看各类的关系:1.命令收集者
C++ 内存泄露 C++内存泄露主要发生在浅拷贝阶段:例如#include#include#include#includeusing namespace std;class A{private: char *m; size_t n;public: A(size_t n=1) { cout<<"i want to creat it"<<endl; m=new char[n];
C++11一些新特性 1.auto关键字,推断变量的类型。2.decltype,用于在编译器推断出表达式的类型。3.对于模板的改进,识别2个连续的>>括号。4.列表初始化,C++11 中的stl可以和未指定长度数组一样的初始化功能5.function函数包装,bing绑定函数6.lambda表达式1.右值引用T&&V;2.move语意