Java应用基础微专业-入门篇

第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)

 

 

转载于:https://www.cnblogs.com/FudgeBear/p/6884743.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java语言程序设计(Java 7)- 入门与提高篇》是一本面向初学者和有一定编程基础的读者所编写的Java编程学习教材。本书内容丰富、全面,包含了Java语言的基础知识和高级技术,并通过大量的实例和练习帮助读者深入理解和掌握相关知识。 该书主要分为入门篇和提高篇两部分。入门篇首先介绍了Java语言的基础概念,包括Java开发环境的搭建、基本语法、数据类型、运算符、流程控制等。通过理论和实例结合的方式,帮助读者快速掌握Java编程的基本要点。 提高篇则着重介绍了Java语言的高级特性和技术。其中包括面向对象编程的概念和实践、异常处理机制、泛型、集合框架、多线程编程、网络编程、图形用户界面等。通过深入剖析这些高级技术的原理和应用,读者能够更全面地了解Java编程语言的高级特性。 《Java语言程序设计(Java 7)- 入门与提高篇》采用了大量简洁清晰的示例和案例分析,旨在帮助读者提高编程技能。每个章节都配有练习题,读者可以通过动手实践巩固所学的知识,并提升自己的编程水平。此外,书中还提供了一些实用的开发工具和技巧供读者参考,帮助读者能够更高效地开发Java应用程序。 总之,《Java语言程序设计(Java 7)- 入门与提高篇》是一本非常实用的Java编程入门教材,不仅适合初学者,也适合有一定编程经验的读者作为参考手册使用。无论是学习Java语言的基础知识,还是深入学习Java高级技术,本书都是不可或缺的一本好书。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值