Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.

Slides:



Advertisements
Similar presentations
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Advertisements

CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Cmp Sci 187: Introduction to Java Based on Appendix A of text (Koffmann and Wolfgang)
Advanced Programming Rabie A. Ramadan vpro/ Lecture 1.
 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 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
CS 225 Java Review. Java Applications A java application consists of one or more classes –Each class is in a separate file –Use the main class to start.
Review Java.
Basic Elements of C++ Chapter 2.
COMPUTER SCIENCE I C++ INTRODUCTION
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
1 Course Lectures Available on line:
High-Level Programming Languages: C++
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Programming in C#. I. Introduction C# (or C-Sharp) is a programming language. C# is used to write software that runs on the.NET Framework. Although C#
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Introduction to Computer Systems and the Java Programming Language.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Week 1 Algorithmization and Programming Languages.
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
Slides prepared by Rose Williams, Binghamton University Chapter 5 Defining Classes II.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Introduction to Java Java Translation Program Structure
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo CET 3640 © Copyright by Pearson Education, Inc. All Rights Reserved.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
CSI 3125, Preliminaries, page 1 Data Type, Variables.
By Mr. Muhammad Pervez Akhtar
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
JAVA MULTIPLE CHOICE QUESTION.
3 Introduction to Classes and Objects.
Objectives You should be able to describe: Interactive Keyboard Input
Yanal Alahmad Java Workshop Yanal Alahmad
Java Primer 1: Types, Classes and Operators
Basic Elements of C++.
Java Programming: From Problem Analysis to Program Design, 4e
Basic Elements of C++ Chapter 2.
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 6 Methods: A Deeper Look
MSIS 655 Advanced Business Applications Programming
IFS410 Advanced Analysis and Design
Programs and Classes A program is made up from classes
Object Oriented Programming in java
Java Programming Language
Introduction to Java By Prakash G Asnani
Presentation transcript:

Introduction to Java Appendix A

Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java To learn about the primitive data types of Java To understand how to use the control structures of Java To learn how to use predefined classes such as Math, JOptionPane, String, StringBuffer, and StringTokenizer To learn how to write and document your own Java classes

Appendix A: Introduction to Java3 Chapter Objectives (continued) To understand how to use arrays in Java To learn how to perform I/O in Java using simple dialog windows To learn how to perform I/O in Java using streams

Appendix A: Introduction to Java4 The Java Environment and Classes Platform independent Object oriented Can be embedded in Web pages JVM is a software computer that runs inside an actual computer Java code is first translated into Java byte code instructions which are then interpreted by the JVM

Appendix A: Introduction to Java5 Compiling and Executing a Java Program

Appendix A: Introduction to Java6 Classes and Objects The class is the fundamental programming unit Every program is written as a collection of classes Class definitions are stored in separate files with the extension.java and the file name must be the same as the class name A class is a named description for a group of entities A class is a general description of a group of entities that all have the same characteristics; each entity is an object

Appendix A: Introduction to Java7 The Java API Java consists of small core language augmented by an extensive collection of packages Each package contains a collection of related Java classes, such as: Swing AWT util

Appendix A: Introduction to Java8 The import Statement and the Main Method Import statement tells the compiler to make the names defined in a specified package accessible to the code file The main function identifies where the JVM begins execution of an application program Keywords “public static void” tell the compiler that main is accessible outside of the class, is static, and does not return a value

Appendix A: Introduction to Java9 Primitive Data Types and Reference Variables Java distinguishes two kinds of entities Primitive types Objects Primitive type data is stored in primitive type variables Objects are associated with reference variables which store an object’s address

Appendix A: Introduction to Java10 Primitive Data Types Represent numbers, characters, and Boolean values Integers: byte, short, int, and long Real numbers: float and double Characters: char

Appendix A: Introduction to Java11 Primitive Data Types (continued)

Appendix A: Introduction to Java12 Operators

Appendix A: Introduction to Java13 Type Compatibility and Conversion Widening conversion: operations involving mixed-type operands, the numeric type of the smaller range is converted to the numeric type of the larger range In an assignment operation, a numeric type of smaller range can be assigned to a numeric type of larger range

Appendix A: Introduction to Java14 Referencing and Creating Objects You can declare reference variables that reference objects of specified types Two reference variables can reference the same object The new operator creates an instance of a class A constructor executes when a new object is created

Appendix A: Introduction to Java15 Java Control Statements A group of statements executed in sequence is written as a compound statement delimited by braces The statements execute in the order in which they are listed Control Statements alter the sequential flow of execution

Appendix A: Introduction to Java16 Java Control Statements (continued)

Appendix A: Introduction to Java17 Java Control Statements (continued)

Appendix A: Introduction to Java18 Methods Programmers use methods to define a group of statements that perform a particular operation The modifier static indicates a static or class method A method that is not static is an instance method All method arguments are call-by-value If the argument is a primitive type, its value is passed to the method The method can’t modify the argument value and have the modification remain after return from the method

Appendix A: Introduction to Java19 Methods (continued) If the argument is of a class type, the value of the reference variable is passed, not the value of the object itself Reference variables point to the object and any modification to the object will remain after return from the method

Appendix A: Introduction to Java20 The Class Math Provides a collection of methods that are useful for performing common mathematical operations

Appendix A: Introduction to Java21 Escape Sequences An escape sequence is a sequence of two characters beginning with the character \ Represents characters or symbols that have a special meaning in Java

Appendix A: Introduction to Java22 The String Class String class defines a data type that is used to store a sequence of characters You cannot modify a String object If you attempt to do so, Java will create a new object that contains the modified character sequence

Appendix A: Introduction to Java23 Comparing Objects You can’t use the relational operators or equality operators to compare the values stored in strings or other objects

Appendix A: Introduction to Java24 The StringBuffer Class Stores character sequences Unlike a String object, the contents of a StringBuffer object can be changed

Appendix A: Introduction to Java25 StringTokenizer Class We often need to process individual pieces, or tokens, in a string

Appendix A: Introduction to Java26 Wrapper Classes for Primitive Types Sometimes we need to process primitive-type data as objects Java provides a set of classes called wrapper classes whose objects contain primitive-type values: Float, Double, Integer, Boolean, Character, etc.

Appendix A: Introduction to Java27 Defining Your Own Classes Unified Modeling Language is often used to represent a class Standard means of documenting class relationships widely used in industry

Appendix A: Introduction to Java28 Defining Your Own Classes (continued) The modifier private sets the visibility of each variable or constant to private visibility These data fields can be accessed only within the class definition Only class members with public visibility can be accessed outside of the class Constructors initialize the data fields within a class

Appendix A: Introduction to Java29 Arrays In Java, an array is also an object The elements are indexes and are referenced using a subscripted variable of the form arrayname[subscript]

Appendix A: Introduction to Java30 Input/Output using Class JOptionPane Prior to Java 2, it was fairly difficult to perform input/output operations Java 2 provides JOptionPane which facilitates the display of dialog windows for input and message windows for output

Appendix A: Introduction to Java31 Input/Output using Class JOptionPane (continued)

Appendix A: Introduction to Java32 Converting Numeric Strings to Numbers A dialog window always returns a reference to a string Therefore, a conversion is required

Appendix A: Introduction to Java33 Input/Output using Streams An input stream is a sequence of characters representing program data An output stream is a sequence of characters representing program output The console keyboard stream is System.in The console window is associated with System.out

Appendix A: Introduction to Java34 Chapter Review A Java program is a collection of classes JVM enables a Java program written for one machine to execute on any other machine that has a JVM Java defines a set of primitive data types that are used to represent numbers, characters, and Boolean data The control structures of Java are similar to those found in other languages The Java String and StringBuffer classes are used to reference objects that store character strings

Appendix A: Introduction to Java35 Chapter Review (continued) Be sure to use methods such as equals and compareTo to compare the contents of two String objects You can declare your own Java classes and create objects of these classes using the new operator A class has data fields and instance methods Array variables can reference array objects Class JOptionPane can be used to display dialog windows for data entry and message windows for output The stream classes in package java.io read strings from the console and display strings to the console