抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

Before Class

Resources here

Text book

Algorithms, 4th Edition

CS61B Exams and Solutions

COS226 Spring 2008 Midterm Solution

COS226 Fall 2008 Midterm Solution

COS226 Fall 2009 Midterm Solution

CS61B Fall 2009 Exam Solutions (Final, Midterm, Midterm2, Midterm3)

COS226 Fall 2010 Midterm Solution

COS226 Fall 2011 Midterm Solution

COS226 Spring 2012 Midterm Solution

COS226 Fall 2012 Midterm Solution

COS226 Spring 2013 Midterm Solution

CS61B Fall 2014 Test Solutions (Final, Final2, Final3, Midterm, Midterm2)

CS61B Spring 2016 Midterm2 Walkthrough

CS61B Spring 2017 Midterm2 Walkthrough

CS61B Spring 2016 MT1, Spring 2017 Exam Prep, Spring 2018 MT1, Spring 2019 MT1, Spring 2019 MT2, Fall 2020 MT1

CS61B Spring 2019 Discussion

CS61B Fall 2020 Discussion

Entry Code For GradeScope

You should select your university as UC Berkeley.

sp18: MNXYKX

sp21 code: BP25V6

sp22 code: 743W56

I would like to choose sp18, which is the most classic one and have a total function of the lab.

Lecture 01

More detailed here: ](https://joshhug.gitbooks.io/hug61b/content/chap1/chap11.html

Things about the course

I don’t care actually. After all I’m a worldwide student.

Things about Java

Java is an object oriented language with strict requirements

  • Every Java file must contain a class declaration (This is not completely true, e.g. we can also declare “interfaces” in .Java files that may contain code. We’ll cover these later.).

  • All code lives inside a class*, even helper functions, global constants, etc.

  • To run a Java program, you typically define a main method using public static void main(String[] args)

Java and Static Typing

Java is statically typed!

  • All variables, parameters, and methods must have a declared type.

  • That type can never change.

  • Expressions also have a type, e.g. “larger(5, 10) + 3” has type int.

  • The compiler checks that all the types in your program are compatible before the program ever runs!

    • e.g. String x = larger(5, 10) + 3 will fail to compile.
    • This is unlike a language like Python, where type checks are performed DURING execution.

Reflections on Static Typing

The Good:

  • Debugging is a lot easier, type errors are avoided.
  • Produciton code has no type errors, so that means people’s phones won’t crash because of type errors.
  • Programs run more efficiently in time and memory.
  • Self-documenting: YOU KNOW WHAT YOU’VE GOT.

The Bad:

  • Code is more verbose.
  • Code is less general.

Basic Rules

  • ALL code in Java must be part of a class.

  • We delimit the beginning and end of segments of code
    using { and }

  • All statements in Java must end in a semi-colon.

  • For code to run we need public static void main(String[])

Vars

  • Before Java variables can be used,they must be declared.

  • Java variables must have a specific type.

  • Java variable types can never change.

  • Types are verified before the code even runs!

Define a Function

  • Functions must be declared as part of a class in Java. A function that is part of a class is called a “method”. So in Java, all functions are methods.

  • To define a function in Java,we use “public static”.We will see alternate ways of defining functions Later.

  • ALl parameters of a function must have a declared type, and the return value of the function must have a declared type. Functions in Java return only one value!

  • We use /** comments here */ to describe what a function does. You could also add tags like this @bugfix.

Lab 1

](https://sp18.datastructur.es/materials/lab/lab1setup/lab1setup

So easy.

Notice: If you enter Chinese Characters, you should open the control pannel, go to: Clock & Area -> Area -> Management -> Program not using unicode -> Select the beta option.
However, some pre-installed software may have some configure issues.

We strongly recommend you to install jdk 18, which use utf-8 as default. If there’s problems, try to input chcp 936 in the powershell.

However, we strongly recommend you to use an IDE like IDEA, which will solve the code problem more clever.

In the last, we strongly recommend you to use linux-based system to develop or try to avoid Chinese characters.

评论