Quantcast
Channel: BlogJava--随笔分类-java
Browsing latest articles
Browse All 31 View Live

Image may be NSFW.
Clik here to view.

HttpURLConnection 的使用

System.setProperty("sun.net.client.defaultConnectTimeout", "3000");        System.setProperty("sun.net.client.defaultReadTime ", "3000");                 URL url1=null;        try {            url1 =...

View Article


Image may be NSFW.
Clik here to view.

数学公式解析和计算

JEPhttp://www.singularsys.com/jep/https://sourceforge.net/projects/jep/http://rabbit8.bokee.com/3936531.htmlhttp://suneca.com/article.asp?id=28http://www.javaeye.com/topic/58422里办法多关于jexl1,jexl1.1计算分母为...

View Article


Image may be NSFW.
Clik here to view.

操作数组

1,List转数组    List list = new ArrayList();        list.add("1");        list.add("2");        int size = list.size();        String[] arr = (String[]) list.toArray(new String[size]);     必须带参数new...

View Article

Image may be NSFW.
Clik here to view.

java.io.CharConversionException: Not an ISO 8859-1 character: xx

调用Action获取字符串,其中包含中文,使用如下代码输出: ServletOutputStream out = response.getOutputStream(); request.setAttribute("xmlTree", tree); out.print(tree);使用的编码是GBK,在JDK1.5运行抛出异常:java.io.CharConversionException: Not...

View Article

Image may be NSFW.
Clik here to view.

HttpURLConnection设置网络超时

Java中可以使用HttpURLConnection来请求WEB资源。HttpURLConnection对象不能直接构造,需要通过 URL.openConnection()来获得HttpURLConnection对象,示例代码如下:String urlStr= www.ttt.org;URL url = new URL(urlStr);HttpURLConnection conn =...

View Article


Image may be NSFW.
Clik here to view.

HttpURLConnection timeout solution

From: Niels Campbell (niels_campbell_at_lycos.co.uk)Date: 01/23/04Date: 23 Jan 2004 09:14:16 -0800After spending nearly 3 days on this problem to come up with a solution I think it is only right to...

View Article

Image may be NSFW.
Clik here to view.

Adding Socket Timeout to java.net.URLConnection (JDK 1.2)

Adding Socket Timeout to java.net.URLConnection (JDK 1.2) found a bug , see "connected = true;" in public void connect() throws IOException { Note: 05/11/01 Sam Found a patch for borland As I got the...

View Article

Image may be NSFW.
Clik here to view.

正则表达式笔记

String regex = "<a.*?/a>";//取链接        Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);        Matcher mt = pattern.matcher(str);        while (mt.find()) {        String...

View Article


Image may be NSFW.
Clik here to view.

JVM笔记

1,http://www.javaeye.com/topic/143987在新版本的java里面,同步比gc慢 所以以前很多framework里面都有pool的设定,现在都取消了 现在只有一些数据库连接等IO资源做pool以外,基本的数据class已经都不作pool了pool 一般用在创建很大消费的对象时才用的。 比如 connection, tapestry的page。 像new...

View Article


Image may be NSFW.
Clik here to view.

log笔记

1,为什么要写 if (log.isDebugEnabled())在使用log4j,common-log这样的log框架时,发现很多代码中这样写 if   (log.isDebugEnabled())   {           log.debug( "xxxx "); }...

View Article

Image may be NSFW.
Clik here to view.

分页

http://www.javaeye.com/topic/470144http://www.javaeye.com/topic/121756http://www.javaeye.com/topic/57909http://www.javaeye.com/topic/400225http://www.blogjava.net/weijy/archive/2008/09/27/231449.htmlht...

View Article

Image may be NSFW.
Clik here to view.

java处理浮点数

    public void testBigDecimalEquals() {        assertEquals(new BigDecimal("3.50"),new BigDecimal("3.5"));//不相等    } System.out.println(0.030*100);//输出3.0 System.out.println(0.031*100);//输出3.1...

View Article

Image may be NSFW.
Clik here to view.

线程安全类

当一个类已经很好的同步以保护它的数据时,这个类就称为“线程安全的”。 即使是线程安全类,也应该特别小心,因为操作的线程是间仍然不一定安全。import java.util.Collections;import java.util.LinkedList;import java.util.List;public class TestThread {    public static void...

View Article


Image may be NSFW.
Clik here to view.

java的static

Static 的意义与实作方式   Class(static) field :共用一块记忆体 class(static) method :共用一块记忆体 instance( 非 static) field :随着每个 instance 各有一块记忆体 instance ( 非 static) method :共用一块记忆体     instance method 为什么不是随着每个...

View Article

Image may be NSFW.
Clik here to view.

值和引用

JDK1.6          Integer v1 = 100;        Integer v2 = 100;        System.out.println(v1 == v2); // 输出:true                Integer w1 = 200;        Integer w2 = 200;        System.out.println(w1 == w2);...

View Article


Image may be NSFW.
Clik here to view.

深入java虚拟机笔记

1,java体系结构包括四个独立但相关的技术:java语言、class文件格式、java的api、java虚拟机2,java虚拟机是一台抽象的计算机,主要任务是装载class文件并且执行其中的字节码。不同的java虚拟机,其执行引擎的实现可能不一样。分为软件实现和硬件实现(内嵌在芯片),软件实现有以下几种:(1)每次都会解释字节码(2)即时编译,即编译成本低机器代码,缓存起来可以重用(3)自适应优化...

View Article

Image may be NSFW.
Clik here to view.

java类的加载

打印Thread.currentThread().getContextClassLoader(),显示如下:sun.misc.Launcher$AppClassLoader@19821f这个加载器是系统类加载器。ClassLoader.getSystemResourceAsStream("com/config.xml")使用的就是系统类加载器定位资源的。...

View Article


Image may be NSFW.
Clik here to view.

关于OSGI

参考:1,OSGi,Java模块化框架的另类进化 http://developer.51cto.com/art/201003/190584.htm2,独家专访林昊:一步一步了解Java模块化 http://developer.51cto.com/art/201001/181503.htmleekiang 2011-03-05 00:12 发表评论

View Article

Image may be NSFW.
Clik here to view.

Java字符串

String s1="ab";String s2="a"+"b";System.out.println(s1==s2);//trueString s1 = "abc";String s2 = "ab";String s3 = s2 + "c";System.out.println((s1 == s3));//falseString s1 = "abc"; final String s2 =...

View Article

Image may be NSFW.
Clik here to view.

java知识点

1,double d = 1 / 4;System.out.println(d);//输出为02,    public static void main(String[] args) {        StringBuffer a = new StringBuffer("a");        StringBuffer b = new StringBuffer("b");...

View Article

Image may be NSFW.
Clik here to view.

java基础(续)

StackOverflowError  当应用程序递归太深而发生堆栈溢出时抛出 Jamon(Java Application Monitor)是一款免费的、高性能的、线程安全的Java程序,它使得开发人员能够容易地完成对生产环境应用程序的监控。Java保证读和写32位数或者更小的值是原子操作,也就是说可以在一步完成,因而不可能被打断,因此这样的读和写不需要同步。以下的代码是线程安全(thread...

View Article


Image may be NSFW.
Clik here to view.

log4j

报错:log4j:ERROR Document root element "log4j:configuration",  must match DOCTYPE root "null".解决:Try adding this to the second line (the line below <?xml ...?>)...<!DOCTYPE log4j:configuration...

View Article


Image may be NSFW.
Clik here to view.

JDK5笔记

1,SuppressWarnings的作用是抑制编译器产生警告信息。@SuppressWarnings("unused")@SuppressWarnings("unchecked")eclipse支持的SuppressWarning的值如下,其他开发工具略有差异。all to suppress all warningsboxing to suppress warnings relative to...

View Article

Image may be NSFW.
Clik here to view.

Error: no `server' JVM at `C:\Program Files\Java\jre6\bin\server\jvm.dll

如果报Error: no `server' JVM at `C:\Program Files\Java\jre6\bin\server\jvm.dll的错误,可把jdk下的jre\bin\server下的server文件夹复制到C:\Program Files\Java\jre6\bin目录即可解决。...

View Article

Image may be NSFW.
Clik here to view.

java 应用监控

JavaMelody 能够在QA和实际运行生产环境监测Java或Java EE应用程序服务器。并以图表的形式显示:Java内存和Java CPU使用情况,用户Session数量,JDBC连接数,和http请求、sql请求、jsp页面与业务接口方法(EJB3、Spring、Guice)的执行数量,平均执行时间,错误百分比等。图表可以按天,周,月,年或自定义时间段查看。 jwebap...

View Article


Image may be NSFW.
Clik here to view.

jvm内存分析笔记

1. java.lang.OutOfMemoryError: GC overhead limit exceeded原因   <http://blog.csdn.net/taijianyu/article/details/6606792>   <http://www.sunnybtoc.com/page/M0/S746/746195.html>   2....

View Article

Image may be NSFW.
Clik here to view.

java调用shell

Runtime run = Runtime.getRuntime();String str[] = { "/bin/sh", "-c", "echo '1' >> test.log" };try {    run.exec(str);} catch (IOException e) {}使用Jsch执行Shell脚本...

View Article

Image may be NSFW.
Clik here to view.

CountDownLatch和CyclicBarrier的区别

CountDownLatch : 一个线程(或者多个), 等待另外N个线程完成某个事情之后才能执行。   CyclicBarrier  : N个线程相互等待,任何一个线程完成之前,所有的线程都必须等待。这样应该就清楚一点了,对于CountDownLatch来说,重点是那个“一个线程”, 是它在等待,...

View Article

Image may be NSFW.
Clik here to view.

如何用 Java 获取系统 IP?

参考dubbo里的NetUtils类import java.net.InetAddress;import java.net.NetworkInterface;import java.util.Enumeration;import java.util.regex.Pattern;public class GetIP {public static void main(String[] args)...

View Article



Image may be NSFW.
Clik here to view.

java8国际化直接支持的语言列表

System.out.println("availableLocales :"+ Locale.getAvailableLocales().length);Locale[] arr=Locale.getAvailableLocales(); Arrays.sort(arr, new Comparator<Locale>() { @Override public int...

View Article
Browsing latest articles
Browse All 31 View Live