课程网址(内含自学课程所需的全套资料):Main | CS 61B Spring 2018https://sp18.datastructur.es/
Week1
xterm commands终端指令:
cd
: change your working directorypwd
: present working directory.
: means your current directory..
: means one parent directory above your current directoryls
: list files/folders in directorymkdir
: make a directoryrm
: remove a filecp
: copy a filemv
: move or rename a file- tab键:自动补全文件名
更详细的解释:
Lab 1 Setup: Setting Up Your Computer | CS 61B Spring 2018https://sp18.datastructur.es/materials/lab/lab1setup/lab1setup簡易常用UNIX (LINUX) 指令
http://web.ncyu.edu.tw/~hckuo/Course/unix_cmd.html
Java相关指令:
javac:
is used to compile programs (compilation).
java:
is used to execute programs (execution), we must always compile before execution.
Python相关指令
python -i、或python3 -i、或winpty python:run python in interactive mode using git bash
quit(): to exit python
Git相关指令:
git init
: 初始化:Creates a box in which to permanently store panoramic pictures.
git add
: Takes a temporary photo of one thing that can be assembled into a panoramic photo later.
git commit -m
: Assembles all available temporary photos into a panoramic photo. Also destroys all temporary photos.
git log
: Lists all the panoramic photos we’ve ever taken.
git show
: Looks at what is in a particular panoramic photo.
git checkout
: Rearranges files back to how they looked in a given panoramic photo. Does not affect the panormiac photos in your box in any way.
gitk: GUI
git clone [remote-repo-URL]
: Makes a copy of the specified repository, but on your local computer. Also creates a working directory that has files arranged exactly like the most recent snapshot in the download repository. Also records the URL of the remote repository for subsequent network data transfers, and gives it the special remote-repo-name “origin”.
git remote add [remote-repo-name] [remote-repo-URL]
: Records a new location for network data transfers.
git remote -v
: Lists all locations for network data transfers.
git pull [remote-repo-name] master
: Get the most recent copy of the files as seen in remote-repo-name
git push [remote-repo-name] master
: Pushes the most recent copy of your files to the remote-repo-name.
更详细的解释:
曾参考的Debug文档:
Java基础1-环境篇:JDK安装与环境变量配置_第一段代码的博客-优快云博客_java环境
Java SE 6 vs. JRE 1.6 vs. JDK 1.6 - What do these mean? - Stack Overflow
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings - Stack Overflow
Sublime安装、破解、汉化、使用、教程(详解) - 云+社区 - 腾讯云
Git WTFS | CS 61B Spring 2018
CS 61B 搭建 Auto Grade 环境 - 知乎
Git报错解决:OpenSSL SSL_read: Connection was reset, errno 10054 错误解决_危险、的博客-优快云博客
HTTP/2 stream 1 was not closed cleanly before end of the underlying stream - 知乎
Java——语法跟c和c++非常像(将不一样的地方标红)
%: implements remainder
!=: compares two values for inequality
!:
is an unary negation operator that expects a single boolean
operand. Therefore it can't be applied on an int
.
+: concatenates strings, "horse"
+ "babies"
would return "horsebabies"
+=
public static: 可定义函数
, which is a very rough analog of Python's def
//、/* */: comments
System.out.println: 结尾带换行
System.out.print: 结尾不带换行
double someNumber = 1.03e-7:
Java supports scientific notation
条件
if(){
;//单行时{}可省略
}
else if(){
;
}
else{
;
}
max=m[i]>max?m[i]:max;
switch (month) {
case 2:
days = 28;
break;//若没有此句,则会just keep moving right on through.
case 4:
case 6:
case 9:
case 11:
days = 30;
break;
default:
days = 31;
break;
}
循环
while () {
;
}
do{
;
}while();
for (int i = 0; i < a.length; i = i + 1) {
if (a[i].contains("ab")) {
continue;
}
if (a[i].contains("cd")) {
break;//continue和break也适用于while和do while
}
}
String[] a = {"0", "1", "2"};
//the String s takes on the identity of each String in a exactly once,
//starting from a[0], all the way up to a[a.length - 1]
for (String s : a) {
s=="0";
}
数组
int[] numbers;//可直接int[] numbers = new int[3];
numbers = new int[3];
numbers[0] = 4;
numbers[1] = 7;
numbers[2] = 10;
int[] numbers = new int[]{4, 7, 10};
instance method和static method举例
public class Dog{
/*
Instantiating a class is almost always done using the new keyword, e.g. Dog d = new Dog().
An instance of a class in Java is also called an Object.
*/
public void bark(){//instance method
System.out.println("Moo");
}
public static void runFast(){//static method
System.out.println("Ruff Run");
}
public static void main(String[] args) {
Dog poppa = new Dog();
poppa.bark();
//Dog.bark();//编译错误
/*
error: non-static method bark() cannot be referenced from a static context
*/
poppa.runFast();//OK but not recommended
Dog.runFast();//可正常运行并输出Ruff Run
}
}
类的创建的举例
public class DogLoop {
public static void main(String[] args) {
Dog smallDog = new Dog(5);
Dog mediumDog = new Dog(25);
Dog[] manyDogs = new Dog[4];
manyDogs[0] = smallDog;
Dog.maxDog(manyDogs[0], mediumDog).makeNoise();
}
public static class Dog {//这里不是static的话会error
/* Size of the dog in standard dog size units. */
public int size;
/* This is a constructor. It tells us how to construct
* dogs from our ideal notion of dogness. */
public Dog(int s) {//注意这个是在创建的对象的里面
size = s;
}
public void makeNoise() {
if (size < 10) {
System.out.println("hideous yapping");
} else if (size < 30) {
System.out.println("bark!");
} else {
System.out.println("woof!");
}
}
/* Return the larger of dog d1 and dog d2. */
public static Dog maxDog(Dog d1, Dog d2) {
if (d1.size > d2.size) {
return d1;
}
return d2;
}
}
}
The this
keyword: Inside a method, we can use the this
keyword to refer to the current instance.
输入
public class ArgsDemo {
public static void main(String[] args) {
System.out.println(args[0]);
}
}
Javadocs
Comments contained by /**
and */,
also called “Javadoc comments.
Javdocs tags:
@source
: Use the @source
tag any time you receive significant help on a project.
更详细:
https://zh.wikipedia.org/wiki/Javadoc
https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javadoc.html
https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javadoc.html
代码规范
Style Guide | CS 61B Spring 2019
https://en.wikipedia.org/wiki/Indentation_style
Hello World
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
在线Java compiler
Java Tutor - Visualize Java code execution to learn Java online
官方Tutorial
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html
Java库
曾参考的Debug文档
java - Bad operand type int for unary operator '! in while statement - Stack Overflow
Java编译的时候,出现unmappable character for encoding GBK_、Edgar的博客-优快云博客
Week2
java.math包中提供的API类BigDecimal
使用举例:
import java.math.*;
//......其他代码
/**
* Rounds a double value to a number of decimal places.
*
* @param value Double to be rounded.
* @param places Integer number of places to round VALUE to.
*/
private static double round(double value, int places) {
if (places < 0) throw new IllegalArgumentException();
BigDecimal bd = new BigDecimal(value);
bd = bd.setScale(places, RoundingMode.HALF_UP);
return bd.doubleValue();
}
更详细的解释:
https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html
this.equals
Java自带的判断两个对象是否相等