You are on page 1of 2

1

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

Memory
Output
Devices
Bus
How Data is Stored?
Various kinds of data
Numbers
Characters
Strings
A byte is the minimum
storage unit
E.g. J is represented by
01001010 in one byte
E.g. small number such
as 3 can be stored in a
single byte

.
.
.
2000
2001
2002
2003
2004



.
.
.
01001010
01100001
01110110
01100001
00000011



Memory content

Memory 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 representing
elementary 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

Compiler Source File Machine-language
File
Linker
Executable File
Library Code
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 the
console
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 <String "Welcome to
Java!">
5 invokevirtual #4
8 return

Saved on the disk
stored on the disk
Source code (developed by the programmer)
Byte code (generated by the compiler for JVM
to read and interpret, not for you to understand)

Java Bytecode
Java Virtual
Machine
Any
Computer
With Java, the source
program is compiled into
a special type of object
code, bytecode.
The bytecode can then
run on any computer
with a Java Virtual
Machine.
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