java程序设计-第一章

2023-05-16

第一章

    • 教材知识点、概念
      • 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);
}

表格打印结果
空空 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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

java程序设计-第一章 的相关文章

  • Ubuntu22.04 安装深度微信报错 依赖: libsasl2-2 (>= 2.1.27.1)

    现象 xff1a span class token punctuation span base span class token punctuation span pang 64 pang HP span class token funct
  • Ubuntu22.04更新后 点击深度微信无反应

    系统版本 xff1a Ubuntu 22 04 jammy内核 xff1a x86 64 Linux 5 15 0 53 genericdeepin wine6 stable 版本 xff1a 6 0 0 41 1 深度微信图标点击后 xf
  • MySQL笔记-08 索引

    文章目录 1 索引概述1 1 MySQL索引分类1 1 1 普通索引1 1 2 唯一性索引1 1 3 全文索引1 1 4 单列索引1 1 5 多列索引1 1 6 空间索引 2 创建索引2 1 在建立数据表时创建索引2 1 1 普通索引创建2
  • MySQL笔记-09 视图

    文章目录 1 视图概念1 1 概念1 2 作用 2 创建视图2 1 查看创建视图的权限2 2 创建视图的步骤2 3 创建视图的注意事项 3 视图操作3 1 查看视图3 1 1 DESCRIBE语句3 1 2 SHOW TABLE STATU
  • MySQL笔记-10 数据完整性约束

    文章目录 1 定义完整性约束1 1 实体完整性1 1 1 主键约束1 1 2 候选键约束 1 2 参照完整性1 3 用户定义完整性1 3 1 非空约束1 3 2 CHECK约束1 3 2 1 对列实施CHECK约束1 3 2 2 对表实施C
  • Linux命令行笔记-00 综述

    文章目录 1 Linux命令行简介1 1 Linux命令行的分类1 1 1 根据系统中作用来分类1 1 2 根据对象来分类 2 Linux命令行解释器2 1 命令行解释器shell2 1 1 核心程序2 1 2 公用程序shell2 1 3
  • Linux命令行笔记-01 文件管理-文件的建立、移动和删除

    文章目录 1 文件的建立 移动和删除1 1 96 cat 96 建立文件1 1 1 语法格式与参数1 1 2 示例 1 2 96 touch 96 建立文件1 2 1 语法格式与参数1 2 2 示例1 2 3 注意 1 3 96 ln 96
  • CMake学习-01 综述

    文章目录 1 CMake1 1 CMake生成makefile并编译的流程 2 CMakeLists txt2 1 Demo讲解2 2 常用命令2 2 1 指定CMAKE的最低版本2 2 2 设置项目名称2 2 3 设置变量2 2 4 设置
  • Rust:官方迭代器大全

    一 for 和迭代器 先看一段代码 xff1a span class token keyword fn span span class token function definition function main span span cl
  • Rust: 函数的重载——我做的的一组小实验

    编程的时候 xff0c 我发现有不少函数能够根据左值类型自动调用重载函数 但是 xff0c 我知道 Rust 的函数是不支持重载的 所以我打算尝试一下这一 重载 现象是如何实现的 一 Rust 不支持函数重载 写一段代码 xff1a spa
  • php产生大量session文件导致报错无法创建修改文件:no space left on device

    阿里云SLB健康检测后端服务器组产生百万级别的php的0k大小session文件 今天早上在登录公司一台阿里云的服务器上vim修改配置文件以及touch文件时报错 xff1a no space left on device df h 查看了
  • Rust: Native Windows GUI下载、安装、演示入门

    上 github 下载 xff0c 网址为 https github com gabdube native windows gui 上面有安装说明 按说明方法 xff0c 老是提示权限不够 配置了 ssh 公钥证书 xff0c 仍然不行 请
  • Rust: Native Windows GUI 入门第一课,程序结构剖析

    基于派生宏的代码实例 Cargo toml 文件 span class token punctuation span package span class token punctuation span name span class tok
  • 通过两个神经元的极简模型,清晰透视 Pytorch 工作原理

    解剖麻雀 xff0c 是分析了解复杂问题的好办法 本文通过搭建只有两个神经元的网络 xff0c 从根本上剖析 Pytorch 工作原理 先附上全部源代码 xff0c 然后听我慢慢唠 xff01 span class token keywor
  • Cifar-10 数据格式分析

    Cifar 10 的介绍可去官网阅读 xff0c 也可参照我之前整理的 笔记 xff1a CIFAR 01 和 CIFAR 100 数据集内容和格式详解 1 下载 Cifar 10 数据 本文下载了 Cifar 10 的 Python 语言
  • 准确率(Accuracy)、精度(Precision)、召回率(Recall)和 mAP 的图解

    机器学习的评价指标让人眼花缭乱 以前我写过一篇笔记总结了这个话题 xff0c 有兴趣的可以参考一下 xff1a 一分钟看懂深度学习中的准确率 xff08 Accuracy xff09 精度 xff08 Precision xff09 召回率
  • conda 基本用法

    好久不用超算服务器了 xff0c 今天远程登陆一下 xff0c 发现以前写的代码都不能运行了 鼓捣半天 xff0c 忽然想起来 xff0c 需要设置 conda 环境才行 写此小结 xff0c 汇总一下 conda 的基本用法 很久以前安装
  • jupyter 基本用法

    前一段时间 xff0c 同事帮我在超算服务器安装了一套 jupyter notebook 软件 xff0c 甚是好用 但用了几天后 xff0c 忽然就不能用了 今天研究了一下 xff0c 发现是服务器程序关闭了 xff0c 所以我在浏览器端
  • pytorch模型的保存与加载

    torch save 与 torch load 模型保存有两种形式 xff0c 一种是保存模型的 state dict xff0c 只是保存模型的参数 那么加载时需要先创建一个模型的实例 model xff0c 之后通过 torch loa
  • 用 SDK Mamager 安装 Nano

    用 SDK Mamager 安装 Nano 一 安装 sdk manager 在 PC 机上 Ubuntu 环境下 xff0c 下载 sdk manager 安装包 xff0c 用鼠标点击后自动运行 界面上有 Install 字样 xff0

随机推荐

  • TensorRTx 开源代码内容说明

    TensorRTx 提供了把常见网络模型转化为 TensorRT 格式的功能 TensorRTx旨在使用tensorrt网络定义API实现流行的深度学习网络 tensorrt有内置的解析器 xff0c 包括caffeparser uffpa
  • 关于在ubuntu下用docker部署Django卡在 Watching for file changes with StatReloader 不动了 以及 run后无法访问web 的问题

    1 问题描述 xff1a 用docker部署Django时遇到问题如下 xff1a 卡在这里不动了 xff0c 等了半小时服务也没起来 我的dockerfile如下 xff1a 直接启动没有问题 xff1a 用exec命令在容器内直接起也没
  • 漫话线性代数:线性变换的几何解释

    网购了一本书 xff0c 说的是线性代数的几何解释 一口气读完 xff0c 感觉这部书有些贪多了 xff0c 什么细节都要弄个几何解释 xff0c 不免让琐碎的细节把关键性的主题给遮掩了 所以萌生一个念头 xff0c 把线性代数的核心概念和
  • ChatGPT 逆天测试,结局出乎预料

    目录 一 数学解题能力二 编程能力三 日常生活咨询四 问一些离谱的问题 xff0c 它有啥反应 xff1f 五 逆天大测试 一 数学解题能力 据说 ChatGPT 会做数学题 xff0c 给他几个条件不充分的问题 xff0c 看看他是否真的
  • 我发现 chatGPT 在智能客服方面一个逆天的应用呀

    chatGPT 有助于快速构建知识库 xff0c 想了一个有趣的例子 xff0c 感觉 chatGPT真是强大呀 xff01 废话不多讲 xff0c 直接看效果吧 xff1a
  • 在 WIndows 下安装 Apache Tinkerpop (Gremlin)

    一 安装 JDK 首先安装 Java JDK xff0c 这个去官网下载即可 xff0c 我下载安装的 JDK19 xff08 jdk 19 windows x64 bin msi xff09 xff0c 细节不赘述 二 去 Tinkerp
  • 阅读笔记:TF - IDF 原理

    今天查阅 TF IDF 资料 xff0c 发现百度百科里面提供了一个例子 xff0c 解释的很清楚 xff0c 记下来备用 原文链接 xff1a https baike baidu com item tf idf 8816134 fr 61
  • 词向量语义匹配:欧氏距离和余弦相似度,选择哪一个?

    最近做自然语言处理算法 xff0c 需要根据词向量判断两个词汇的相似度 面临两个选择 xff1a 欧氏距离和余弦相似度 选择哪一个好呢 xff1f 一 概念图解 为便于理解这个问题 xff0c 假设词向量是二维的 我们分析一下这两种方法计算
  • 一分钟理解 AP(Affinity Propagation) 亲和⼒传播算法

    这篇博客发出来后 xff0c 我用 Rust 复现代码出现问题 为此 xff0c 我对对照了 sklearn 的相关代码 xff0c 反复比较了两天 xff0c 发现一处 bug xff0c 把 43 61 误写成了 61 xff0c 导致
  • 机器学习:准确率(Precision)、召回率(Recall)、F值(F-Measure)、ROC曲线、PR曲线

    增注 xff1a 虽然当时看这篇文章的时候感觉很不错 xff0c 但是还是写在前面 xff0c 想要了解关于机器学习度量的几个尺度 xff0c 建议大家直接看周志华老师的西瓜书的第2章 xff1a 模型评估与选择 xff0c 写的是真的很好
  • (5)细菌实验分组

    描述 有一种细菌分为A B两个亚种 xff0c 它们的外在特征几乎完全相同 xff0c 仅仅在繁殖能力上有显著差别 xff0c A亚种繁殖能力非常强 xff0c B亚种的繁殖能力很弱 在一次为时一个小时的细菌繁殖实验中 xff0c 实验员由
  • Python you-get 库 + FFmpeg 工具下载B站视频

    Python you get 库 43 FFmpeg 工具下载B站视频 电脑系统 xff1a Windows 10 准备阶段 xff08 安装you get和FFmpeg xff09 安装其实非常简单 xff0c 出现问题可以在网上参考其他
  • 虚拟机的创建、Linux相关基本命令等

    作业内容 xff1a 1 重新创建一个虚拟机 xff0c 熟悉下步骤 创建一个新的虚拟机 xff1a 1 点击 xff1a 创建新的虚拟机 2 下一步 3 提前下载一个镜像文件 xff0c 选择该文件即可 xff08 下载地址 xff1a
  • 解决mysql8.0主从配置,从库连接报错:Authentication plugin ‘caching_sha2_password‘ reported error

    其他配置都是按照网上分享的流程 xff0c 但是show slave status 查看从库状态时 xff0c Slave IO Running 61 connecting xff0c 这个状态是不对的 xff08 正常的Slave IO
  • windows10下visual studio 2019安装以及cuda11配置

    安装visual studio 2019 进入官方的下载页面 xff0c 可能需要登录 xff0c 登录后选取社区版下载 注意 xff0c 这里只是下载安装器 xff0c 真正的安装会在后续执行文件 xff0c 配置安装目录后 xff0c
  • Go语言基础语法_1_2021-10-28

    序言 xff1a 本身 xff0c 我是一个Java开发者 xff0c 但是最近在学习Java虚拟机 xff0c 但是看来看去总是不明白Java虚拟机是怎样实现的 xff0c 而有一本书是 自己动力手写Java虚拟机 xff0c 是用go语
  • debian(Linux)系统下安装jdk1.8

    第一步 xff1a 下载安装包 下载Linux环境下的jdk8 xff0c 请去 xff08 Java Downloads Oracle xff09 中下载jdk的安装文件 xff1b 由于我的Linux是64位的 xff0c 因此我下载j
  • Codeblocks自动代码格式化

    在代码框里点右键 xff0c 按Format use Astyle就会自动代码格式化了 但是它默认的风格是大括号另起一行 xff0c 很不习惯 xff0c 实际上是可以改的 1 Setting gt Editor gt Source For
  • 无法找到输出设备?

    希望我的方法能帮到你 我的电脑是联想 系统是win11 上次更新之后 扬声器就不能用了 右下角的喇叭是一个叉叉 一直没有放在心上 今天解决了一下 右键显示叉叉的喇叭 gt 希望我的方法 能帮到你
  • java程序设计-第一章

    第一章 教材知识点 概念1 2 什么是计算机1 3 编程语言1 4操作系统 Operating System1 5 操作系统1 6 1 7 1 8 1 10关键术语 教材quiz1 如何换行要点12 打印表格 要点2 域宽3 求半径5 5的