programming fundamentals basics
TRANSCRIPT
-
8/11/2019 Programming Fundamentals Basics
1/2
Outline
Topics
Computer basics
Programming languages Simple Java program and method
Writing comments
Fun fact
The original name for Java is oak because of a big
oak tree that grew outside the developer's window. It
was eventually changed to Java
What is a Computer?
An electronic device that stores and
processes data
Hardware
Software
CPU
e.g., Disk, CD,
and Tape
Input
Devices
e.g., Keyboard,
Mouse
e.g., Monitor,
Printer
Communication
Devices
e.g., Modem, and
NIC
Storage
Devices MemoryOutput
Devices
Bus
How Data is Stored?
Various kinds of data
Numbers
Characters
Strings
A byte is the minimumstorage unit
E.g. J is represented by
01001010 in one byte
E.g. small number suchas 3 can be stored in a
single byte
.
.
.
2000
2001
2002
2003
2004
.
.
.
01001010
01100001
01110110
01100001
00000011
Memory contentMemory address
Encoding for character J
Encoding for character a
Encoding for character v
Encoding for character a
Encoding for number 3
Machine Languages
System of instructions and data directly
understandable by a computer's central
processing unit
Example:100011 00011 01000 00000 00001 000100
000010 00000 00000 00000 10000 000001
000000 00001 00010 00110 00000 100000
Every CPU model has its own machine
code, or instruction set, although there is
considerable overlap between them
Assembly Languages
Human-readable notation for the machine language that
a specific computer architecture uses representingelementary computer operations (translated via
assemblers)
Example:load hourlyRate
mul workHours
store salary
MUL R1, R2, R3
Assembly Source File
Assembler 1101101010011010
Machine Code File
High-level Languages
Higher level of abstraction from machine language
Codes similar to everyday English
Use mathematical notations (translated via compilers)
Example:
salary = hourlyRate * workHours
Make complex programming simpler
CompilerSource File Machine-languageFile
Linker Executable File
Library Code
http://en.wikipedia.org/wiki/James_Goslinghttp://en.wikipedia.org/wiki/James_Goslinghttp://en.wikipedia.org/wiki/James_Gosling -
8/11/2019 Programming Fundamentals Basics
2/2
A Simple Java Program
//This program prints Welcome to Java!
public class Welcome {public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
print a message to theconsole
The main method
program statement
Welcome.java
Creating, Compiling, and Running Programs
Source Code
Create/Modify Source Code
Compile Source Code
i.e., javac Welcome.java
Bytecode
Run Byteode
i.e., java Welcome
Result
If compilation errors
If runtime errors or incorrect result
public class Welcome {public static void main(String[] args) {
System.out.println("Welcome to Java!");}
}
Method Welcome()
0 aload_0
Method void main(java.lang.String[])
0 getstatic #2 3 ldc #3
5 invokevirtual #4
Saved on the disk
stored on the disk
Source code (developed bythe programmer)
Byte code (generated bythe compiler for JVMto read and interpret, not for you to understand)
Java Bytecode
Java VirtualMachine
AnyComputer
With Java, the sourceprogram is compiled into
a special type of object
code, bytecode.The bytecode can then
run on any computer
with a Java VirtualMachine.
Java Virtual Machine is a
software that interprets
Java bytecode
Method
A collection of statements that performs a
sequence of operations
System.out.println: a method to display a
message on the console
The string argument is enclosed within
parentheses
The main method provides the control of
program flow The Java interpreter executes the application
by invoking the main method
Comments
Three types of comments in Java
Line comment: A line comment is preceded by two
slashes (//) in a line
Paragraph comment: A paragraph comment is
enclosed between /* and */ in one or multiple lines
javadoc comment: javadoc comments begin with /**
and end with */
used for documenting classes, data, and methods
can be extracted into an HTML file using JDK's javadoc
command