Java基础 println 输出常量的示例

  •     JDK :OpenJDK-11
  •      OS :CentOS 7.6.1810
  •      IDE :Eclipse 2019‑03
  • typesetting :Markdown

code

package per.jizuiku.base;

/**
 * @author 给最苦
 * @date 2019/06/29
 * @blog www.cnblogs.com/jizuiku
 */
class Demo {

    /**
     * @param args
     */
    public static void main(String[] args) {

        // 输出常量
        System.out.println("hello");// 字符串
        System.out.println(100);// 整数
        System.out.println(11.1);// 小数
        System.out.println('a');// 字符
        System.out.println(true);// 布尔常量
        System.out.println(false);

        // System.out.println(null);
        // 上面一行代码在输出的时候出现错误
        // 提示:对println的引用不明确。
    }
}

result

hello
100
11.1
a
true
false

sourceCode

/**
    * Prints a boolean and then terminate the line.  This method behaves as
    * though it invokes {@link #print(boolean)} and then
    * {@link #println()}.
    *
    * @param x  The {@code boolean} to be printed
    */
public void println(boolean x) {
    synchronized (this) {
        print(x);
        newLine();
    }
}
/**
    * Prints a boolean value.  The string produced by {@link
    * java.lang.String#valueOf(boolean)} is translated into bytes
    * according to the platform's default character encoding, and these bytes
    * are written in exactly the manner of the
    * {@link #write(int)} method.
    *
    * @param      b   The {@code boolean} to be printed
    */
public void print(boolean b) {
    write(String.valueOf(b));
}
private void write(String s) {
    try {
        synchronized (this) {
            ensureOpen();
            textOut.write(s);
            textOut.flushBuffer();
            charOut.flushBuffer();
            if (autoFlush && (s.indexOf('
') >= 0))
                out.flush();
        }
    }
    catch (InterruptedIOException x) {
        Thread.currentThread().interrupt();
    }
    catch (IOException x) {
        trouble = true;
    }
}

resource

  • [ JDK ] openjdk.java.net
  • [ doc - 参考 ] docs.oracle.com/en/java/javase/11
  • [ 规范 - 推荐 ] yq.aliyun.com/articles/69327
  • [ 规范 - 推荐 ] google.github.io/styleguide
  • [ 源码 ] hg.openjdk.java.net
  • [ OS ] www.centos.org
  • [ IDE ] www.eclipse.org/downloads/packages
  • [ 平台 ] www.cnblogs.com


感谢帮助过 给最苦 的人们。
Java、Groovy和Scala等基于JVM的语言,优秀,值得学习。
规范的命名和代码格式等,有助于沟通和理解。
JVM的配置、监控与优化,比较实用,值得学习。

原文地址:https://www.cnblogs.com/jizuiku/p/11107748.html