190 likes | 314 Views
Diving in to Java. What is Computer Science?. 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. You can say ….
E N D
What is Computer Science? • 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
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
Modern Days • 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?
Machine Language • Machine language is what the computer understands • What the microprocessor understands • Machine language is defined by which microprocessor you have inside your computer
Can People Write Machine code? • 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
Examples of HLL’s • C • C++ • Basic • Fortran
So how do you go from High to Low? • 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)
Compilation process • 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
As a programmer • You write source code e.g. When you were writing Karel programs • Machine understands object code
Things get funky in JAVA Some intermediary language also known as Java Byte code
So why have this extra process? • 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
JVM is essential to run JAVA programs • It is important to install JRE (Java Runtime Environment) • The class file can be run on any computer using the JRE on any machine
Java is Object Oriented • 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
What is a class? • 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
Classes as Hierarchy • 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
Super class Karel Super Class Super Karel Sub Class
Example of classes Digest food Blastula stage Animals Warm Blooded Have memory glands Five fingers Highly developed brains Monkeys