C++ Spring Break Packet 11 The Java Programming Language

Similar documents
Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Introduction to OOP Using Java Pearson Education, Inc. All rights reserved.

Section 2.2 Your First Program in Java: Printing a Line of Text

Full file at

1/14/2014. Introduction to CSE 1325 Object Oriented Programming (Using Java) Introduction (Cont.) Introduction

Section 2.2 Your First Program in Java: Printing a Line of Text

by Pearson Education, Inc. All Rights Reserved.

Introduction to Java. Lecture 1 COP 3252 Summer May 16, 2017

History of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995

Programming with Java

CHAPTER 1. Introduction to JAVA Programming

Object Oriented Concepts and Programming (CSC244) By Dr. Tabbasum Naz

Introduction to Java Programming

Introduction to C++ Programming. Adhi Harmoko S, M.Komp

Introduction to JAVA Programming Language

Chapter 1 Introduction to Computers, Programs, and Java

Lesson 2: First Java Programs

Fundamentals of Programming. Lecture 1: Introduction to C Programming

Chapter 1. Introduction

Index. Course Outline. Grading Policy. Lab Time Distribution. Important Instructions

II. Compiling and launching from Command-Line, IDE A simple JAVA program

CHAPTER 1 Introduction to Computers and Java

Introduction to Computers, the Internet and the World Wide Web

Object Oriented Design

Java is a high-level programming language originally developed by Sun Microsystems and released in Java runs on a variety of

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Fundamentals of Programming. By Budditha Hettige

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1: Introduction to Computers and Java

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

Chapter 1 Introduction to Computers, Programs, and Java

1. Introduction. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer? A Bit of History

Chapter 2 First Java Programs

Tutorial 1 CSC 201. Java Programming Concepts عؾادئماظربجمةمبادؿكدامماجلاصا

Eclipse Tutorial. For Introduction to Java Programming By Y. Daniel Liang

Project 1. Java Control Structures 1/17/2014. Project 1 and Java Intro. Project 1 (2) To familiarize with

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Introduction to Computers and Java

Lecture 1: Introduction to Java

Introduction to Computers and Java

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

9/11/08 (c) 2008 Matthew J. Rutherford Class (c) 2008 Matthew J. Rutherford Class

Introduction to Computers and Java

An Introduction to Software Engineering. David Greenstein Monta Vista High School

Introduction to Programming

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Lecture 1: Overview of Java

Java Language. Programs. Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs.

COMP1007 Principles of Programming

Supplement H.1: JBuilder X Tutorial. For Introduction to Java Programming, 5E By Y. Daniel Liang

Supplement II.B(1): JBuilder X Tutorial. For Introduction to Java Programming By Y. Daniel Liang

Chapter. Focus of the Course. Object-Oriented Software Development. program design, implementation, and testing

2 rd class Department of Programming. OOP with Java Programming

Chapter 1 Introduction to Computers, Programs, and Java

AP Computer Science A: Java Programming

Certified Core Java Developer VS-1036

Module 1: Introduction to Computers, Programs, and Java

Introduction to Java

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

Chapter 1 Introduction to Java

Introduction to Computers and Visual Basic.Net Pearson Education, Inc. All rights reserved.

NetBeans Tutorial. For Introduction to Java Programming By Y. Daniel Liang. This tutorial applies to NetBeans 6, 7, or a higher version.

1B1a Programming I Getting Started

Programming Languages and Program Development Life Cycle Fall Introduction to Information and Communication Technologies CSD 102

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

Identifiers. Identifiers are the words a programmer uses in a program Some identifiers are already defined. Some are made up by the programmer:

Java Programming Language Mr.Rungrote Phonkam

Chapter 1: Introduction to Computers, Programs, and Java

Java Programming. Zheng-Liang Lu. Java 308 Spring Department of Computer Science & Information Engineering National Taiwan University

CT 229. CT229 Lecture Notes. Labs. Tutorials. Lecture Notes. Programming II CT229. Objectives for CT229. IT Department NUI Galway

Getting Started With Java

Introduction Basic elements of Java

Chapter 1 Introduction to Computers, Programs, and Java

CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq

Objects and Classes Lecture 1

Chapter 1 Introduction to Computers, Programs, and Java

Eng. Mohammed S. Abdualal

Introduction to Java Applications; Input/Output and Operators

Goals. Java - An Introduction. Java is Compiled and Interpreted. Architecture Neutral & Portable. Compiled Languages. Introduction to Java

Objectives. Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer?

Networks Programming Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000)

Chapter 1 Overview of Programming and Problem Solving By C.K. Liang

Programming. Syntax and Semantics

CSE 421 Course Overview and Introduction to Java

Getting Started with Eclipse/Java

Introduction to Java. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Advanced Object-Oriented Programming Introduction to OOP and Java

Getting Started (1.8.7) 9/2/2009

Before you start with this tutorial, you need to know basic Java programming.

Java Programming. Zheng-Liang Lu. Java 301 Summer Department of Computer Science & Information Engineering National Taiwan University

AP Computer Science A

Chapter 1. Introduction to Computers and Java Objects. Background information. » important regardless of programming language. Introduction to Java

Introduction to Computers, the Internet and the Web Pearson Education, Inc. All rights reserved.

MEAP Edition Manning Early Access Program Get Programming with Java Version 1

0 Introduction: Computer systems and program development

Transcription:

C++ Spring Break Packet 11 The Java Programming Language! Programmers write instructions in various programming languages, some directly understandable by computers and others requiring intermediate translation steps.! Three general language types:! Machine languages! Assembly languages! High-level languages! Any computer can directly understand only its own machine language.! This is the computer s natural language, defined by its hardware design.! Generally consist of strings of numbers (ultimately reduced to 1s and 0s) that instruct computers to perform their most elementary operations one at a time.! Machine dependent a particular ma-chine language can be used on only one type of computer.! Englishlike abbreviations that represent elementary operations formed the basis of assembly languages.! Translator programs called assemblers convert assembly-language programs to machine language.

C++ Spring Break Packet 12! High-level languages! Single statements accomplish substantial tasks.! Compilers convert high-level language programs into machine language.! Allow you to write instructions that look almost like everyday English and contain commonly used mathematical notations.! C, C++, Microsoft s.net languages (e.g., Visual Basic, Visual C++ and C#) are among the most widely used high-level programming languages; Java is by far the most widely used.! Compiling a high-level language program into machine language can take a considerable amount of computer time.! Interpreter programs execute high-level language programs directly, although slower than compiled programs run.! Java uses a clever mixture of compilation and interpretation to run programs.! Java evolved from C++, which evolved from C, which evolved from BCPL and B.! C! Originally implemented in 1972! Evolved from B by Dennis Ritchie at Bell Laboratories! Became widely known as the UNIX operating system s development language! Today, most of the code for general-purpose operating systems is written in C or C++.

C++ Spring Break Packet 13! C++! An extension of C! Developed by Bjarne Stroustrup in the early 1980s at Bell Laboratories! Provides capabilities for object-oriented programming.! Hybrid language it s possible to program in either a C-like style, an object-oriented style or both.! Microprocessors are having a profound impact in intelligent consumer-electronic devices.! 1991! Recognizing this, Sun Microsystems funded an internal corporate research project, which resulted in a C++-based language named Java! Created by James Gosling.! 1993! The web exploded in popularity! Sun saw the potential of using Java to add dynamic content to web pages.! Java garnered the attention of the business community because of the phenomenal interest in the web.! Java programs consist of pieces called classes.! Classes include methods that perform tasks and return information when the tasks complete.! Java class libraries! Rich collections of existing classes! Also known as the Java APIs (Application Programming Interfaces)! Two aspects to learning the Java world.! The Java language it-self! The classes in the extensive Java class libraries! Download the Java API documentation! java.sun.com/javase/downloads/! Scroll down to the Additional Resources section and click the Download button to the right of Java SE 6 Documentation.

C++ Spring Break Packet 14! Programming tips! Software Engineering Observations explain concepts that affect and improve the overall architecture and quality of software systems.! Good Programming Practices help you write programs that are clearer, more understandable, more maintainable and easier to test and debug i.e., remove programming errors.! Common Programming Errors discuss problems to watch out for and avoid.! Programming tips (cont.):! Performance Tips techniques for writing programs that run faster and use less memory! Portability Tips techniques to help you write programs that can run, with little or no modification, on a variety of computers! Error-Prevention Tips techniques for removing bugs from your programs! Look-and-Feel Observations techniques to help you design the look and feel of your applications user interfaces

C++ Spring Break Packet 15 Program Development! Java program development and execution cycle (illustrated in Fig. 1.1).

C++ Spring Break Packet 16! Java programs normally go through five phases! edit! compile! load! verify! execute! Phase 1 consists of editing a file with an editor program (normally known simply as an editor).! Type a Java program (source code) using the editor! Make any necessary corrections! Save the program! A file name ending with the.java extension indicates that the file contains Java source code.! Linux editors: vi and emacs.! Windows editors: Notepad, EditPlus (www.editplus.com), TextPad (www.textpad.com) and jedit (www.jedit.org).! Integrated development environments (IDEs)! Provide tools that support the software-development process, including editors for writing and editing programs and debuggers for locating logic errors errors that cause programs to execute incorrectly.! Popular IDEs! Eclipse (www.eclipse.org)! NetBeans (www.netbeans.org)! JBuilder (www.codegear.com)! JCreator (www.jcreator.com)! BlueJ (www.bluej.org)! jgrasp (www.jgrasp.org)

C++ Spring Break Packet 17! Phase 2! Use the command javac (the Java compiler) to compile a program. For example, to compile a program called Welcome.java, you d type javac Welcome.java! If the program compiles, the compiler produces a.class file called Welcome.class that contains the compiled version of the program.! Java compiler translates Java source code into bytecodes that represent the tasks to execute.! Bytecodes are executed by the Java Virtual Machine (JVM) a part of the JDK and the foundation of the Java platform.! Virtual machine (VM) a software application that simulates a computer! Hides the underlying operating system and hardware from the programs that interact with it.! If the same VM is implemented on many computer platforms, applications that it executes can be used on all those platforms.! Bytecodes are platform independent! They do not depend on a particular hardware platform.! Bytecodes are portable! The same bytecodes can execute on any platform containing a JVM that understands the version of Java in which the bytecodes were compiled.! The JVM is invoked by the java command. For example, to execute a Java application called Welcome, you d type the command java Welcome

C++ Spring Break Packet 18! Phase 3! The JVM places the program in memory to execute it! This is known as loading.! Class loader takes the.class files containing the program s bytecodes and transfers them to primary memory.! Also loads any of the.class files provided by Java that your program uses.! The.class files can be loaded from a disk on your system or over a network.! Phase 4! As the classes are loaded, the bytecode verifier examines their bytecodes! Ensures that they are valid and do not violate Java s security restrictions.! Java enforces strong security to make sure that Java programs arriving over the network do not damage your files or your system (as computer viruses and worms might).! Phase 5! The JVM executes the program s bytecodes.! JVM typically uses a combination of interpretation and just-in-time (JIT) compilation.! Analyzes the bytecodes as they are interpreted, searching for hot spots parts of the bytecodes that execute frequently.! A just-in-time (JIT) compiler (the Java HotSpot compiler) translates the bytecodes into the underlying computer s machine language.! When the JVM encounters these compiled parts again, the faster machine-language code executes.! Java programs actually go through two compilation phases! One in which source code is translated into bytecodes (for portability across computer platforms)! A second in which, during execution, the bytecodes are translated into machine language for the actual computer on which the program executes.

C++ Spring Break Packet 19 Object-Oriented Programming! Unified Modeling Language (UML )! A graphical language that allows people who design software systems to use an industry-standard notation to represent them.! Chapters 12 13 present an object-oriented design and implementation of the software for a simple automated teller machine (ATM).! Objects! Reusable software components that model real world items.! Humans think in terms of objects. People, animals, plants, cars, etc.! Have attributes (e.g., size, shape, color and weight)! Exhibit behaviors (e.g., a ball rolls, bounces, inflates and deflates; a baby cries, sleeps, crawls, walks and blinks; a car accelerates, brakes and turns; a towel absorbs water).! Object-oriented design (OOD)! Models software in terms similar to those that people use to describe real-world objects.! Class relationships! Inheritance relationships! Models communication between objects (via messages).! Encapsulates attributes and operations (behaviors) into objects.! Information hiding! Objects may know how to communicate with one another across well-defined interfaces, but normally they are not allowed to know how other objects are implemented.

C++ Spring Break Packet 20! Object oriented languages! Programming in such a language, called object-oriented programming (OOP)! Allows you to implement an object-oriented design as a working system.! Java is object oriented.! Focus on creating classes.! Each contains fields and the set of methods that manipulate the fields and provide services to clients (i.e., other classes that use the class).! Programmers use existing classes as the building blocks for constructing new classes.! Classes are to objects as blueprints are to houses.! Associations relationships between classes.! Packaging software as classes facilitates reuse.! Object-oriented analysis and design (OOAD)! Analyzing your project s requirements (i.e., determining what the system is supposed to do) and developing a design that satisfies them (i.e., deciding how the system should do it).! Unified Modeling Language (UML) A single graphical language for communicating the results of any OOAD process has come into wide use.! The UML is the most widely used graphical representation scheme for modeling object-oriented systems.

C++ Spring Break Packet 21 Video Tutorial Summary Successful completion of this assignment will include the following: Have a tab separating this from other sections. Summarize each key point in the video tutorials. Give an example of the implementation of each key point. (In some cases, you will need to provide a screenshot of proof of implementation.) Find a separate web reference for each of the key points listed above. Wikis will not be allowed. Provide a reference list in APA format. What is Java? http://www.youtube.com/watch?v=hnvkr1liv0w Installing the JDK and IDE http://www.youtube.com/watch?v=ehh02lqj4tm and http://www.youtube.com/watch?v=- CSyFuBpuZQ Running a Java Program http://www.youtube.com/watch?v=_7rd_qkmlxo and http://www.youtube.com/watch?v=bhcu8uyjhyi

C++ Spring Break Packet 22 Practice Problems Use the scantron provided in class. Q1: End-of-line comments that should be ignored by the compiler are denoted using a. a. Two forward slashes ( // ). b. b. Three forward slashes ( /// ). c. c. A slash and a star ( /* ). d. d. A slash and two stars ( /** ). Q2: Which of the following is not a valid Java identifier? a. a. my Value b. b. $_AAA1 c. c. width d. d. m_x Q3: Which of the following cannot cause a syntax error to be reported by the Java compiler? a. a. Mismatched {} b. b. Missing */ in a comment that begins with /* c. c. Missing ; d. d. An extra blank line. Q4: Which of the following does not contain a syntax error? a. a. System.out.println( 'Hello world!' ): b. b. System.out.println( "Hello world!" ); c. c. System.out.println( "Hello world!" ); d. d. System.out.println( Hello world! ); Q5: Which command compiles the Java source code file Welcome.java? a. a. cd Welcome.java b. b. javac Welcome.java c. c. java Welcome.java d. d. compile Welcome.java Q6: Which command executes the Java class file Welcome.class? a. a. javac Welcome.class b. b. java Welcome.class c. c. java Welcome d. d. run Welcome.class Q7: Which is the output of the following statements? System.out.print( "Hello "); System.out.println( "World" ); a. a. Hello World b. b. HelloWorld c. c. Hello World d. d. World Hello Q8: Which of the following is the escape character? a. a. * b. b. \ c. c. \n d. d. "

C++ Spring Break Packet 23 Q9: Which of the following statements will print a single line containing "hello there"? a. a. System.out.println( "hello" ); System.out.println( " there" ); b. b. System.out.println( "hello", " there" ); c. c. System.out.println( "hello" ); System.out.print( " there" ); d. d. System.out.print( "hello" ); System.out.println( " there" ); Q10: Which of the following escape sequences represents a carriage return? a. \n. b. \r. c. \cr. d. \c. Q11: Which of the following statements would display the phase Java is fun? a. a. System.out.println( "hellois fun\rjava " ); b. b. System.out.println( 'Java is fun' ); c. c. System.out.println( "\"Java is fun\"" ); d. d. System.out.println( Java is fun ); Q12: All import declarations must be placed a. inside the class declaration s body. b. before the class declaration. c. after the class declaration. d. all of the above will work. Q13: Which of the following is a variable declaration statement? a. a. int total; b. b. import java.util.scanner; c. c. public static void main( String args[] ) d. d. // first string entered by user Q14: Which of the following statements does not alter a memory location? a. a. int a; b. b. number = 12; c. c. y = y + 2; d. d. width = Integer.parseInt(input); Q15: What will be output after the following Java statements have been executed? int a, b, c, d; a = 4; b = 12; c = 37; d = 51; if ( a < b ) System.out.println( "a < b" ); if ( a > b ) System.out.println( "a > b" ); if ( d <= c ) System.out.println( "d <= c" ); if ( c!= d ) System.out.println( "c!= d" ); a. a. a < b c!= d b. b. a < b d <= c c!= d c. c. a > b c!= d d. d. a < b c < d a!= b