1 Chapter 2 First Java Programs Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

Chapter 8 Improving the User Interface
INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
Chapter 3 Syntax, Errors, and Debugging
Chapter 2 First Java Programs
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. OBJECTIVES FOR THIS UNIT Upon completion of this unit, you should be able to: Explain the Java virtual machine.
MC697 Object-Oriented Programming Using Java. In this class, we will cover: How the class will be structured Difference between object-oriented programming.
Chapter 1 Introduction to JAVA. Why Learn JAVA? Java is one of the fastest growing programming language in the world. Java is one of the fastest growing.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
1 Fall 2008ACS-1903 Chapter 1 Topics Java History Java Programs Why Program? Computer Systems: Hardware and Software Programming Languages What Is a Program.
01 Introduction1June Introduction CE : Fundamental Programming Techniques.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 7 Improving the User Interface
Honors 101, Fall 2006 Please do not sit in back of room! Lots of info on web page Join the mailing list Download Eclipse and start using it Read the text.
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,
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Chapter 2 First Java Programs
Computer Programming 12 Mr. Jean March 3 rd, 2014.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
1.1 History of Computers 1940s: The ENIAC was one of the world’s first computers. Large stand-alone machine Used large amounts of electricity Contained.
Introducing Java.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Parts of a Computer Why Use Binary Numbers? Source Code - Assembly - Machine Code.
A First Program Using C#
Lesson 2: First Java Programs
COMPUTER SOFTWARE Section 2 “System Software: Computer System Management ” CHAPTER 4 Lecture-6/ T. Nouf Almujally 1.
(C) 2010 Pearson Education, Inc. All rights reserved.  Java programs normally go through five phases  edit  compile  load  verify  execute.
111 © 2002, Cisco Systems, Inc. All rights reserved.
Computer Programming 12 Mr. Jean March 19 th, 2013.
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.
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.
© 2006 Pearson Education 1 Obj: cont 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 –
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.
Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions.
Lesson 2: First Java Programs. Objectives: –Discuss why Java is an important programming language. –Explain the Java virtual machine and byte code. –Choose.
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.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
Fall 2006Slides adapted from Java Concepts companion slides1 Introduction Advanced Programming ICOM 4015 Lecture 1 Reading: Java Concepts Chapter 1.
Getting started with Programming using IDE. JAVA JAVA IS A PROGRAMMING LANGUAGE AND A PLATFORM. IT CAN BE USED TO DELIVER AND RUN HIGHLY INTERACTIVE DYNAMIC.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Copyright © Mohamed Nuzrath Java Programming :: Syllabus & Chapters :: Prepared & Presented By :: Mohamed Nuzrath [ Major In Programming ] NCC Programme.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and web applications Very rich GUI libraries Portability (machine independence) A real Object.
By Mr. Muhammad Pervez Akhtar
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Programming Languages Concepts Chapter 1: Programming Languages Concepts Lecture # 4.
Programming 2 Intro to Java Machine code Assembly languages Fortran Basic Pascal Scheme CC++ Java LISP Smalltalk Smalltalk-80.
Chapter 2 First Java Programs Fundamentals of Java.
BlueJ X ICSE Syllabus. Board Pattern THEORY (100 marks) PRACTICAL (100 marks) PROJECT (50 marks) ASSIGNMENTS (50 marks)
1 Sections Java Virtual Machine and Byte Code Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Lesson 2: First Java Programs. 2.1 Why Java? Java is one of the most popular programming languages in the world. Java is a modern object-oriented programming.
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles.
2.5 Edit, Compile, and Execute Figure 2-3 illustrates the edit, compile and execute steps. Java bytecode.
Introduction to Algorithm. What is Algorithm? an algorithm is any well-defined computational procedure that takes some value, or set of values, as input.
1 Sections 3.1 – 3.2a Basic Syntax and Semantics Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
1 Sections 3.3 – 3.4 Terminal I/O and Comments Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Fundamentals of Programming I Overview of Programming
Text by: Lambert and Osborne
Chapter 2 First Java Programs
Java programming lecture one
Section 3.2c Strings and Method Signatures
Computer Programming-1 CSC 111
Presentation transcript:

1 Chapter 2 First Java Programs Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne

Chapter 2 Lambert / OsborneFundamentals of Java 4E 222 Objectives Discuss why Java is an important programming language. Explain the Java virtual machine and byte code. Choose a user interface style. Describe the structure of a simple Java program. Write a simple program.

Chapter 2 Lambert / OsborneFundamentals of Java 4E 333 Objectives (continued) Edit, compile, and run a program using a Java development environment. Format a program to give a pleasing, consistent appearance. Understand compile-time errors. Write a simple graphics program.

Chapter 2 Lambert / OsborneFundamentals of Java 4E 444 Vocabulary applet assignment operator byte code DOS development environment graphical user interface (GUI) hacking import statement integrated development environment (IDE) interpreter Java virtual machine (JVM)

Chapter 2 Lambert / OsborneFundamentals of Java 4E 555 Vocabulary (continued) just-in-time compilation (JIT) panel panes parameter source code statement terminal I/O user interface variable

Chapter 2 Lambert / OsborneFundamentals of Java 4E 666 Why Java? 1 - Java is the fastest growing programming language in the world. – Sun, IBM use Java to develop applications. 2 - Java is ideal for distributed, network-based applications: – Enables the construction of virus-free, tamper-free systems (secure) – Supports the development of programs that do not overwrite memory (robust) – Yields programs that can be run on different types of computers without change (portable)

Chapter 2 Lambert / OsborneFundamentals of Java 4E 777 Why Java? 3- Java supports the use of advanced programming concepts such as threads. A thread is a process that can run concurrently with other processes. 4- Java bears a superficial resemblance to C++, which is currently the world’s most popular industrial-strength programming language. On the negative side, Java runs more slowly than most modern programming languages because it is interpreted.

Chapter 2 Lambert / OsborneFundamentals of Java 4E 888 The Java Virtual Machine and Byte Code Java compilers translate Java into Java byte code. – Not machine language – Must install JVM (Java Virtual Machine). A JVM is an interpreter. – An interpreter is a program that runs like a computer. – An interpreter runs slower than a computer.

Chapter 2 Lambert / OsborneFundamentals of Java 4E 999 The Java Virtual Machine and Byte Code (continued) Any computer can run an interpreter. – Makes Java byte code portable (is the machine language for an imaginary Java computer) – a technique called just-in-time compilation (JIT) when running the JVM Java applets – Applets are small programs already translated into byte code that are built into Web sites.

Chapter 2 Lambert / OsborneFundamentals of Java 4E 10 Choosing a User Interface Style Two user interfaces for a temperature conversion program Graphical user interface (GUI) Terminal I/O user interface

Chapter 2 Lambert / OsborneFundamentals of Java 4E 11 Choosing a User Interface Style (continued) Why use terminal I/O? – In Java, it’s easier to implement than GUI. – There are programming situations that require terminal I/O. – Terminal-oriented programs are similar in structure to programs that process files of sequentially organized data.

Chapter 2 Lambert / OsborneFundamentals of Java 4E 12 Hello World “Hello World” is traditionally the first program in a textbook. Hello world program executed

Chapter 2 Lambert / OsborneFundamentals of Java 4E 13 Hello World (continued) The Source Code: The bulk of the instructions of a program.

Chapter 2 Lambert / OsborneFundamentals of Java 4E 14 Hello World (continued) The Explanation: System.out is an object that displays characters in a terminal window. println is the message being sent to the object. The quotations indicate what is to be displayed. Semicolons mark the end of each statement. The characters between the parentheses are the parameters. The period (. ) is the method selector operator.

Chapter 2 Lambert / OsborneFundamentals of Java 4E 15 Hello World (continued) The Larger Framework: Program comments are in green, reserved words in blue, and code in black.

Chapter 2 Lambert / OsborneFundamentals of Java 4E 16 Edit, Compile, and Execute Edit – Save it as a text file with the extension.java. Compile – Translates the source code into Java byte code. Execute – The programmer instructs the JVM to load the byte code into memory and execute. – The user and program can now interact.

Chapter 2 Lambert / OsborneFundamentals of Java 4E 17 Edit, Compile, and Execute (continued) Editing, compiling, and running a program

Chapter 2 Lambert / OsborneFundamentals of Java 4E 18 Edit, Compile, and Execute (continued) Development Environments: Unix or LinuxStandard text editorFree Microsoft WindowsNotepad and DOS window Free Integrated development environment (IDE) BlueJ, Eclipse, or JGrasp Not free, but combines editor, compiler, debugger, and JVM

Chapter 2 Lambert / OsborneFundamentals of Java 4E 19 Edit, Compile, and Execute (continued) The program as typed into Notepad

Chapter 2 Lambert / OsborneFundamentals of Java 4E 20 Edit, Compile, and Execute (continued) Compile-Time Errors: Mistakes detected by the compiler are called syntax errors or compile-time errors. Compiler’s error message

Chapter 2 Lambert / OsborneFundamentals of Java 4E Edit, Compile, and Execute (continued) Readability: Programs may be maintained by other people. Layout affects readability. – Use indentation, blank lines, and spaces. 21

Chapter 2 Lambert / OsborneFundamentals of Java 4E 22 Temperature Conversion Temperature conversion program reads user input and performs computations. The first line of code is an import statement. Variables for Fahrenheit and Celsius. Assignment statements use an operator such as *, /, +, and -.

Chapter 2 Lambert / OsborneFundamentals of Java 4E 23 Temperature Conversion (continued) Variables and objects used in the conversion program

Chapter 2 Lambert / OsborneFundamentals of Java 4E 24 Summary In this chapter, you learned: Java is the fastest growing programming language in the world. It is secure, robust, and portable. It is also similar to C++, the world’s most popular programming language. 24

Chapter 2 Lambert / OsborneFundamentals of Java 4E 25 Summary (continued) 25 The Java compiler translates Java into a pseudomachine language called Java byte code. Byte code can be run on any computer that has a Java virtual machine installed. The Java virtual machine (JVM) is a program that behaves like a computer—an interpreter. Java programs include variables, arithmetic expressions, statements, objects, messages, and methods.

Chapter 2 Lambert / OsborneFundamentals of Java 4E 26 Summary (continued) Three basic steps in the coding process are editing, compiling, and running a program using a Java development environment. Programmers should pay attention to a program’s format to ensure readability. Java programs accomplish many tasks by sending messages to objects. Examples are sending text to the terminal window for output and receiving input data from the keyboard. There are several user interface styles, among them terminal based and graphical based. 26