introduction to programming with java, for beginners machine vs. programming language intro to java...
Post on 22-Dec-2015
215 views
TRANSCRIPT
Introduction to Programming with Java, for Beginners
Machine vs. Programming Language
Intro to Java
Edit-Compile-Run Program Process
2
Outline What do computers understand? Machine Language vs. Programming
Language Introduction to Java Process of Computer Programming Write, Compile and Run Java Program
3
Recap A programming language
a language that you can learn to write, and the computer can be made to understand
We will learn Java in this course But before we jump into Java, lets know a
computer a little bit
4
What Computers are good at? Doing calculations and comparisons
Producing the same answer every time Like calculating the sum of hundreds of numbers
Storing information Mostly do not forget information
Looking up information quickly Search through a phone book to find the customer
name for a phone number
5
Computer’s Anatomy Consists of:
Central Processing Unit (CPU) a.k.a processorBasically does all the calculation e.g. addition
MemoryStores Information (instructions or data)RAM (volatile) and Hard Drive (Non-volatile)
Input/Output DevicesCommunicate with the outside world (e.g.
keyboard, mouse)
6
What does the Computer Understand? At the lowest level, a computer has electronic “plumbing”
Operates by controlling the flow of electrons through very fast tiny electronic devices called transistors
The devices react to presence or absence of voltage Could react actual voltages but designing electronics then
becomes complex
Symbolically we represent
1. Presence of voltage as “1”
2. Absence of voltage as “0”
7
What does the Computer process & store?
An electronic device can represent uniquely only one of two things Each “0” and Each “1” is referred to as a Binary Digit or Bit Fundament unit of information storage
To represent more things we need more bits E.g. 2 bits can represent four unique things: 00, 01, 10, 11 k bits can distinguish 2k distinct items
Combination binary bits together can represent some information or data. E.g. 00101001 can be1. Decimal value 41 2. Alphabet (or character) ‘A’ in ASCII notation3. Command to be performed e.g. Performing Add operation
8
Machine Language Computers understand only 0’s and 1’s
A.k.a Machine Language Very tedious for “Humans” to deal with 0’s or 1’s
9
Programming to Machine Language
The compiler translates the programming language into a specific machine language Specific Machine: Electronic Hardware + Operating
System e.g. Intel Process + Windows XP vs. Intel processor
+ Mac OS
Once translated (Programming -> Machine) The same program cannot run on different machine
Java avoids the above problem Code is portable - Write one run anywhere! One of the features for popularity of Java
10
Java Compiler andVirtual Machine
The Java Compiler Reads file with extension .java Checks syntax / grammar Creates a .class file which
contains byte code (machine code) independent of any machine
Java Byte Code Is portable
The JVM(Java Virtual Machine) Translates byte code in to
instructions for a particular processor, which “runs the program”
11
Other Features of Java Has Graphical User Interface Capability
Create interactive programs Stand alone Java Applications that can be executed on any
computer that has JVM
Create Dynamic Web PagesJava Applets are programs that can run in Browser (e.g.
Internet Explorer or Firefox) that has Java PluginJava Servlets are programs that can run machines hooked
up to internet (server)
Gained popularity in gadgets such as PDAs, cell phones etc.
12
Editions of Java Java SE
“Standard Edition” (currently at version 6.0) For desktop applications
Java ME “Micro Edition” For gadgets such as smart phones or personal digital
assistants
Java EE “Enterprise Edition” For Java programs that run on web servers
Website: http://java.sun.com/
13
Things needed for Java Program
JRE, Java Runtime Environment This is the software that allows you to run Java
programs on your computer Called either “the JRE” or “the runtime”
JDK, Java Development Kit The software that allows you to create and run Java
programs on your computer When you install the SDK, you get a JRE along with it
14
Java Books Online: See the Resources page on course website
Java Backpack Reference Guide By Peter J. DePasquale Useful, concise reference
Others An Introduction to Problem Solving and
Programming” (4th Edition) by Walter Savitch Head First Java by Kathy Sierra and Bert Bates
15
Process of Computer Programming
To come up with a computation solution
Remember that Rome was not built in one day!! Program in pieces, and test before writing the whole
solution
Edit
(Syntax + Semantics)
Compile
Run
(observe your output)
Compile-time
or Syntax ErrorRun-time
or Semantic
Error
16
Process I Writing Programs
Use any regular text editor Write Java style program and save the file as
filename.java.
Exercise on Linux OS: Save Hello.java in your directory from course website Open Terminal Window
Users interacted with the computer with terminal window before GUI
You should see: “username@ …>”
17
Process I (contd..) Type “ls” to see contents of your disk
ls is command that displays files & directory username@...> ls
Type “cd” to change directory/folder where Hello.java is saved cd means change directory E.g. cd Desktop
18
Process I (contd..) Compiling Java on a “Linux OS”
Type: export PATH=/usr/java/jdk1.5.0_04/bin/This tells xterm where to find the java compiler
To compile type: javac Hello.java If no compiler errors you should see Hello.class in
your program1 directoryTo see whether your directory contains type “ls”
Executing/Running your program At the command prompt type: java Hello You will find the word “Hello World” printed
19
Process I (contd..) This process is not straight forward
Need to know commands such as cd, lsCommands can different on different Operating
System e.g. On Windows “ls” is “dir”
Regular text editors do no highlight or color certain features that tell us that this a java program There are better editors that highlight the
language syntax
20
Process II Simpler way!!
Use Integrated Development Environment (IDE) Another software program that makes it easier to
write, compile and run programs We’re going to use the free Dr. Java IDE
Activity Dr Java Tutorial