Intro to Java (Discussion 1) (Nhập môn Java) - Christine Zhou

UN
Uni24h
0 downloads
14
0

Document content

Page 3

Introductions & About Me - Christine, 3rd year - Email: cazhou@berkeley.edu - Feel free to email me! - Always available to chat one-on-one - What is your name, year, major?

Page 4

Announcements - Lab1 is due tonight at 11:59PM. - HW0 is due this Friday at 11:59PM. - Office hours and discussion/lab calendars on the course website. - Discussion survey: shoutkey.com/leak

Page 5

Git - VCS (version-control system), can save your work and go back to previous versions very easily - You have a central repository living somewhere stored by git - You can use ‘git clone’ to get a copy of this central repository anywhere you want (ie. on your local computer and instructional account) - When you ‘git add X.java’, ‘git commit -m “...”’, and ‘git push’, you are sending your work to the central repository - Not to other copies of the repository!

Page 6

Some Git Commands to Know - Camera analogy - git add: take a snapshot of your files (this is called staging your changes) - git commit: save the snapshot that you took with a message - git push: pushes snapshots from your repo to the central repo - git pull: pulls snapshots from the central repo to your repo - git status: shows the status of your repo - git log: shows all the snapshots/corresponding messages you’ve made on your repo - git tag: mark a specific snapshot with a tag

Page 7

1. Javaian Rhapsody - Variable assignments, to different types (String, int, Singer) - String and int are provided in Java, Singer is a self-defined class!

Page 8

1. Javaian Rhapsody (continued) - While loops will continue as long as the condition is true - Condition in this case is x>0 - Possible to loop infinitely if the condition is always true - Maybe we forget to decrement x?

Page 9

1. Javaian Rhapsody (continued) - Create arrays in Java with the bracket notation, can access with indexing - For loops: for (instantiation; condition; incrementation) - Will do what is within the brackets until the condition is false - System.out.print or System.out.println: how we print in Java!

Page 10

2. Fibonacci - Remember: fib(N) = fib(N-1) + fib(N-2) - The 0-th fibonacci number is 0, the 1st is 1, etc.

Page 11

2. Fibonacci (continued) - Too many redundant calculations when done recursively… - What other way can we approach this?

Page 12

2. Fibonacci (continued) - Look at how we did the problem iteratively - Do the arguments of fib3 sound familiar to what we did in fib2?

Page 13

3. Mystery - Keep track of the variables when running through the example! - To determine what it’s doing, try to figure out what each of the variables stand for!

Page 14

3. Mystery (continued) - Keep track of variables when running through an example? - What does targetIndex represent? (What does mystery do?)

Showing the first 14 pages. Download the document to see it all.

Comments (0)

Sign in to join the discussion

No comments yet. Be the first!