Week 5 – Diving into Java

Download Report

Transcript Week 5 – Diving into Java

1
• Its all about the science/study to
problem solving using computational
devices
• How efficient is the solution?
• Programming is an artifact which is
part of the process a technique
2
You can say …
• Computer Science is just as much about
programming as Astronomy is about
building telescopes
• Astronomy is much more than just building
telescopes
• It’s a science of studying celestial bodies
• Telescopes are just a mechanism to study
the science
3
• The computer actually only
understands 0’s and 1’s
• Binary is a number system that has just
0 and 1. Its base is 2 numbers
• So how can we take these commands
like move or turn left and turn them
into 0’s and 1’s?
4
• Machine language is what the
computer understands
• What the microprocessor understands
• Machine language is defined by which
microprocessor you have inside your
computer
5
• People are really bad when it comes to
writing 1’s and 0’s
• So we program in what is known as a
High Level Language
• There are all kinds of HLL’s
• One of the high level languages you’re
going to learn in this class is Java
6
•C
• C++
• Basic
• Fortran
7
• We program in a high level language
because its level is higher than that of
machine language
• There is a translation process
• High Level -> Low Level (Machine
Level)
8
• To go from a high level to low level is
called “Compilation”
• This is achieved by a compiler
• Eclipse that you have been using along
is a compiler
• It converts the high level language into
something that the machine can
understand
9
• You write source code e.g. When you
were writing Karel programs
• Machine understands object code
10
11
Some intermediary
language also
known as Java Byte
code
12
• Well guess what?
• In the world there are Macs, PC’s,
Linux and all kinds of machines
• And the 1’s and 0’s that a Mac speaks
are different to the 1’s and 0’s that a
PC speaks and different to the 1’s and
0’s that the Linux speaks
13
• It is important to install JRE (Java
Runtime Environment)
• The class file can be run on any
computer using the JRE on any
machine
14
• The idea is a program is written in a
bunch of classes
• Lets refer to Karel
• public class KarelProgram extends
Karel
• Java program is a set of classes
15
• A class is just an encapsulation of some
behavior that the program does and
data
• Like Karel’s programs use some
movement so that is behavior and then
you have some data
16
• Remember you wrote a class which
extends Karel and gives you the basic
functionality of Karel
• And then we extended SuperKarel
which gave us even more functions like
turnRight
Karel
SuperKarel
Subclass
17
Karel
Super Karel
Super Class
Sub Class
18
Example of classes
Animals
Digest food
Blastula stage
Warm Blooded
Have memory
glands
Five fingers
Highly developed
brains
Monkeys
19