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. 使用Spring进行远程访问与Web服务

    1.1. 简介   Spring为各种远程访问技术的集成提供了整合类.Spring使得开发具有远程访问功能的服务变得相当容易,而这些远程访问服务由普通Spring POJO实现.目前,Spring支持 ...

  2. e.which

    e.which is not an event, which is a property of the event object, which most people label as e in th ...

  3. Microsoft.VisualC 命名空间包含支持用 c + + 语言的代码生成和编译的类。 混合编程中使用COM接口指针

    Microsoft.VisualC 命名空间包含支持用 c + + 语言的代码生成和编译的类. Microsoft.VisualC.StlClr Unmanaged Code 和 Managed Co ...

  4. POJ Cow Exhibition

    题目链接:Click Here~ 题目意思自己看吧. 算法分析: 对我来想是没有想到,最后看别人的博客才知道的.要把当中的一个条件当作体积.由于两个条件都存在负数,所以还要先保证最后不会再体积中出现负 ...

  5. Mysql 中文中繁杂的字 插入报错的 解决方案

    首先 数据库默认编码选用 utf8 连接字符串也相应改成utf8,不能是gb2312

  6. React的设计哲学 - 简单之美

    React最初来自Facebook内部的广告系统项目,项目实施过程中前端开发遇到了巨大挑战,代码变得越来越臃肿且混乱不堪,难以维护.于是痛定思痛,他们决定抛开很多所谓的“最佳实践”,重新思考前端界面的 ...

  7. JavaScript逻辑运算符(操作数运算符)

    1.概述 ||(或)和&&(与)都是逻辑运算符.但是或/与叫“逻辑运算符”不太合适,叫“操作数运算符”更合适! 因为||(或)和&&(与)返回的不是布尔值,而是两个操作 ...

  8. (二)EasyUI 使用——常用组件

    1. EasyUI常用组件的基本用法 1.1 layout布局 <!-- 布局面板 大小自适应父容器 --> <div data-options="fit:true&quo ...

  9. mac下安装python pip、pyspider

    如果mac下没有安装wget,还需要安装wget,见http://www.cnblogs.com/cocowool/archive/2012/06/24/2560574.html 使用 pip 安装 ...

  10. 用JS将json日期格式化成正常日期

       function ChangeDateFormat(cellval) {             var date = new Date(parseInt(cellval.replace(&qu ...