第1章--用程序来做计算

1.1 第一个Java程序

Mac version: Preference -> General -> Keys -> Search "Content Assist" for binding to the short-key you want.

1.2 用变量做计算

1.3 表达式(浮点数,优先级和类型转换)

rounding happens to floating number: (e.g. shown below)

  System.out.println(1.2-1.1);
  output: 0.09999999999999987

第2章--判断

2.1 作比较

comparison between int and double:

  int a = 5;
  double b = 5.0;
  System.out.println(a==b);
  output: true

comparison between double and double:

  int a = 5;
  double b = 5.0;
  System.out.println(a==b);
  output: true   int a = 1.0;
  double b = 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1;
  System.out.println(b == c);
  System.out.println(b+"; "+c);
  output: false
  output: 1.0; 0.9999999999999999

solution: Math.abs(a-b) < 1e-6;

2.2 判断语句

2.3 多路分支

第3章--循环

3.1 循环(while和do-while循环)

do-while syntax: (cannot image that I even do not remember this)

  do {
   // body
  } while (condition);

3.2 for循环

3.3 循环控制(含复合赋值、逻辑类型)

using break with a label:similar to "goto" in c language

    blahblahblah;
LABEL:
for(int i = 0; i < 10; i++) {
blahblahblah
if (...) {
break LABEL; // break the loop labelled "LABEL"
}
}

3.4 循环应用

tricks for integer processing:

得到个位数:%10

去掉最低位:/10

Formatted Print:

System.out.printf("%.2f", x);

第4章--数组

4.1 数组的创建和使用

syntax of defining and creating an array: // fine, haven't write Java for rly a long time

type[] name = new type[size]; // size could be a variable, but it must be provided

e.g: int[] i = new int[array_size];

with initialisation:

type[] name = new type[size];

e.g: int[] i = {1,2,3};

4.2 数组变量和运算

int[] a = new int[size];

initialise array a

int[] b = a; // b just points to the block data which a points to (same block of data)

a == b ?  true

but what if a and b points to different blocks of memory?

int[] a = {1,2};

int[] b = {1,2};

a == b ? false

if we wanna compare the content of two arrays: solution--traversing and comparing each pair of element

if we wanna copy an array: solution--traversing and copying each element one by one

syntax for "for-each" loop to traverse an array:

for (type element: array) {}

4.3 二维数组

syntax for creating, initialising, and modifying a two-dimensional array:

int[][] a = new int[size][size];

int[][] a = { {1,2,3,4}, {1,2} };

a[1][2] = 5;

第5章--函数

5.1 函数的定义和调用

函数有多个出口(多个return statements)--> bad design

5.2 函数的参数与本地变量

Java在调用函数时,永远只能传值给函数(?)

life-cycle of a local variable: inside the block

  e.g.

    {
     int i;
    }
    i = 0; // ERROR

(END)


Java应用基础微专业-入门篇的更多相关文章

  1. Java应用基础微专业-工程篇

    第1章-命令行 1.1 命令行基础 ls -a: list all files (including hidden files) .DS_Store: files detailed informati ...

  2. Java应用基础微专业-设计篇

    第1章--抽象与接口 1.1 抽象 An abstract class can be created without abstract methods, the purpose of doing th ...

  3. Java应用基础微专业-进阶篇

    第1章--使用对象 1.1 字符类型 char c = 65; // char --> int char c = '\u0041'; // \u: unicode + (Hex 41--> ...

  4. 总结删除文件或文件夹的7种方法-JAVA IO基础总结第4篇

    本文是Java IO总结系列篇的第4篇,前篇的访问地址如下: 总结java中创建并写文件的5种方式-JAVA IO基础总结第一篇 总结java从文件中读取数据的6种方法-JAVA IO基础总结第二篇 ...

  5. 总结java中文件拷贝剪切的5种方式-JAVA IO基础总结第五篇

    本文是Java IO总结系列篇的第5篇,前篇的访问地址如下: 总结java中创建并写文件的5种方式-JAVA IO基础总结第一篇 总结java从文件中读取数据的6种方法-JAVA IO基础总结第二篇 ...

  6. Java中的IO流 - 入门篇

    前言 大家好啊,我是汤圆,今天给大家带来的是<Java中的IO流-入门篇>,希望对大家有帮助,谢谢 由于Java的IO类有很多,这就导致我刚开始学的时候,感觉很乱,每次用到都是上网搜,结果 ...

  7. jQuery学习笔记 - 基础知识扫盲入门篇

    jQuery学习笔记 - 基础知识扫盲入门篇 2013-06-16 18:42 by 全新时代, 11 阅读, 0 评论, 收藏, 编辑 1.为什么要使用jQuery? 提供了强大的功能函数解决浏览器 ...

  8. Java中的集合List - 入门篇

    前言 大家好啊,我是汤圆,今天给大家带来的是<Java中的集合List - 入门篇>,希望对大家有帮助,谢谢 简介 说实话,Java中的集合有很多种,但是这里作为入门级别,先简单介绍第一种 ...

  9. Java中的映射Map - 入门篇

    前言 大家好啊,我是汤圆,今天给大家带来的是<Java中的映射Map - 入门篇>,希望对大家有帮助,谢谢 简介 前面介绍了集合List,这里开始简单介绍下映射Map,相关类如下图所示 正 ...

随机推荐

  1. Docker创建镜像文件并在容器中运行

    1.如何创建镜像文件 首先找到Docker ToolBox安装的路径,在路径下直接新建Dockerfile文件 在Dockerfile文件里写入的内容为: FROM docker/whalesay:l ...

  2. [LuoguP2900] [USACO08MAR]土地征用(Land Acquisition)

    土地征用 (Link) 约翰准备扩大他的农场,眼前他正在考虑购买N块长方形的土地.如果约翰单买一块土 地,价格就是土地的面积.但他可以选择并购一组土地,并购的价格为这些土地中最大的长 乘以最大的宽.比 ...

  3. HDU 2088 Box of Bricks(脑洞)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2088 Box of Bricks Time Limit: 1000/1000 MS (Java/Oth ...

  4. STM32之关闭JTAG

    1.有些时候不想用JTAG口(而用SWJ在线调试),把JTAG暂用的IO通过remap出来使用 2.比如48 pin的STM32F103CBT6单片机: GPIO_PinRemapConfig(GPI ...

  5. stm32之remap

    1.GPIO的重映射属于AFIO,不同类型不同引脚数单片机情况不一样,比如下图: 2.AFIO 下面还分default/Remap,如果用到了remap就得使用: GPIO_PinRemapConfi ...

  6. 05 oracle中lock和latch的用途

    oracle中lock和latch的用途   本文向各位阐述Oracle的Latch机制,Latch,用金山词霸翻译是门插栓,闭锁,专业术语叫锁存器,我开始接触时就不大明白为什么不写Lock,不都是锁 ...

  7. Spring security学习笔记(二)

    对比两种承载认证信息的方式: session vs token token验证方案: session验证方案: session即会话是将用户信息保存在服务端,根据请求携带的session_id,从服务 ...

  8. Laravel 生成二维码

    (本实例laravel 版本 >=5.6, PHP版本 >=7.0) 1.首先,添加 QrCode 包添加到你的 composer.json 文件的 require 里: "re ...

  9. QWT编译与配置-Windows/Linux环境

    QWT编译与配置-Windows/Linux环境 QWT和FFTW两种开源组件是常用的工程软件支持组件,QWT可以提供丰富的绘图组件功能,FFTW是优秀数字波形分析软件.本文使用基于LGPL版权协议的 ...

  10. golang for循环里面创建协程问题的研究

    原本想在一个for里面创建10个协程,这些协程顺序拿到for的递增变量,把这10个递增变量都打印出来.但事与愿违,于是做实验,查书,思考,写出以下记录. golang里,在for循环里面起协程,如下代 ...