zoukankan      html  css  js  c++  java
  • Java Learning (20110810)

    today, after discuss with Martin, learn with another way.
    I start to use chinese material, videos and files, and then explain to Martin. See whether this way is faster.
    ———————-
    identifier (标识符)
    start with letter, underline, $
    legal: userName, User_Name, _sys_value, $change
    illegal: 2mail, room#, class (reserved)
    ———–print format – printf———–
    package ch.allenstudy.newway01;
    public class NameConvention {
    public static void main(String[] args)
    {
    int i = 47;
    System.out.printf(“%d\n”, i);
    System.out.printf(“%x\n”, i);
    System.out.printf(“%#x\n”, i);
    System.out.printf(“%#X\n”, i);
    }
    }

    In Eclipse, run it, hint that has error. Force to run it, got below:
    ————————
    Exception in thread “main” java.lang.Error: Unresolved compilation problems:
    The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, int)
    The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, int)
    The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, int)
    The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, int)

    at ch.allenstudy.newway01.NameConvention.main(NameConvention.java:7)
    ————————–
    But in the video, everything works fine.
    Finally find the solution:
    In Eclipse, Window > Preferences > Java > Compiler. Change the “Compiler compliance level” from default “1.4″ to “6.0″.
    Then no erros.
    Result is as below:
    ———————
    47
    2f
    0x2f
    0X2F
    ———————

    Special character reprensation:
    backslash: \\
    Backspace: \b
    Carriage return: \r
    Tab (Form feed): \t
    New line: \n
    Single quote: \’
    =====================================
    package ch.allenstudy.newway01;
    public class TestPrintf {
    public static void main(String[] args)
    {
    char ch1 = ‘中’;
    char ch2 = ‘\u4e2d’;
    System.out.printf(“%c %c\n”, ch1, ch2);
    }
    }
    Result:
    中 中
    This means that: \u4e2d is an alternative representation of Chinese character 中.
    =====================================
    Diff type variable number scope


     A sample of force conversion:
    —————–
    package ch.allenstudy.newway01;

    public class TestPrintf {
    public static void main(String[] args)
    {
    byte b = 10;
    int i = 6;
    i = b;
    //b = i; //error
    b = (byte) i; //ok, force to convert to byte
    float x;
    //x = 10*0.2; //error, 10*0.2 is double type
    x = 10*0.2f; //ok, “f” means float
    System.out.printf(b+”, “+i+”, “+x);
    }
    }
    Result:
    10, 10, 2.0
    ========================
    package ch.allenstudy.newway01;

    public class TestPrintf {
    public static void main(String[] args)
    {
    int i = -3;
    int j = 11;
    int k = i & j; //3: 00000011 取反 11111101, 11: 00001011
    System.out.printf(“%d\n”, k);
    }
    }
    Result: 9
    Why? 我们一起看看与操作
    11111101
    00001011
    __________
    00001001
    So result is 9.

  • 相关阅读:
    设计模式
    【C/C++多线程编程之六】pthread相互排斥量
    J2EE的13个规范之(三) Servlet简单介绍
    .NET实现单点登录研究过程总结--【SSO】
    hdu4081 次小生成树变形
    eclipse代码提示框背景色改动
    Linux SO_KEEPALIVE属性,心跳
    [实战]MVC5+EF6+MySql企业网盘实战(20)——Bootstrap Paginator
    [工具]图片等比例压缩工具
    [工具类]视频音频格式转换
  • 原文地址:https://www.cnblogs.com/backpacker/p/2262553.html
Copyright © 2011-2022 走看看