source code basics. code for a computer to execute instructions, it needs to be in binary each...

16
Source Code Basics

Upload: jerome-cameron

Post on 23-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Source Code Basics. Code For a computer to execute instructions, it needs to be in binary Each instruction is given a number Known as “operation code”

Source Code Basics

Page 2: Source Code Basics. Code For a computer to execute instructions, it needs to be in binary Each instruction is given a number Known as “operation code”

CodeFor a computer to execute instructions, it needs to be in binary• Each instruction is given a

number• Known as “operation code”• Collection of these is what a

program “binary” is

Page 3: Source Code Basics. Code For a computer to execute instructions, it needs to be in binary Each instruction is given a number Known as “operation code”

Op Codes

Page 4: Source Code Basics. Code For a computer to execute instructions, it needs to be in binary Each instruction is given a number Known as “operation code”

Punch Cards

Page 5: Source Code Basics. Code For a computer to execute instructions, it needs to be in binary Each instruction is given a number Known as “operation code”

But…

Page 6: Source Code Basics. Code For a computer to execute instructions, it needs to be in binary Each instruction is given a number Known as “operation code”

Machine Code• Punch-card like instructions still used today–Called machine code, or (technically incorrect)

assembly language

• Now we convert human-readable instructions into this

• What a program “binary” is. What companies sell and is too complex to figure out how it works exactly… but sometimes….

Page 7: Source Code Basics. Code For a computer to execute instructions, it needs to be in binary Each instruction is given a number Known as “operation code”

Source• Enter 2nd generation

programming languages–First (most significantly) C–C++– Java

• More for humans – using English words

Page 8: Source Code Basics. Code For a computer to execute instructions, it needs to be in binary Each instruction is given a number Known as “operation code”

C++ and Java

Page 9: Source Code Basics. Code For a computer to execute instructions, it needs to be in binary Each instruction is given a number Known as “operation code”

JVM• Sometimes called the Java

Runtime Environment (JRE)• The java program is the JVM/JRE• Is why Java is secure (checks

and controls java code, isolates it) and portable (java code just needs to worry about the JVM)

Page 10: Source Code Basics. Code For a computer to execute instructions, it needs to be in binary Each instruction is given a number Known as “operation code”

Languages: C++C++• Pro: Fast!• Con: Have to worry about so

many details, complex -> slow to implement (just like machine code)

Page 11: Source Code Basics. Code For a computer to execute instructions, it needs to be in binary Each instruction is given a number Known as “operation code”

Languages: JavaJava• Pro: Worry about less (e.g.

memory), fully object oriented (more in line with real world), less machine oriented

• Con: Slow (mostly) run speed, very slow load speed

Page 12: Source Code Basics. Code For a computer to execute instructions, it needs to be in binary Each instruction is given a number Known as “operation code”

Languages: 4th GenerationRuby, Swift, Python, Shell • Pros: Worry about even less, more

human centric (even like natural language), higher programmer efficiency

• Cons: Even slower (but computers are getting faster), loss of control over some things (like memory)

Page 13: Source Code Basics. Code For a computer to execute instructions, it needs to be in binary Each instruction is given a number Known as “operation code”

4th Generation• Non-compiled• Java and C# is halfway (still compile for the

interpreter)• Likely to dominate most programming as

computers speed up and problems get more complex

• Interpreter is like the JVM, each language needs one (ruby, python, sh)

• Bad for learning… hide too many fundamentals

Page 14: Source Code Basics. Code For a computer to execute instructions, it needs to be in binary Each instruction is given a number Known as “operation code”

The PointNever have a general argument about which language is “better”• Always pros and cons. There are

tradeoffs• Only which language is best for

the given problem or project

Page 15: Source Code Basics. Code For a computer to execute instructions, it needs to be in binary Each instruction is given a number Known as “operation code”

Java SourceJava enforces rules:• Every source code file must be .java• Every file must have a matching class

definition with exact same name (case sensitive!)

• Brackets {} groups “blocks” of code• All normal code must belong to a class

Page 16: Source Code Basics. Code For a computer to execute instructions, it needs to be in binary Each instruction is given a number Known as “operation code”

Example Java