Java唯一码生成 代码段

private static String beforeBh; private static String beforeNum; public static String codeGenerate() { Date now = new Date(); String behind = now.getTime()+""; if(beforeBh==null) { beforeBh = behind;

jopen 2015-11-14   1017   0
Java  

Properties属性文件操作Java工具类 代码段

public class PropsUtil { private static final Logger logger = LoggerFactory.getLogger(PropsUtil.class); private Properties props = null; public PropsUtil(String propsPath) { this(propsPath, Const.DEFA

peke 2016-01-06   2523   0
Java  

约瑟夫问题 java 实现 代码段

约瑟夫问题 这是17世纪的法国数学家加斯帕在《数目的游戏问题》中讲的一个故事:15个教徒和15 个非教徒在深海上遇险,必须将一半的人投入海中,其余的人才能幸免于难,于是想了一个办法:30个人围成一圆圈,从第一个人开始依次报数,数到第九个人就将他扔入大海。该人后面的人从1开始重新报数,如此循环进行直到仅余15个人为止。问怎样排法,才能使每次投入大海的都是非教徒。 思路 1. 先建立一个类,有 id

SylArmenta 2016-02-09   2458   0
Java  

通过Java NIO 实现文件下载 代码段

private void output(HttpServletResponse response, String filePathAndFileName, String mimeType) throws IOException { File file = new File(filePathAndFileName); // set response headers response.setConte

mcc 2015-02-05   5162   0
Java  

利用Java来压缩 JavaScript 代码 代码段

通过移除空行和注释来压缩 JavaScript 代码 /** * This file is part of the Echo Web Application Framework (hereinafter \"Echo\"). * Copyright (C) 2002-2009 NextApp, Inc. * * Compresses a String containing JavaScript b

wgd7 2015-03-14   2160   0
Java  

java快速排序算法代码 代码段

package Mypackage; public class QuickSort { public static void main(String[] args) { int[] arr = { 2, 5, 4, 3, 7, 0, 9, 1, 6, 8 }; quickSort(arr, 2, 7); for (int i = 0; i < arr.length; i++) System.out

pc688 2015-05-05   885   0
Java  

一些格式的Java工具类 代码段

public class FormatTools { /** * 判断邮箱 * * @param email * @return */ public static boolean isEmail(String email) { String str = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([

jopen 2015-06-02   942   0
Java  

java 定时备份数据库 代码段

/** 操作数据库 */ public class BackupDb { public String backup() throws IOException{ String user = "root"; //数据库的用户名 String password = "admin";//数据库的密码 String database = "hrtweb";//要备份的数据库名 Date date = new

jopen 2015-11-14   1975   1
Java  

Java版 微信红包算法 代码段

private double[] divide(double totalMoney,int num,double minMoney){ double[] each = new double[num]; for(int i=0;i<num-1;i++){ //计算最大安全值,保证不会超出 。如果安全值越大,价格波动越大 .建议是平均值 double maxSafeMoney = (totalMone

jopen 2015-12-10   1673   0
Java  

Java随机生成6位数字 代码段

public class T { /** * 随机生成 num位数字字符数组 * * @param num * @return */ public static char[] generateRandomArray(int num) { String chars = "0123456789"; char[] rands = new char[num]; for (int i = 0; i < nu

jopen 2015-12-18   1452   0

Java-- join源代码测试 代码段

public class JoinTest { public static void main(String[] args) { // TODO Auto-generated method stub Thread t1 = new ThreadA();//利用多态实例化一个A线程 Thread t2 = new ThreadB(t1);//利用多态实例化一个B线程 t1.start(); t2.s

cwf8 2015-01-11   2896   0
Java  

java中调用mysql存储过程 代码段

public class GenerateSampleData { public void select() { String sql=""; Connection con = null; CallableStatement callAble=null; try{ Class.forName("com.mysql.jdbc.Driver"); String url="jdbc:mysql://lo

ymc4 2015-02-11   1333   0
MySQL  

Java分页实现代码 代码段

package com.page; public class PageUtil { // 每页显示的条数 private int pageSize; // 总共的条数 private int recordCount; // 当前页面 private int currentPage; public PageUtil(int pageSize, int recordCount, int current

cwf8 2015-03-25   4266   0
Java  

java中对时间的操作 代码段

代码演示: //数据库中去的日期 Date s = list.get(0).getSdate(); System.out.println(s);// Tue Apr 28 00:00:00 CST 2015 //手动new Date d = new Date(); System.out.println(d);// Tue Apr 28 20:53:15 CST 2015 System.out.pr

me87re 2015-05-04   720   0
Java  

Java对各种排序算法的实现 代码段

冒泡排序 public class BubbleSort { public static int[] bubbleSort(int[] array) { if (array == null) { return null; } for (int i = 0; i < array.length; i++) { for (int j = i + 1; j < array.length; j++) { i

x286 2015-05-25   7386   6

java 下载网络中在文件 代码段

URL url = new URL(Config.local + "/excel/" + name); HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection(); // 设置请求信息 httpConnection.setRequestProperty("GET", "/down.zip HTTP/1.1"

javap 2015-06-25   941   0
Java  

java代理IP设置实例 代码段

System.setProperty("http.maxRedirects", "50"); System.getProperties().setProperty("proxySet", "true"); // 如果不设置,只要代理IP和代理端口正确,此项不设置也可以 System.getProperties().setProperty("http.proxyHost",“代理ip地址”); Sy

mdk3 2015-08-26   791   0
Java  

java 检测文本、文件编码 代码段

/** * 默认GB18030 */ public static final String detectCharset(byte[] byteArray){ // 建立InputStream ByteArrayInputStream bais = new ByteArrayInputStream(byteArray); // 默认编码 String utf8 = "UTF-8"; String c

jopen 2015-08-29   1533   0
Java  

Java获取本地IP方法 代码段

获取本地服务器IP经常会出现127.0.0.1,0:0:0:0:0:0:0:1,fe80:0:0:0:960:74bd:e1a0:e5b9%11 这些情况,以下代码可解决此问题 public static void main(String[] args) { try { Enumeration<NetworkInterface> enumeration = NetworkInterface .ge

jopen 2015-11-11   1074   1
Java  

Mongodb driver for java 使用样例 代码段

MongoDB的数据 ================================ { "_id" : ObjectId("54d3509f30c0ed0f308ed1ef"), "cust_id" : "A123", "amount" : 500.0, "status" : "A" } { "_id" : ObjectId("54d350a830c0ed0f308ed1f0"), "cust

AusWesolows 2016-02-11   6796   0
MongoDB  
1 2 3 4 5 6 7 8 9 10