1. 判断是否是奇数:

public static boolean isOdd(int i) { return i %2 != 0 ; }

2. System.out.println(2.0 - 1.1); 输出:0.89999999 99999999 (Double型的)

System.out.println(new BigDecimal("2.00").subtract(new BigDecimal("1.10")));   --输出 0.90 要加上引号,否则会有小数。

System.out.println(new BigDecimal("2.01").subtract(new BigDecimal("1.65")));   -- 输出 0.36

System.out.println(new BigDecimal(2.0).subtract(new BigDecimal(1.1)));  -- 输出    0.899 99999999 99999111 82158029 98747676 61094665 52734375

System.out.printf("%.2f\n", 2.0-1.115);   --输出:0.89

final long MICROS_PER_DAY = 24 * 60 * 60 * 1000 * 1000;
final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000;
System.out.println(24 * 60 * 60 * 1000 * 1000);                              --- 输出: 500654080  , 当做了int型,导致越界。
System.out.println(24 * 60 * 60 * 1000 );                                        --- 输出: 86400000 
System.out.println(MICROS_PER_DAY/MILLIS_PER_DAY);         --- 输出 :5

对于长整型的计算,要加上L:  System.out.println(24L * 60 * 60 * 1000 * 1000);  --- 输出: 86400000 000

System.out.println("H" + "a"); 输出: Ha

System.out.println("H" + 'a');     Ha

System.out.println('H' + 'a');    169

char[] numbers = {'1','2','3'};

System.out.println("a" + numbers);     输出:a[C@c3c749

void java.io.PrintStream.println(String x)

Prints a String and then terminate the line. This method behaves as though it invokes print(String) and then println().

System.out.println(numbers);  输出:123

void java.io.PrintStream.println(char[] x)     重载的方法

Prints an array of characters and then terminate the line. This method behaves as though it invokes print(char[]) and then println().

\u0022 是双引号的unicode编码。

System.out.println("a\u0022 + \u0022b ".length());   相当于: System.out.println("a" + "b ".length());  , 输出 a2  。(b后面有一个空格)

System.out.println(Test.class.getName().replace(".","/"));   输出: com/Test

String java.lang.String.replace(CharSequence target, CharSequence replacement)

Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence. The replacement proceeds from the beginning of the string to the end, for example, replacing "aa" with "b" in the string "aaa" will result in "ba" rather than "ab".

System.out.println(Test.class.getName().replaceAll(".","/"));   输出:////////

System.out.println(Test.class.getName().replaceAll("\\.","/"));   输出:com/Test

String java.lang.String.replaceAll(String regex, String replacement)

Replaces each substring of this string that matches the given regular expression with the given replacement.

An invocation of this method of the form str.replaceAll(regex, repl) yields exactly the same result as the expression

java.util.regex.Pattern.compile(regex).matcher(str).replaceAll(repl)

StringBuffer word = null;
word = new StringBuffer('P');

‘P’ 当做了int数。

java.lang.StringBuffer.StringBuffer(int capacity)

Constructs a string buffer with no characters in it and the specified initial capacity.

Parameters:
capacity the initial capacity.

System.out.println(word);                           输出换行
System.out.println(word.append("a"));      输出 a

int j = 0;
for(int i = 0; i < 100; i++){
j = j++;
System.out.println(j);
}

输出100 行 0 (j的值总是 0):

0

0

……

final int END=Integer.MAX_VALUE;                    //2147483647
final int START = END - 100;
int count = 0;
for(int i = START; i <= END; i++){
  count++;
  System.out.println(i);     -- 死循环。  当 i 达到 2147483647 ,再增加会变成负数。
}

java的一些问题的更多相关文章

  1. Spark案例分析

    一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...

  2. 故障重现(内存篇2),JAVA内存不足导致频繁回收和swap引起的性能问题

    背景起因: 记起以前的另一次也是关于内存的调优分享下   有个系统平时运行非常稳定运行(没经历过大并发考验),然而在一次活动后,人数并发一上来后,系统开始卡. 我按经验开始调优,在每个关键步骤的加入如 ...

  3. Elasticsearch之java的基本操作一

    摘要   接触ElasticSearch已经有一段了.在这期间,遇到很多问题,但在最后自己的不断探索下解决了这些问题.看到网上或多或少的都有一些介绍ElasticSearch相关知识的文档,但个人觉得 ...

  4. 论:开发者信仰之“天下IT是一家“(Java .NET篇)

    比尔盖茨公认的IT界领军人物,打造了辉煌一时的PC时代. 2008年,史蒂夫鲍尔默接替了盖茨的工作,成为微软公司的总裁. 2013年他与微软做了最后的道别. 2013年以后,我才真正看到了微软的变化. ...

  5. 故障重现, JAVA进程内存不够时突然挂掉模拟

    背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...

  6. 死磕内存篇 --- JAVA进程和linux内存间的大小关系

    运行个JAVA 用sleep去hold住 package org.hjb.test; public class TestOnly { public static void main(String[] ...

  7. 【小程序分享篇 一 】开发了个JAVA小程序, 用于清除内存卡或者U盘里的垃圾文件非常有用

    有一种场景, 手机内存卡空间被用光了,但又不知道哪个文件占用了太大,一个个文件夹去找又太麻烦,所以我开发了个小程序把手机所有文件(包括路径下所有层次子文件夹下的文件)进行一个排序,这样你就可以找出哪个 ...

  8. Java多线程基础学习(二)

    9. 线程安全/共享变量——同步 当多个线程用到同一个变量时,在修改值时存在同时修改的可能性,而此时该变量只能被赋值一次.这就会导致出现“线程安全”问题,这个被多个线程共用的变量称之为“共享变量”. ...

  9. Java多线程基础学习(一)

    1. 创建线程    1.1 通过构造函数:public Thread(Runnable target, String name){}  或:public Thread(Runnable target ...

  10. c#与java的区别

    经常有人问这种问题,用了些时间java之后,发现这俩玩意除了一小部分壳子长的还有能稍微凑合上,基本上没什么相似之处,可以说也就是马甲层面上的相似吧,还是比较短的马甲... 一般C#多用于业务系统的开发 ...

随机推荐

  1. Oracle使用row_number()函数查询时增加序号列

    使用Oracle自带的row_number()函数能够实现自动增加序号列的要求,但是同时引发一个问题,如果我们查询出来的数据需要使用Order By排序的话,那么我们会发现新增加的序号列是乱序的,它会 ...

  2. Netty源码细节-accept、read(Linux os层 + Netty层代码细节)(转)

    原文:http://budairenqin.iteye.com/blog/2215899 这篇分析一下accept的细节, 我觉得网络IO相关开发很多时候不能仅仅局限于java层, 尤其从accept ...

  3. java 入门-helloWorld

    Java 教程 Java 是由Sun Microsystems公司于1995年5月推出的高级程序设计语言. Java可运行于多个平台,如Windows, Mac OS,及其他多种UNIX版本的系统. ...

  4. C语言字符串操作总结大全(超具体)

    1)字符串操作 strcpy(p, p1) 复制字符串 strncpy(p, p1, n) 复制指定长度字符串 strcat(p, p1) 附加字符串 strncat(p, p1, n) 附加指定长度 ...

  5. 虚拟机下安装CentOS无法上网的解决方式

    我使用VMware虚拟机安装Ubuntu和CentOS,都使用NAT模式连接网络,可是Ubutun能够正常上网,而CentOS不能连接到网络. 原来Centos7默认是不启用有线网卡的.须要手动开启. ...

  6. SVN学习(一)——SVN 检出文件步骤、图标显示及含义

    May, I come... 1. 创建一个目录用来存放检出得到的文件,例如MyCRM 2. 直接进入目录MyCRM,点右键 3. 可以看到检出得到的文件 此时文件图标上没有任何标识.可能你会想到通过 ...

  7. 向 mysql 插入汉字时报错 Incorrect string value: '\xE6\x9B\xB9\xE5\x86\xAC...' for col....

    Incorrect string value: '\xE6\x9B\xB9\xE5\x86\xAC...' for column 'realname' at row 1 该情况一般是由数据库设计时的编 ...

  8. VB的第一个项目

     前言-----本人也是刚刚接触VB,企业的VB代码基本能看的懂,但是自己开发,只能呵呵.一般在刚学习一门新的语言时,很容易发生一些自己相当然的认识错误,so,记下并分享开发学习的过程,望指正.--- ...

  9. js知识地图--js大脑图beta01版正式发布

    原文地址 http://zhangyaochun.iteye.com/blog/1682605 原作者:zhangyaochun

  10. opencv的C语言接口和C++接口差别(入门篇)

    opencv是一个开源的图像处理库,最经典的1.0版本号提供的接口都是C语言接口. 后来的opencv2.x版本号保留了C语言接口,可是提供了C++接口,当中的C语言接口仅仅是为了向后兼容,而C++接 ...