1 / 70

COP3502 Programming Fundamentals for CIS Majors 1

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.

jubal
Download Presentation

COP3502 Programming Fundamentals for CIS Majors 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Dr. Parisa Rashidi

  2. Computer basics • What is Java? • API, IDE, and JDK • Write a simple program in Java • Console output • GUI • Understand the basic syntax of Java

  3. Computing Basics Hardware, software, etc.

  4. Hardware • Operating Systems • Software From Wikipedia, the free encyclopedia

  5. 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

  6. CPU = Central Processing Unit • Speed measured in MHz • 1 MHz = 10^6 pulses per second • Executes instructions retrieved from memory

  7. 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

  8. 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 . .

  9. 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

  10. 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)

  11. Monitor Display • Quality • Resolution • number of pixels per square inch • E.g. 1024 by 768 • Dot pitch • amount of space between pixels Dot pitch

  12. 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

  13. Controls all programs • Manages hardware resources • Examples • Windows 7 • Ubuntu • MacOS

  14. 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

  15. Programming Languages Basics

  16. Every operating system, application and mobile app has been written in some programming language

  17. 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) • …

  18. Wewill be using Java (1991) Duke: Java’s Mascot

  19. Some famous applications written in Java • Mars exploration rover • Hubble telescope • Vuze • Minecarft • Android (mostly)

  20. High level language (Java) • Assembly Language • Machine language Difficulty of programming

  21. 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

  22. 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

  23. 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

  24. //This program prints Welcome to Java! publicclass Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } Run

  25. Compile: • javacWelcome.java • Run • java Welcome • Caution: no .class at the end of Welcome!

  26. Java Basics

  27. Allows you to develop and deploy applications on • Internet for servers • desktop computers • small hand-held devices

  28. Applets

  29. 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

  30. 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

  31. Makes writing & managing large scale programs easier • NetBeansOpen Source by Oracle • Eclipse Open Source by IBM • BlueJ • …

  32. 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

  33. 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.

  34. Simple • Object-Oriented • Distributed • Robust • Secure • Architecture-Neutral • Portable • Performance

  35. 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)

  36. Programming languages • Java • Simple program • javacnameOfSourceFile.java • java nameOfClassFile

  37. //This program prints Welcome to Java! publicclass Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } Run

  38. Programming in Java

  39. Object Oriented Programming ( OOP) • main method • Programming syntax

  40. Object Oriented Programming ( OOP) • A software methodology • Great flexibility, modularity, clarity, and reusability • Uses “encapsulation”, “inheritance”, and “polymorphism” • Everything is Java is an “Object”

  41. 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”

  42. 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

  43. Here is another example of a class: • class Window { ... } • Here are some examples of Windows:

  44. Data usually goes first in a class • Example: class Dog { String name;int age; ...rest of the class...} Class

  45. 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

  46. Run

  47. packagepackagename; packageMyMathPackage; • Groups related classes in the same category • How to declare a class is part of a package? • Unique name • Hierarchal packagebook.chapter1;

  48. 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.

  49. 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

More Related