java程序设计-第一章

第一章

    • 教材知识点、概念
      • 1.2 什么是计算机
      • 1.3 编程语言
      • 1.4操作系统 Operating System
      • 1.5 操作系统
      • 1.6 、1.7 、1.8、1.10
      • 关键术语
  • 教材quiz
    • 1. 如何换行
    • 要点1
    • 2. 打印表格
  • 要点2 域宽
    • 3. 求半径5.5的圆的周长和面积
    • 要点
    • 4.
    • 要点4
    • Lab0

第一章 计算机、程序和Java概述

Java语言程序设计与数据结构(中、英文)梁勇 著

Lab0

教材知识点、概念

1.2 什么是计算机

  1. 硬件、软件定义
  • hardware: the visible, physical elements of the computer
  • sofware: provide the invisible instructions that control the hardware and make it perform special tasks
  1. 5种主要的硬件组件/major computer components
  • a centeral processing unit [CPU] 中央处理器
    memory [Main memory]内存/主存
    Storage devices[ such as disks and CDs] 储存设备/磁盘和光盘
    Input devices[ such as the mouse and keyboard] 输入设备
    Output devices[such as monitors and printers]
    Communication devices [such as modems and network interface cards] 通信设备/调制调节器和网卡
  1. CPU含义、衡量其速度的单位
  • Central Processing Unit 中央处理器
  • hertz\megahertz\gigahertz 赫兹/兆赫/千兆赫
    Hz\ MHz \GHz 现在的电脑通常是3GHz
  1. 比特和字节/ bits and bytes
  • bits: binary digits 0 or 1
    byte: is composed of 8 bits ; the minimum storage unit in the computer
    encoding scheme: the way where the data encoded and decoded 编码模式
  1. 内存、RAM、衡量内存大小的单位
  • memory [内存]: the bytes in the memory can be accessed in any order, 又称RAM [random-access-memory 随机访问储存器]
    unique address
  • kilobytes\ megabytes\ gigabytes\ terabytes
    KB\ MB\ GB\ TB 现在的电脑通常装有6-8GB的内存
  1. 磁盘、衡量磁盘大小的单位\ Disks
    hard disks usually is 500 GB- 1TB
  2. 内存、永久储存设备不同之处\ Memory and storage devices
    RAM is a volatile form of data storage

1.3 编程语言

  1. CPU理解的语言
  • machine language 机器语言
  1. 汇编语言、汇编器 assembly language/ assembler
  • assembly language : uses a short descriptive word, known as mnemonic 助记符, to represent each of the machine-language
  • assembler :to translate assember-language program to machine code
    low-level language
  1. 高级编程语言、源程序\ High-level language Source program
    platform independent, meaning that you can write a program once and run it on any computer

  2. 解释器、编译器
    interpreter : reads one statement from the source code and translates it into machine code or virtual machine code(Java.class) and executes it right away.
    compiler : translates the source code into the machine code file, and then executes.

source code --interpreter-- output
source code --compiler --machine-code file --executor --output

  1. 解释语言、编译语言的区别\ Interpreter language and Compiler language
  • Interpreter language : 一次编译即可被机器识别-一次编译终身运行 效率高 跨平台能力好
  • Compiler language : 编译为中间代码 跨平台性差 因为不同电脑位数不同情况下 编译出来的中间代码是不一样的
  • Java:编译-解释型语言 先编译成与平台无关的.class 语言,然后在JVMjava虚拟机上解释执行是一行读取一行翻译一行执行的。

1.4操作系统 Operating System

  1. 操作系统、流行的操作系统 \Operating System
  • The OS manages and controls the computer’s activities.
    Microsoft Windows, Mac OS, Linux

Users – Applicatians Programes – OS – hardware

  1. OS的主要任务 major tasks \ 多道程序设计、多线程、多处理
  • controlling and monitoring system activities
  • allocating and assigning system resources
  • scheduling operations
    • multiprogramming: allows multiple programs to run simultaneouslyby sharing the same CPU
    • multithreading: allows a single program to execute multiple tasks at the same time.
    • multiprocessing: uses teo or more processers to perform subtasks and then combine the solutions of subtasks to a solution for the entire task.

1.5 操作系统

  1. Java有谁发明、属于公司
    James Gosling at Sun Microsystems, which then be purchased by Oracle.

  2. Java applet\ Java 小程序
    Java programs can be run from a Web browser.

  3. 安卓使用的编程语言 : Java

1.6 、1.7 、1.8、1.10

  1. Java语言规范\ Java language specification
  • the technique definition of Java programming language’s syntax and semantics. [ 语法,语义]
  • API: the application program interface [应用程序接口] knoen as library , contains predefined ckass and interfaces.
  1. JDK、JRE
  • Java development toolkits: each invoked from a command line, for developing, testing Java program;
  • JRE: Java runtime environment 运行Java program 的程序
  1. IDE Integrated development environment \集成开发环境
  • editing, compiling, testing, debugging, online help… on a graphcial user interface \ 图形用户界面
  1. 关键字 key words / reserved words
    main, public, void, static

  2. 大小写敏感 case sensitive
    main != Main

  3. 注释、一行和一段\ comment

  • line comment //
  • block/ paragraph comment /* */
    / * * … */ 可以生成HTML文件
  1. 显示字符的语句\ display a string on the console
    System.out.println("。。。");
  2. Java源文件、字节码文件的拓展名 Java source filename extension/ Java bytecode extension
    .java \ .class
  3. Java编译器的输入和输出the input and the output of the compiler
    Java source file and the Java bytecode file
  4. 编译、运行Java程序的命令

javac .\*.java
java *

  1. JVM\ Java virtual machine
    Java虚拟机 a program that interpretes Java bytecode
  2. Java在任意一台计算机上运行需要什么
    JVM
  3. NoClassFoundError错误的原因
    execute a class file that does not exist
  4. NoSuchMethodError错误的原因
    execute a class file that does not have a main method or misplay the main method
  5. 编译错误(语法错误)、运行时错误、逻辑错误及示例
  • syntax error
  • runtime error 如 发生\0 导致程序提前终止
  • logic error 结果和预想的不一致

关键术语

API
bus 总线
byte 字节
bytecode 字节码
bytecode verifier 核实、查证
cable modem 电缆调制调节器
class loader 类加载器
dot pitch 点距
DSL digital subscriber line 数字线路
pixel 像素
screen solution 显示屏像素

  • Java program can be enbedded in HTML pages and download by Web broesers to bring live animation and interaction to Web clients

教材quiz

1. 如何换行

System.out.println("Welcome to Java\n"+
	"Welcome t\no CS"+"\n"+"Programming is fun");

Welcome to Java
Welcome t
o CS
Programming is fun

要点1

  • \n 放在““的中间,单独或者任何地方均可;

2. 打印表格

  • 使用%3d %5d打印后端对齐的数字和%3s %5s打印后端对齐的字符
System.out.printf("%3s  %5s  %5s\n", "a", "a^2", "a^3");//%3s 表示打印字符串string 然后包括打印的内容,前面加自身占3格,用于字符的最后一个letter对齐
for (int i = 1; i <= 4; i++) {//i=1 满足<=4 into 循环体,作完i=1,then i=i+1=2,      i=2,满足<=4,into,over,i=i+1=3,    i=3,满足<=4,into over,i=i+1=4,    i=4,....
   System.out.printf("%3d  %5d  %5d\n", i, i * i, i * i * i);
}

java程序设计-第一章_第1张图片
空空 a 空空空空 a ^ 2 空空空空 a ^ 3
后面的全部都是用%5d后端对齐

  • 关于\t
System.out.println("aaa \taa");
System.out.println("aaa\taa");

aaa空[Tab]aa
aaa空aa

要点2 域宽

  • %3d %5d打印后端对齐数字;%3s %5s打印后端对齐的字符
  • 如果域宽小于被打印数据的宽度,数据通常会在域内右对齐。如果输出值的宽度大于域宽时,域宽是自动增长的。域宽通常插在百分号和转换说明符之间
  • “%m.nf”:输出浮点数,m为宽度[域宽],n为小数点右边数位 ;
  • “%3.1f” 输入3852.99 输出3853.0

3. 求半径5.5的圆的周长和面积

private static final double radius = 5.5;//?PRIVATE 啥玩意

public static void main(String[] args) {

    double perimeter = 2 * radius * Math.PI;
    double area = radius * radius * Math.PI;

    System.out.println("Perimeter = " + perimeter);
    System.out.println("Area = " + area);
}

要点

  • private?干哈?
  • Math.PI

4.

(Area and perimeter of a rectangle) Write a program that displays the area and perimeter
of a rectangle with the width of 4.5 and height of 7.9

public static void main(String[] strings) {//这个args变成了string 有什么不同吗

    final double width = 4.5;
    final double height = 7.9;

    double area = width * height;

    System.out.printf("%.1f * %.1f = %.2f", width, height, area);//%.1f float?类型 只显示一位小数
}

要点4

  • public static void main(String[] strings) args与strings有什么不同吗?
  • %.1f :.1[点一]表示小数点后保留一位

Lab0

你可能感兴趣的:(1)