Copyright © 2002 ProsoftTraining. All rights reserved. Advanced TCP/IP Concepts and Practices.
Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.
Transcript of Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.
![Page 1: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/1.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Java Programming Fundamentals
![Page 2: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/2.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 1:Java Runtime Environment
![Page 3: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/3.jpg)
Objectives
• Identify the differences between stand-alone applications and applets
• Describe the role of the Java Virtual Machine• Create a simple Java program• Use Java comments• Compile and execute a Java program• Describe the differences between *.java and *.class files
![Page 4: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/4.jpg)
The Java Virtual Machine
• Stand-alone applications• Applets• Classes• Methods• Bytecode
![Page 5: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/5.jpg)
Java Comments
• Single-line comment• Multiline comment• Javadoc comment
![Page 6: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/6.jpg)
Summary
Identify the differences between stand-alone applications and applets
Describe the role of the Java Virtual Machine Create a simple Java program Use Java comments Compile and execute a Java program Describe the differences between *.java and *.class files
![Page 7: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/7.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 2:Data Types,
Variables and Operators
![Page 8: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/8.jpg)
Objectives
• Use primitive data types• Declare a variable• Distinguish between local and class variables• Distinguish between implicit and explicit
casting• Use the operators for primitive types
![Page 9: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/9.jpg)
Data Types
• Primitives– Integers– Floating-point numbers– Character– Boolean
![Page 10: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/10.jpg)
Declaring Variablesand Variable Scope
• Types– Local– Instance– Class
• Default variable values• Variable declaration and initialization• Casting
– Implicit– Explicit
![Page 11: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/11.jpg)
Casting Rules Chart
byte short int long float double
char
![Page 12: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/12.jpg)
Operators
• Arithmetic operators• Relational operators• Logical operators
– Short-circuit• Bitwise operators
![Page 13: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/13.jpg)
AutomaticCasting
• Java automatically casts– bytes or shorts ints– floats doubles
![Page 14: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/14.jpg)
Summary
Use primitive data types Declare a variable Distinguish between local and class variables Distinguish between implicit and explicit
casting Use the operators for primitive types
![Page 15: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/15.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 3:Control
Statements
![Page 16: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/16.jpg)
Objectives
• Explain the block structure of Java• Use Java conditional statements• Use Java iterative statements
![Page 17: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/17.jpg)
Code Blocks
• Used to group the contents of a class or a method
• Used to designate all conditional and iterative statements
• Used for exception handling
![Page 18: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/18.jpg)
Conditional Statements
• if statement
• switch/case statement– break statement
![Page 19: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/19.jpg)
Iterative Statements (Loops)
• while loop (entry condition loop)• do while loop (exit condition loop)• for loop• Nested loops (break and continue)
![Page 20: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/20.jpg)
Summary
Explain the block structure of Java Use Java conditional statements Use Java iterative statements
![Page 21: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/21.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 4:Methods
![Page 22: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/22.jpg)
Objectives
• Create and use static methods• Return a value from a method• Explain pass by value• Describe overloading methods• Identify the method signature
![Page 23: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/23.jpg)
JavaMethods
• The executable part of a class– Member
![Page 24: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/24.jpg)
Return Statement
• Data types• Void
![Page 25: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/25.jpg)
Calling a Method
• Parameters• Literals
![Page 26: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/26.jpg)
Pass by Value
• A copy of the value of the variable is available to the method; changes to the copy do not affect the original value
![Page 27: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/27.jpg)
Overloading
• Method signature– Name– Parameter list
• Does not include return type
![Page 28: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/28.jpg)
Summary
Create and use static methods Return a value from a method Explain pass by value Describe overloading methods Identify the method signature
![Page 29: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/29.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 5:Arrays
![Page 30: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/30.jpg)
Objectives
• Declare and initialize an array• Allocate space for a new array• Describe array indexing• Use the length property• Discuss why arrays are passed by reference• Discuss Java’s garbage collection mechanism• Retrieve command line parameters
![Page 31: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/31.jpg)
What Is an Array?
• Collection of same type• Non-primitive data type
![Page 32: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/32.jpg)
Initializing an Array
• Allocation• Reference• Index
![Page 33: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/33.jpg)
Objects
• Properties• Methods
![Page 34: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/34.jpg)
Using an Array
• length property
![Page 35: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/35.jpg)
1
0
3
1
5
2
MyIntArray
tmpIntArray
Passing an Array to a Method
![Page 36: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/36.jpg)
Garbage Collection
• Variable name reuse• Memory leak
![Page 37: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/37.jpg)
Command Line Parameters
• Always String type data
![Page 38: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/38.jpg)
Summary
Declare and initialize an array Allocate space for a new array Describe array indexing Use the length property Discuss why arrays are passed by reference Discuss Java’s garbage collection mechanism Retrieve command line parameters
![Page 39: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/39.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 6:Classes
and Objects
![Page 40: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/40.jpg)
Objectives
• Identify the parts of an object• Create and use instance members• Distinguish between instance and class
members• Define abstraction• Create object references
![Page 41: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/41.jpg)
Object-Oriented Programming
• Refers to the creation of a number of objects that communicate with one another
![Page 42: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/42.jpg)
What Isan Object?
• Instantiation• The new keyword
![Page 43: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/43.jpg)
Instance andClass Members
• Class members– The exception in Java
• Instance members– The rule in Java
• Accessing instance members– Dot notation
• Accessing class members
![Page 44: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/44.jpg)
Abstraction
• What does the object do versus how does it do it?
• Functionality versus implementation
![Page 45: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/45.jpg)
Object References
rachael
tmpEmp
name: "Rachael"dept: "Accounting"salary: 52000
tmpEmp variable
![Page 46: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/46.jpg)
Summary
Identify the parts of an object Create and use instance members Distinguish between instance and class
members Define abstraction Create object references
![Page 47: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/47.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 7:Inheritance
![Page 48: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/48.jpg)
Objectives
• Create a new class using inheritance• Create an overridden method
![Page 49: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/49.jpg)
What Is Inheritance?
• Code reuse• Using inheritance
– extends keyword– subclass– superclass– Multiple inheritance
![Page 50: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/50.jpg)
Overriding Methods
• Same signature as the superclass• super.method()
![Page 51: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/51.jpg)
Summary
Create a new class using inheritance Create an overridden method
![Page 52: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/52.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 8:Constructors
![Page 53: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/53.jpg)
Objectives
• Use the default constructor• Create a constructor to initialize instance
variables• Call other constructors from the same class
and the parent class• Create a no-arguments constructor• Discuss String characteristics and define the
common methods of String
![Page 54: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/54.jpg)
What Is a Constructor?
• new keyword• Similarities to methods
– Initialization of object– Pass parameters
• Differences from methods– Same name as class– No return type
• Callback
![Page 55: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/55.jpg)
Using Constructors
• Default constructor– No arguments– Must be explicitly created if there are any
other constructors• Overloading constructors
– Unique parameter types
![Page 56: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/56.jpg)
The Keyword this
• this() as a constructor• Avoiding namespace conflicts• The super keyword
![Page 57: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/57.jpg)
Constructors and Callbacks
• Constructors are a major facilitator in establishing interobject communication
![Page 58: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/58.jpg)
Strings and StringBuffer
• String constructors• String characteristics• Methods of String• StringBuffer
![Page 59: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/59.jpg)
Summary
Use the default constructor Create a constructor to initialize instance
variables Call other constructors from both the same
class and the parent class Create a no-arguments constructor Discuss String characteristics and define the
common methods of String
![Page 60: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/60.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 9:Interfaces and Abstract Classes
![Page 61: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/61.jpg)
Objectives
• Define and use interfaces• Define polymorphism• Use abstract classes• Create an abstract method
![Page 62: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/62.jpg)
What Is an Interface?
• Contents of an interface– Abstract methods– Final variables
• Interface functions– Decoupling objects– Providing data type
![Page 63: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/63.jpg)
Polymorphism
• Using one method name to invoke many different methods
![Page 64: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/64.jpg)
What Is an Abstract Class?
• Cannot be instantiated• Can be used for a type
![Page 65: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/65.jpg)
Summary
Define and use interfaces Define polymorphism Use abstract classes Create an abstract method
![Page 66: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/66.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 10:Packages and Access Modifiers
![Page 67: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/67.jpg)
Objectives
• Compile and run a class with packages• Identify the packages in the Java 2 API• Identify the various access levels in Java• Describe how access modifiers can be used to
set the access level of a variable, method or class
• Describe the object-oriented programming principle of encapsulation
• Identify accessor and mutator methods
![Page 68: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/68.jpg)
Packages and Access Modifiers
• Packages– import statement
• Access modifiers– public– protected– package– private
![Page 69: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/69.jpg)
Java 2 Application Programming Interface
• Organized into packages such as– java.lang– java.awt– java.io– java.util– java.net
![Page 70: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/70.jpg)
Encapsulation
• Accessor– Method that reads a variable
• Mutator– Wrapping variables and methods together
![Page 71: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/71.jpg)
ObjectEncapsulation
Data 1Data 2Data 3Data 4
![Page 72: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/72.jpg)
Summary
Compile and run a class with packages Identify the packages in the Java 2 API Identify the various access levels in Java Describe how access modifiers can be used to
set the access level of a variable, method or class
Describe the object-oriented programming principle of encapsulation
Identify accessor and mutator methods
![Page 73: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/73.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 11:Swing Components
![Page 74: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/74.jpg)
Objectives
• Distinguish between the AWT and Swing• Identify the general organization of the Swing
class structure• Define and use Swing widgets and containers
![Page 75: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/75.jpg)
What Is the AWT?
• Heavyweight components– Peer components
• AWT 1.0– Container propagation– Single-method event-handling
• AWT 1.1– New event model
![Page 76: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/76.jpg)
What Is Swing?
• Lightweight components– No peer components– All Java
• Customizable• Model View Controller (MVC) programming
paradigm• Included in Java 2 (JDK 1.2)
![Page 77: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/77.jpg)
Basic Swing Components
• JComponent• JLabel• JButton• JTextField• JTextArea• JScrollBar
• ImageIcon• JScrollPane• JPanel• JFrame• JFileChooser• JApplet
![Page 78: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/78.jpg)
Graphical Widgets
• The graphical components with which users interact– JButton– JLabel– JScrollBar
![Page 79: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/79.jpg)
SwingContainers
• Two types– Top level (includes JFrame, Window)– Lower level (includes JPanel, JScrollPane)
![Page 80: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/80.jpg)
Summary
Distinguish between the AWT and Swing Identify the general organization of the Swing
class structure Define and use Swing widgets and containers
![Page 81: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/81.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 12:Layout Managers
![Page 82: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/82.jpg)
Objectives
• Define a layout manager• Set a layout manager for a Container• Effectively use FlowLayout, GridLayout, BorderLayout and BoxLayout
• Nest containers and layout managers to form more complex GUI layouts
• Separate a complex design into its component containers and layout managers
![Page 83: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/83.jpg)
What Is a Layout Manager?
• FlowLayout• GridLayout• BorderLayout• BoxLayout• CardLayout
• GridBagLayout• GridLayout• OverlayLayout• ScrollPaneLayout• ViewportLayout
![Page 84: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/84.jpg)
FlowLayout
• Centers components on each line in a flowing manner
![Page 85: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/85.jpg)
GridLayout
• Adds components in a gridlike format
![Page 86: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/86.jpg)
BorderLayout
CENTER
EAST
WEST
SOUTH
NORTH
![Page 87: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/87.jpg)
BoxLayout
• Allows either a horizontal or a vertical layout of components
![Page 88: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/88.jpg)
CombiningLayouts
Button 1
Button 2
Button 3
Button 4
![Page 89: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/89.jpg)
Summary
Define a layout manager Set a layout manager for a Container Effectively use FlowLayout, GridLayout, BorderLayout and BoxLayout
Nest containers and layout managers to form more complex GUI layouts
Separate a complex design into its component containers and layout managers
![Page 90: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/90.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 13:Graphics in Java
![Page 91: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/91.jpg)
Objectives
• Identify the AWT class structure for graphics• Gain access to a container’s graphic context
by overriding the paint(Graphics g) method
• Use methods of the Graphics class via the graphics context
• Effectively use the Color and Font classes
![Page 92: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/92.jpg)
Graphics Class
• The graphics context is used to access the functionality of the Graphics class (an abstract class)
![Page 93: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/93.jpg)
Graphics Class Methods
• draw3DRect()• drawArc()• drawLine()• drawOval()• drawPolygon()• drawPolyline()• drawRect()
• drawRoundRect()• fill3DRect()• fillArc()• fillOval()• fillPolygon()• fillRect()• fillRoundRect()
![Page 94: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/94.jpg)
Other Classes
• Color setColor()• Font setFont()
– FontMetrics
![Page 95: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/95.jpg)
Summary
Identify the AWT class structure for graphics
Gain access to a container’s graphic context by overriding the paint(Graphics g) method
Use methods of the Graphics class via the graphics context
Effectively use the Color and Font classes
![Page 96: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/96.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 14:The Event
Delegation Model
![Page 97: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/97.jpg)
Objectives
• Describe the event delegation model• Create listener classes that can respond to
events• Register listener classes with their Component sources
• Capture events and deal with them in meaningful ways
![Page 98: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/98.jpg)
What Is an Event?
• What caused the event?• What was the exact nature of the event?• Is additional information available about
the event?
![Page 99: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/99.jpg)
JDK 1.0 Event Handling
• Tightly coupled with the AWT• Inefficient• General• Unruly• Code and event handling could not be
separated
![Page 100: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/100.jpg)
SDK 1.2 Event Handling
• Generating the event object• Sending the event object to the listener• Preparing the listener to receive the event• Example: Creating a closeable JFrame• JFrame convenience methods for event
handling• Example: Event handling and callbacks
![Page 101: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/101.jpg)
Summary
Describe the event delegation model Create listener classes that can respond to
events Register listener classes with their Component sources
Capture events and deal with them in meaningful ways
![Page 102: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/102.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 15:Inner Classes
![Page 103: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/103.jpg)
Objectives
• Define an inner class• Recognize the advantages of inner classes
over package-level classes in relation to event handling
• Design and implement inner classes for event handling
![Page 104: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/104.jpg)
What Is an Inner Class?
• A class defined within other classes• Introduced with the SDK 1.2
![Page 105: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/105.jpg)
Inner Classes for Event Handling
• Member inner classes• Anonymous inner classes
![Page 106: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/106.jpg)
Summary
Define an inner class Recognize the advantages of inner classes
over package-level classes in relation to event handling
Design and implement inner classes for event handling
![Page 107: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/107.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 16:Java Applets
![Page 108: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/108.jpg)
Objectives
• Compare and contrast Java applets and applications
• Implement the life cycle of an applet through its inherited methods
• Embed an applet into an HTML document• Pass parameters from an HTML document to
its contained applet• Identify applet security restrictions• Convert an applet into an application
![Page 109: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/109.jpg)
JApplet Class Hierarchy
Object
Component
Applet
Panel
Container
JApplet
![Page 110: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/110.jpg)
Applets and Web Browsers
• Applets do not have a main() method• Applets have a life cycle• Applets are started from HTML pages, and
receive information from HTML pages• Because they are program code, applets
should not be trusted
![Page 111: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/111.jpg)
Converting an Application into an Applet
• Use init() method to perform instantiation
• Instantiating the applet is unnecessary• Applets must be derived from JApplet• Applet size should be set within the HTML
document (the Web browser makes it visible)
• Applets must be declared public
![Page 112: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/112.jpg)
Converting an Applet into an Application
• By adding an instance of the JApplet to the JFrame and calling its init() and start() methods, the conversion from JApplet to stand-alone JFrame readily takes place
![Page 113: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/113.jpg)
Summary
Compare and contrast Java applets and applications
Implement the life cycle of an applet through its inherited methods
Embed an applet into an HTML document Pass parameters from an HTML document to
its contained applet Identify applet security restrictions Convert an applet into an application
![Page 114: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/114.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 17:Exceptions
![Page 115: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/115.jpg)
Objectives• Differentiate between errors and
exceptions• Differentiate between runtime exceptions
and explicit exceptions• Propagate an exception using the throws
statement• Handle an exception using the try/catch
statement• Create and use a user-defined exception
![Page 116: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/116.jpg)
What Is an Exception?
• Exceptions– Runtime exceptions (unchecked)– Other exceptions (checked)
![Page 117: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/117.jpg)
Exception Class Hierarchy
![Page 118: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/118.jpg)
HandlingExceptions
• Ignore the Exception• Handle the Exception with a try/catch
statement• Throw the Exception to the calling method• Handle the Exception and rethrow it to the
calling method
![Page 119: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/119.jpg)
Creating User-Defined Exceptions
• Creating the exception• Throwing the exception• Exception handling tips
![Page 120: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/120.jpg)
Exception Handling Tips
• Use simple tests instead of try/catch• Choose user-defined exceptions wisely• Use one try/catch block for multiple
exceptions• Do something meaningful with caught
exceptions
![Page 121: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/121.jpg)
Summary
Differentiate between errors and exceptions Differentiate between runtime exceptions and
explicit exceptions Propagate an exception using the throws
statement Handle an exception using the try/catch
statement Create and use a user-defined exception
![Page 122: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/122.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 18:Creating Threads
and Thread Methods
![Page 123: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/123.jpg)
Objectives
• Define threads• Create and instantiate threads using two
different techniques• Control single-thread flow• Define the four thread states and their
relationships to thread methods
![Page 124: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/124.jpg)
What Are Threads?
• Multitasking• Multiprocessing• Multithreading
![Page 125: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/125.jpg)
How Operating Systems Handle Multitasking
• Pre-emptive multitasking• Cooperative multitasking
![Page 126: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/126.jpg)
Types of Threads in Java
• Daemon thread• User thread
– Main thread– Other user threads
![Page 127: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/127.jpg)
The Main Thread
main thread
user thread user thread
user thread user thread
![Page 128: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/128.jpg)
Creating Threads
• Subclassing the Thread class• Implementing the Runnable interface• Which technique?
![Page 129: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/129.jpg)
Summary
Define threads Create and instantiate threads using two
different techniques Control single-thread flow Define the four thread states and their
relationships to thread methods
![Page 130: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/130.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 19:Thread
Synchronization
![Page 131: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/131.jpg)
Objectives
• Define synchronization in relation to object monitors
• Control thread racing using thread synchronization
• Convert non-atomic to atomic processes to avoid thread racing
• Use sophisticated methods for controlling threads
• Stop, suspend and resume threads• Explain thread deadlock
![Page 132: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/132.jpg)
What Is Thread Synchronization?
• Controlling threads in a predictable manner
![Page 133: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/133.jpg)
Thread Racing
• Two threads trying to access the same data
![Page 134: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/134.jpg)
Synchronized and the Object Monitor
• synchronized keyword• Threads waiting in a queue to obtain an
objects monitor• All synchronized methods of an object use a
single monitor
![Page 135: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/135.jpg)
Thread Race Condition
• Competing for resources• Synchronizing the methods• Atomic processes
![Page 136: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/136.jpg)
Sophisticated Thread Synchronization
• Consumer/producer scenario
![Page 137: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/137.jpg)
Stopping, Suspending and Resuming Threads
• Stopping a thread• Suspending a thread• Resuming a thread
![Page 138: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/138.jpg)
Summary
Define synchronization in relation to object monitors
Control thread racing using thread synchronization
Convert non-atomic to atomic processes to avoid thread racing
Use sophisticated methods for controlling threads
Stop, suspend and resume threads Explain thread deadlock
![Page 139: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/139.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 20:Streams and Serialization
![Page 140: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/140.jpg)
Objectives
• Define a stream• Differentiate between byte streams and
character streams• Recognize the abstraction of byte streams
through the InputStream and OutputStream classes
• Recognize the abstraction of character streams through the Reader and Writer classes
• Create and use file objects
![Page 141: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/141.jpg)
Objectives (cont’d)
• Use System.in and System.out to perform stream operations
• Nest streams using wrapper classes to enhance basic stream behavior
• Perform file I/O• Define object serialization• Use serialization to save an object to a file• Explain the transient keyword
![Page 142: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/142.jpg)
What Is a Stream?
• A path of information from a source to a destination
![Page 143: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/143.jpg)
InputStream, OutputStream, Reader and Writer
• JDK 1.0 (bytes)– InputStream– OutputStream
• JDK 1.1 (characters)– Reader– Writer
![Page 144: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/144.jpg)
Files
• Instantiating a file object• Working with a file object
– Methods of File– Directories– FileDialog/FileChooser
![Page 145: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/145.jpg)
Stream Classes of java.io.*
• System.in and System.out• Reading bytes from System.in• Converting a byte stream into a character
stream• Wrapper streams• File I/O
![Page 146: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/146.jpg)
Serialization
• The process of object serialization– Marking an object for serialization– Writing the object to file– Reading the serialized object from a file
• Transient variables and security
![Page 147: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/147.jpg)
Summary
Define a stream Differentiate between byte streams and
character streams Recognize the abstraction of byte streams
through the InputStream and OutputStream classes
Recognize the abstraction of character streams through the Reader and Writer classes
Create and use file objects
![Page 148: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/148.jpg)
Summary (cont’d)
Use System.in and System.out to perform stream operations
Nest streams using wrapper classes to enhance basic stream behavior
Perform file I/O Define object serialization Use serialization to save an object to a file Explain the transient keyword
![Page 149: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/149.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 21:Networking in Java
![Page 150: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/150.jpg)
Objectives
• Define networking, IP addresses, the Domain Name System, and ports
• Discuss the socket model and socket-to-socket communication
• Explain the client/server model• Write a single-threaded client/server echo
system• Write a multithreaded client/server echo
system
![Page 151: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/151.jpg)
What Is Networking?
• Computers communicating across distances• Java networking
– TCP/IP– UDP
![Page 152: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/152.jpg)
Connecting Computers Across the Internet
• IP addresses– Dotted quad– 32 bits– IPv6
• DNS• Sockets• Well-known ports
![Page 153: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/153.jpg)
Well-Known Ports and Their Protocols
Port Protocol
21 FTP
23 Telnet
25 E-mail
79 Finger
80 HTTP
119 NNTP/Usenet
![Page 154: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/154.jpg)
Networking Classes of java.net.*
• Common networking classes– InetAddress– Socket– ServerSocket
![Page 155: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/155.jpg)
The Java Client/Server Model
• Server– Delivers information– ServerSocket object– accept method returns a socket
• Client– Requests information from the server– Connects to server with socket
![Page 156: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/156.jpg)
Building the EchoServer
• The client– Step 1: getConnection– Step 2: sendMessage– Step 3: receiveMessage
• The server– Step 1: getConnection– Step 2: receiveMessage– Step 3: sendMessage
![Page 157: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/157.jpg)
MultithreadingYour Client/Server Model
• Modifications to the server• The Connection class• The Client class• Running the threaded client/server example
![Page 158: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/158.jpg)
Summary
Define networking, IP addresses, the Domain Name System, and ports
Discuss the socket model and socket-to-socket communication
Explain the client/server model Write a single-threaded client/server echo
system Write a multithreaded client/server echo
system
![Page 159: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/159.jpg)
Java Programming Fundamentals
Java Runtime Environment Data Types, Variables and Operators Control Statements Methods Arrays Classes and Objects Inheritance Constructors
![Page 160: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/160.jpg)
Java Programming Fundamentals
Interfaces and Abstract Classes Packages and Access Modifiers Swing Components Layout Managers Graphics in Java The Event Delegation Model Inner Classes
![Page 161: Copyright © 2002 ProsoftTraining. All rights reserved. Java Programming Fundamentals.](https://reader038.fdocuments.net/reader038/viewer/2022110213/56649f555503460f94c79755/html5/thumbnails/161.jpg)
Java Applets Exceptions Creating Threads and Thread Methods Thread Synchronization Streams and Serialization Networking in Java
Java Programming Fundamentals