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. javascript数据类型检测方法

    一.字符串.数字.布尔值.undefined的最佳选择市使用 typeof 运算符进行检测: 对于字符串,typeof 返回"string" 对于数字,typeof 返回" ...

  2. kubelet分析

    kubelet是k8s中节点上运行的管理工具,它负责接受api-server发送的调度请求,在Node上创建管理pod,并且向api-server同步节点的状态.这篇文章主要讲讲kubelet组件如何 ...

  3. Private strand flush not complete错误

    Private strand flush not complete错误 (2013-10-22 11:04:58) 转载▼   分类: FAQ 最近的一个报表系统数据库,总是出现checkpoint ...

  4. What is Continuous Integration?

    什么叫持续集成? 原文: https://docs.microsoft.com/en-us/azure/devops/what-is-continuous-integration ---------- ...

  5. subscription group permisson

  6. 模板:什么是Traits

    Traits不是一种语法特性,而是一种模板编程技巧.Traits在C++标准库,尤其是STL中,有着不可替代的作用.   如何在编译期间区分类型   下面我们看一个实例,有四个类,Farm.Worke ...

  7. 自定义radio/checkbox样式

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  8. RSA的密钥把JAVA格式转换成C#的格式(2)

    把C#格式转换成Java:RSA的密钥把JAVA格式转换成C#的格式(1) 我已经在第一篇介绍过如何把C#格式转换成Java,现在来看看如何把Java格式转换成C#. /// <summary& ...

  9. Hibernate单向“多对一”关联

    1. 基于外键关联的单向“多对一”关联是最常见的单向关联其中指定many-to-one的unique="true",为单向“一对一”,不指定就是单向“多对一” <class  ...

  10. ibatis 动态查询

    http://www.iteye.com/topic/393042最近做了很多动态的查询,尤其是排序,以及一些状态字段,所以就做了一个总的动态查询,以不变应万变,呵呵 ibatis 里面的sql代码: ...