700 likes | 827 Views
COP3502 Programming Fundamentals for CIS Majors 1. Instructor: Dr. Parisa Rashidi. C omputer basics What is Java? API , IDE, and JDK W rite a simple program in Java Console output GUI Understand the basic syntax of Java. Computing Basics. Hardware, software, etc.
E N D
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Dr. Parisa Rashidi
Computer basics • What is Java? • API, IDE, and JDK • Write a simple program in Java • Console output • GUI • Understand the basic syntax of Java
Computing Basics Hardware, software, etc.
Hardware • Operating Systems • Software From Wikipedia, the free encyclopedia
Basic hardware components of a computer • CPU • Memory • Storage • I/O (Input/Output) • Communication devices CPU Communication Devices Input Devices Output Devices Memory Storage Devices BUS
CPU = Central Processing Unit • Speed measured in MHz • 1 MHz = 10^6 pulses per second • Executes instructions retrieved from memory
We are talking about RAM • Random Access Memory • Volatile • Stores data • A sequence of bytes • Each byte = 8 bits • Each bit can be 0 or 1 Memory (sequence of bytes) Byte (8 bits) Bit
All data is encoded as 0-1 • Byte = minimum storage unit • Large numbers are stored in more than 1 byte Memory Content Memory Address . . . Encoding for character ‘J’ Encoding for Character ‘a’ Encoding for character ‘v’ Encoding for Character ‘a’ Encoding for number 2 . .
Quick reminder • Byte = minimum storage unit • KB = 10^3 Bytes • MB = 10^6 Bytes • GB = 10^9 Bytes • TB = 10^12 Bytes • PB = 10^15 Bytes
Memory is volatile • Store programs & data on non-volatile devices • Hard disks (now TB) • CD (700 MB) • DVD (4.7 GB) • Blu-ray (25-100 GB) • USB Flash drive (now 256 GB)
Monitor Display • Quality • Resolution • number of pixels per square inch • E.g. 1024 by 768 • Dot pitch • amount of space between pixels Dot pitch
Modem • Uses a phone line • Speed = 56,000 bps (bits per second) • DSL • Uses phone line • 20 times faster than modem • Cable modem • Uses TV cable line • Speed same as DSL • NIC • Used in local area networks • E.g. 10BaseT has speed of 10 Mbps
Controls all programs • Manages hardware resources • Examples • Windows 7 • Ubuntu • MacOS
Textbook • Lab sections • Mailing List • W. 8-9 (3-5 pm) W. 10-11 (5-7pm) • Th. 2-3 (3-5 pm) Th. 10-11 (5-7 pm) • any section W. 2-3
Every operating system, application and mobile app has been written in some programming language
There are many programming languages • COBOL (1959) • FORTRAN (1957) • BASIC (1964) • Visual Basic (1991) • Pascal (1970) • Delphi (1986) • Ada (1980) • C (1972) • C++ (1983) • Objective C (1983) • C# (2001, a Java-like language by Microsoft) • …
Wewill be using Java (1991) Duke: Java’s Mascot
Some famous applications written in Java • Mars exploration rover • Hubble telescope • Vuze • Minecarft • Android (mostly)
High level language (Java) • Assembly Language • Machine language Difficulty of programming
Machine language • The language of CPU • Each CPU family has its own instruction set • Patterns of bits corresponding to different commands • E.g. To add two numbers instruction: • 1101101010011010
Assembly language • Easier than machine language • E.g. To add two numbers instruction: • mov ax, aadd ax, bmov c, ax • Yet not so easy! Assembler Assembly Code Machine Language Code 0000111 0000101 1100011 0011111 1110000 mov ax, aadd ax, bmov c, ax
High level languages • Easiest to program • English like syntax • E.g. To add two numbers in Java • c = a + b; Library Code Machine Language Code Machine Language Code High Level Source Code Linker Compiler
//This program prints Welcome to Java! publicclass Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } Run
Compile: • javacWelcome.java • Run • java Welcome • Caution: no .class at the end of Welcome!
Allows you to develop and deploy applications on • Internet for servers • desktop computers • small hand-held devices
Developed by James Gosling at Sun Microsystems • First named Oak • Later named Java 1995 • HotJava • The first Java-enabled Web browser • Write once, run anywhere
Java = Language specification + API • Specification: technical definition of the language (semantic + syntax) • API: contains predefined libraries for developing java programs • JVM = Java Virtual Machine • JDK = Java Development Kit • IDE = Integrated Development Environment
Makes writing & managing large scale programs easier • NetBeansOpen Source by Oracle • Eclipse Open Source by IBM • BlueJ • …
JDK = Java Development Kit • JDK 1.02 (1995) • JDK 1.1 (1996) • JDK 1.2 (1998) • JDK 1.3 (2000) • JDK 1.4 (2002) • JDK 1.5 (2004) a. k. a. JDK 5 or Java 5 • JDK 1.6 (2006) a. k. a. JDK 6 or Java 6 • JDK 1.7 (2010) a. k. a. JDK 7 or Java 7
Java Standard Edition (Java SE) • client-side standalone applications or applets. • Java Enterprise Edition (Java EE) • server-side applications such as Java servlets and Java Server Pages (JSP). • Java Micro Edition (Java ME). • applications for mobile devices We use Java SE.
Simple • Object-Oriented • Distributed • Robust • Secure • Architecture-Neutral • Portable • Performance
Homework 1 is posted • Due next Friday • Programming assignment 1 is posted • Due next Friday • Source code available on website • No class on Monday (Holiday)
Programming languages • Java • Simple program • javacnameOfSourceFile.java • java nameOfClassFile
//This program prints Welcome to Java! publicclass Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } Run
Object Oriented Programming ( OOP) • main method • Programming syntax
Object Oriented Programming ( OOP) • A software methodology • Great flexibility, modularity, clarity, and reusability • Uses “encapsulation”, “inheritance”, and “polymorphism” • Everything is Java is an “Object”
Real world objects • Dog, TV set, desk, etc. • Every object has “state” and “behavior” • Dog object • State: name, color, breed, hungry • Behavior: barking, fetching, wagging tail • In OOP • State = “field” • Behavior = “method”
E.g. Dog class • class Dog { ...description of a dog goes here... } • Each object (class) has • State (Properties or data fields) • Behavior (methods) • Can have instances Dog Dog Dog Bark() Eat () Bark() Eat () Bark() Eat () Instances Class Name • Name • Age • Weight • cooper • 3.5 • 34 • max • 2 • 30 Properties Methods
Here is another example of a class: • class Window { ... } • Here are some examples of Windows:
Data usually goes first in a class • Example: class Dog { String name;int age; ...rest of the class...} Class
Methods usually go after the data Class • Example: class Dog { … void bark() {System.out.println("Woof!"); }} • A class may contain methods that describe the behavior of objects
packagepackagename; packageMyMathPackage; • Groups related classes in the same category • How to declare a class is part of a package? • Unique name • Hierarchal packagebook.chapter1;
Many packages in Java API • javax.swing • java.lang • java.util • Java.net • … • How to use a package? import packagename; Only “Welcome” class is imported. import book.chapter1.Welcome; import book.chapter1.*; All classes in chapter1 imported.
Usually: the source program must be recompiled on another machine • Because the object program can only run on a specific machine. • With Java: • Compile the source program into bytecode. • The bytecode can then run on any computer • Which has Java Virtual Machine (JVM) • A software that interprets Java bytecode. • JVM • Class loader • Bytecode verifier