Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Chapter One: Introduction.

Slides:



Advertisements
Similar presentations
11 January 2013Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Advertisements

INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Chapter 1: Introduction
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
Chapter 1 These slides for CSE 110 Sections are based in part on the textbook-authors’ slides, which are copyright by the authors. The authors state that.
1 Java Basics. 2 Compiling A “compiler” is a program that translates from one language to another Typically from easy-to-read to fast-to-run e.g. from.
The Java Programming Language  Simple – but abstract  Safe  Platform-independent ("write once, run anywhere")  Has a Rich growing library  Designed.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
1 Fall 2008ACS-1903 Chapter 1 Topics Java History Java Programs Why Program? Computer Systems: Hardware and Software Programming Languages What Is a Program.
CHAPTER 1 INTRODUCTION GOALS  To understand the activity of programming  To learn about the architecture of computers  To learn about machine code and.
Introduction to Java Programming, 4E
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Chapter 1 - Introduction. Ch 1Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
Microsoft Visual Basic 2012 CHAPTER ONE Introduction to Visual Basic 2012 Programming.
Microsoft Visual Basic 2005 CHAPTER 1 Introduction to Visual Basic 2005 Programming.
CS102 Introduction to Computer Programming
Computer Science 1710: Object- Oriented Programming 1 Spring 2007 Instructor: Andrew Vardy.
Introducing Java.
Week 1 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
 2003 Prentice Hall, Inc. All rights reserved. 1 Java Training Course Dr. H.E. Dunsmore Purdue University Java – How to Program, Deitel (5 th Edition)
Copyright © 2013 by John Wiley & Sons. All rights reserved. INTRODUCTION CHAPTER Slides by Donald W. Smith TechNeTrain.com Final Draft Oct. 15,
111 © 2002, Cisco Systems, Inc. All rights reserved.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Chapter One: Introduction.
Week 1 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Introduction to Computers and Java Chapter 1.3. A Sip of Java: Outline History of the Java Language Applets A First Java Program Compiling a Java Program.
©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 1 Chapter 1 Introduction.
Chapter 1 Introduction. Goal to learn about computers and programming to compile and run your first Java program to recognize compile-time and run-time.
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
Chapter 1 CSIS-120: Java Intro. What is Programming?  A: It is what makes computer so useful.  The flexibility of a computer is amazing  Write a term.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter 1 – Introduction.
Programming With C.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Chapter 1: Introduction to Programs, and Java 1. Objectives To review programs (§ ). To understand the relationship between Java and the World Wide.
ICOM 4015: Advanced Programming Lecture 1 Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Reading: Chapter One: Introduction.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Introduction to Java Programming with Forte Y. Daniel Liang.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter 1 – Introduction ( ปรับปรุง )
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 1 - Introduction.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture.
Introduction To JAVA By Ihtesham Ul Haq. Course Objectives Upon completing the course, you will understand Upon completing the course, you will understand.
Fall 2006Slides adapted from Java Concepts companion slides1 Introduction Advanced Programming ICOM 4015 Lecture 1 Reading: Java Concepts Chapter 1.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.
J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second Edition D.S. Malik D.S. Malik.
Chapter 1 Introduction. Chapter Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
Chapter 1 09/04/13. Change Your Password  The command is: passwd In the lab first do : ssh -Y onyx  You will have to see me to change it, if you forget.
Application Architecture Using Java Hong Li. Introduction Developed by a team led by James Gosling at Sun Microsystem. Originally called Oak, designed.
Creating a Java Application and Applet
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To learn about the architecture of computers To learn about machine code.
Lecture1 Instructor: Amal Hussain ALshardy. Introduce students to the basics of writing software programs including variables, types, arrays, control.
Chapter 1 - Introduction. Announcements Info Sheet Web Site: Lab Hours NotecardsPictures.
CSH Intro. to Java. The Big Ideas in Computer Science Beyond programming Solving tough problems Creating extensible solutions Teams of “Computational.
ITP 109 Week 2 Trina Gregory Introduction to Java.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Introduction to Algorithm. What is Algorithm? an algorithm is any well-defined computational procedure that takes some value, or set of values, as input.
Chapter 1 – Introduction
John Woodward A Simple Program – Hello world
GC101 Introduction to computer and program
Chapter Goals To learn about computers and programming
Chapter 1 – Introduction
Java programming lecture one
Goals To learn about computers and programming
Computer Programming-1 CSC 111
Presentation transcript:

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Chapter One: Introduction

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. To understand the activity of programming To learn about the architecture of computers To learn about machine code and high level programming languages To become familiar with your computing environment and your compiler To compile and run your first Java program To recognize syntax and logic errors Chapter Goals

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Computer savvy (file management, text editing) Problem solving skills Time management High school basic math No prior programming background required Prerequisites

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Computers are programmed to perform tasks Different tasks = different programs Program Sequence of basic operations executed in succession Contains instruction sequences for all tasks it can execute Sophisticated programs require teams of highly skilled programmers and other professionals What Is Programming?

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Central processing unit Chip Transistors Storage Primary storage: Random-access memory (RAM) Secondary storage: e.g. hard disk Removable storage devices: e.g.: floppy disks, tapes, CDs Peripherals Executes very simple instructions Executes instructions very rapidly General purpose device The Anatomy of a Computer

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Central processing unit Chip Transistors Storage Primary storage: Random-access memory (RAM) Secondary storage: e.g. hard disk Removable storage devices: e.g.: floppy disks, tapes, CDs Peripherals Executes very simple instructions Executes instructions very rapidly General purpose device The Anatomy of a Computer

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. bj4_01_04

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Schematic Diagram of a Computer

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. The first usable electronic computer designed by John Mauchly and J. Presper Eckert of the University of Pennsylvania Completed by 1946 Contained about vaccuum tubes in many cabinates Weighed more than 27 tons was roughly 2.4 m × 0.9 m × 30 m Consumed 150 kW of power Vaccuum tubes burned out at the rate of several tubes per day The ENIAC

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Work on the ENIAC was supported by U.S. Navy Computation of ballistic table give the trajectory of a projectile Depend on the wind resistance initial velocity atmospheric condition 1950’s the word computer referred to people who did that kind of work the ENIAC was later used for peaceful purposes such as tabulator of U.S. census data The ENIAC

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. The ENIAC

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. the processor executes machine instructions CPU from different vendors have different sets of machine instructions. Java programs contain machine instructions for a so-called “Java virtual machine” (JVM) that being enable Java applications to run on different CPUs without modification Java virtual machine is an idealized CPU that is simulated by a program run on the actual CPU Translating Human-Readable programs to Machine Code

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Java Virtual Machine (JVM) – a typical sequence of machine instructions is: 1.Load the contents of memory location Load the value If the first value is greater than the second value, continue with the instruction that is stored in memory location 240. Machine instructions are encoded as numbers: Compiler translates high-level language to machine code Machine Code

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Java Virtual Machine fetch sequence of numbers decode them execute the associated sequence of commands Java Virtual Machine (JVM)

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. The most direct method is to place the actual numbers into computer memory It is tedious and error-prone to look up the numeric codes for thousands command and manually place the code into memory. Computer are good at automating tedious and error-prone activities. Communicate the command sequence to the computer

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Began to appear in the mid-1950s Programmer expresses the idea behind the task that needs to be performed Compiler translates the high-level description into machine instructions for a particular processor For example Java instruction If (intRate > 100) System.out.println(“Interest rate error”); Translate into … High-level Programming Language

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Originaly named Oak Developed as a part of the Green project at the Sun Microsystems for use in consumer devices in Designed by James Gosling, Patrick Naughton and others in The Java Programming Language

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Simple Safe Platform-independent ("write once, run anywhere") Rich library (packages) Designed for the internet The Java Programming Language

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Applets on a Web Page Visit web page that contains Java code, the code automaticlly running.

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. VersionYearImportant New Features Inner classes Swing, Collections Performance enhancements Assertions, XML 52004Generic classes, enhanced for loop, auto-boxing, enumerations 62006Library improvements Small language changes and library improvments Java Versions Java was revised and extended many times

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Java library You cannot hope to learn all of Java in one term Java itself is relative simple but Java has a vast library with support for –Graphics –User interface design –Cryptography –Networking –Sound –Database storage –Many other purposes Expert Java programmers just use some parts that they need to particular projects

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. An Integrated Development Environment

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. 1: public class HelloPrinter 2: { 3: public static void main(String[] args) 4: { 5: // Display a greeting in the console window 6: 7: System.out.println("Hello, World!"); 8: } 9: } Output: Hello, World! ch01/hello/HelloPrinter.java

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. HelloPrinter in an IDE

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. 1: public class HelloPrinter 2: { 3: public static void main(String[] args) 4: { 5: // Display a greeting in the console window 6: 7: System.out.println("Hello, World!"); 8: } 9: } Output: Hello, World! HelloPrinter.java Start a new class Classes are a fundamental concept in Java. In Java, every program consists of one or more classes The word “public” denotes that the class is usable by the public In Java, every source file can contain at one public class and the name of the public class must match the name of the file containing the class HelloPrinter.java comment

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. main method public static void main(String[] args) { …. } The above construction declares a method called main A method contains a collection of programming instructions Every Java application must have a main method. Most Java programs contain other methods beside main.

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. ch01/hello/HelloPrinter.java public static void main(String[] args) { …. } The above construction declares a method called main A method contains a collection of programming instructions Every Java application must have a main method. Most Java programs contain other methods beside main.

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. 1: public class HelloPrinter 2: { 3: public static void main(String[] args) 4: { 5: // Display a greeting in the console window 6: 7: System.out.println("Hello, World!"); 8: } 9: } HelloPrinter.java Start a new class Body of main method Statement inside the curly brackets are executed one by one. Each statement ends in a semicolon(;)

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. 1: public class HelloPrinter 2: { 3: public static void main(String[] args) 4: { 5: // Display a greeting in the console window 6: 7: System.out.println("Hello, World!"); 8: } 9: } System.out The console window is represented in Java by an object called System.out. An object is an entity that you manipulate in your program In Java, each object belongs to a class The class declares methods that specify what you can do with the objects System.out object belongs to PrintStream class PrintStream class has a method called println for printing a line of text. called Syste.out

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. public class ClassName public static void main(String[] args) // comment Method call System class System.out object println method A Simple Program

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. object.methodName(parameters) Example: System.out.println("Hello, Dave!"); Purpose: To invoke a method of an object and supply any additional parameters. Syntax 1.1 Method Call

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. bj4_syn_01_01

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. How would you modify the HelloPrinter program to print the words "Hello," and "World!" on two lines? Answer: System.out.println("Hello,"); System.out.println("World!"); Self Check

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Would the program continue to work if you omitted the line starting with // ? Answer: Yes – the line starting with // is a comment, intended for human readers. The compiler ignores comments. Self Check 1.13

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. What does the following set of statements print? System.out.print("My lucky number is"); System.out.println( ); Answer: The printout is My lucky number is12 It would be a good idea to add a space after the is. Self Check 1.14

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Syntax errors System.ouch.print("..."); System.out.print("Hello); Detected by the compiler Logic errors System.out.print("Hell"); Detected (hopefully) through testing Errors

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Suppose you omit the // characters from the HelloPrinter.java program but not the remainder of the comment. Will you get a compile-time error or a run-time error? Answer: A compile-time error. The compiler will not know what to do with the word Display. Self Check 1.15

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. The Compilation Process

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved.

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. program class files API class files Execution engine Class loader Java virtual machine bytecodes

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. The Edit-Compile-Test Loop

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. The source file of a Java class is stored in a file: ClassName.java Java source files are essentially text files and can be opened in any text editor The compiled file of a Java class is stored in a file: ClassName.class Java class files are binary files (not human-readable). Source files and Class files

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved.

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved.

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Homework Obtain a Course Book Install Java and Eclipse Eclipse IDE: –Read the following eclipse tutorials –Help -> Help contents -> Workbench User Guide –Basic tutorial thru Deleting Resources Java Development User Guide –Basic tutorial thru Running Your Program »Don’t worry about understanding details of JUnit sample project