• 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.

  • 相关阅读:
    (转)原始图像数据和PDF中的图像数据
    itextSharp 附pdf文件解析
    (转)pdf文件结构
    【iCore1S 双核心板_ARM】例程九:DAC实验——输出直流电压
    【iCore4 双核心板_FPGA】例程七:状态机实验——状态机使用
    【iCore4 双核心板_FPGA】例程六:触发器实验——触发器的使用
    【iCore4 双核心板_ARM】例程八:定时器PWM实验——呼吸灯
    【iCore4 双核心板_ARM】例程七:WWDG看门狗实验——复位ARM
    【iCore1S 双核心板_FPGA】例程七:基础逻辑门实验——逻辑门使用
    【iCore1S 双核心板_FPGA】例程六:状态机实验——状态机使用
  • 原文地址:https://www.cnblogs.com/backpacker/p/2262553.html
Copyright © 2020-2023  润新知