Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 1 - Friday COMP 1600.

Similar presentations


Presentation on theme: "Week 1 - Friday COMP 1600."— Presentation transcript:

1 Week 1 - Friday COMP 1600

2 Last time What did we talk about last time?
Finished discussing hardware Our first Java program

3 Project 1

4 Questions?

5 More Java Syntax

6 Semicolons In Java, like C, C++, and many other languages, we separate different statements with a semicolon ( ; ) If we want to do a number of statements, we just type them in order, with a semicolon after each one

7 Sequencing For example, instead of one print statement, we can have several: Each statement is an instruction to the computer They are printed in order, one by one System.out.println("Hello, world!"); System.out.println("Hello, galaxy!"); System.out.println("Goodbye, world!");

8 Case Sensitivity Java is a case sensitive language
Class is not the same as class System.out.println("Word!"); prints correctly system.Out.Println("Word!"); does not compile

9 Whitespace Java generally ignores whitespace (tabs, newlines, and spaces) is the same as: You should use whitespace effectively to make your code readable System.out.println("Hello, world!"); System.out. println( "Hello, world!");

10 Comments Programs can be confusing
Sometimes you want to leave notes for yourself or anyone else who is reading your code The standard way to do this is by using comments Although comments appear in the code, they do not affect the final program

11 Comments There are two kinds of comments (actually 3)
Single line comments use // Multi-line comments start with a /* and end with a */ System.out.println("Hi!"); // this is a comment System.out.println("Hi!"); /* this is a multi-line comment */

12 What we know Java is a large, complex language
Even so, there are only a few tasks that you can ask it to do You have already learned: Sequencing Basic output

13 Where we are headed There are not that many other things you can tell Java to do Storing numbers and text Basic mathematical operations Choosing between several options Doing a task repetitively Storing lists of things More complicated input and output Naming a task so that you can use it over and over again That's basically it

14 Software Development

15 What is programming again?
The process of giving computers very detailed instructions about what to do How do we do that exactly? First, we need a programming language like Java How do we turn a set of instructions written so that a human can read them into a set of instructions that a computer can read? Magic, of course!

16 First, let's talk about languages
There are many different programming languages: Java C/C++ ML …thousands more Each has different advantages in different situations

17 High vs. low We can classify languages as high or low level
High level languages allow you to give more abstract commands that are more like human thought processes or mathematics Low level languages are closer to the computer world and give explicit instructions for the hardware to follow Python Java C++ C Assembly Language Machine Code Low High

18 Compilers We use a program called a compiler to turn a high level language into a low level language Usually, the low level language is machine code With Java it's a little more complex

19 How does that work in general?
Computer! Solve a problem; Compile Execute Source Code Machine Code Hardware

20 What's the issue with Java?
Java is more complicated Java runs on a virtual machine, called the JVM Java is compiled to an intermediate stage called bytecode, which is platform independent Then, the JVM runs a just-in-time compiler whenever you run a Java program, to turn the bytecode into platform dependent machine code

21 Compilation and execution for Java
class A { Problem p; p.solve(); } Compile JVM Execute Java Source Code Java Bytecode Machine Code Hardware Platform Independent Platform Dependent

22 Let's review the steps we'll use
Write a program in Java Compile the program into bytecode Run the bytecode using the JVM (which automatically compiles the bytecode to machine code)

23 Software development Often goes through phases similar to the following: Understand the problem Plan a solution to the problem Implement the solution in a programming language Test the solution Maintain the solution and do bug fixes Factor of 10 rule!

24 Data Representation

25 Binary Hardware You have heard people talking about all the 1's and 0's inside of a computer What does that all really mean? Using semiconductor physics, we can make a tiny little piece of a microchip be in one of two states, say, OFF and ON, like a switch If we say that OFF is 0 and ON is 1, then, by using a lot of these switches, we can represent a lot of 1's and 0's

26 Binary Representation
What do we do with those 1's and 0's? To begin with, we represent numbers How many of you have heard of base 10? How many of you have heard of base 2? What's the definition of a number system with a given base?

27 Base 10 (decimal) numbers
Our normal number system is base 10 This means that our digits are: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 Base 10 means that you need 2 digits to represent ten, namely 1 and 0 Each place in the number as you move left corresponds to an increase by a factor of 10

28 3,482,931 Base 10 Example Ten thousands Hundreds Millions Ones Hundred
Tens

29 Base 2 (binary) numbers The binary number system is base 2
This means that its digits are: 0 and 1 Base 2 means that you need 2 digits to represent two, namely 1 and 0 Each place in the number as you move left corresponds to an increase by a factor of 2 instead of 10

30 11111100011 Base 2 Example Sixty fours 256's Sixteens Fours 1024's
Ones 512's 128's Thirty twos Eights Twos

31 So, what's the value? = 1∙ ∙29 + 1∙28 + 1∙27 + 1∙ ∙25 + 0∙24 + 0∙23 + 0∙22 + 1∙21 + 1∙20 = = 2019

32 The good news You don't actually have to worry about doing binary conversions when you are coding Java You should know this information because it explains how Java is different from math In math, you can talk about an arbitrarily large number In Java, each number is stored with a specific number of binary digits There are limits on how big (or small) a given number can be

33 Upcoming

34 Next time… We'll talk more about data representation

35 Reminders Read Chapter 3 No class on Monday!
No lab assignment on Tuesday, but you can come to ask questions or get started on Project 1 Interested in coaching 7-18 year old kids in programming? Consider working at theCoderSchool For more information: Visit Contact Kevin Choo at Ask me!


Download ppt "Week 1 - Friday COMP 1600."

Similar presentations


Ads by Google