introduction to java 2 programming n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Introduction to Java 2 Programming PowerPoint Presentation
Download Presentation
Introduction to Java 2 Programming

Loading in 2 Seconds...

play fullscreen
1 / 17

Introduction to Java 2 Programming - PowerPoint PPT Presentation


  • 121 Views
  • Uploaded on

Introduction to Java 2 Programming. Lecture 10 API Review; Where Next. Overview. Reviewing the Java API Some packages we’ve seen And some new ones… Coding and Design Tips Tips for good Java programs Where Next? Books, Websites, Tutorials. java.lang. The real core of the Java API

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Introduction to Java 2 Programming' - agostino


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
introduction to java 2 programming

Introduction to Java 2 Programming

Lecture 10

API Review; Where Next

overview
Overview
  • Reviewing the Java API
    • Some packages we’ve seen
    • And some new ones…
  • Coding and Design Tips
    • Tips for good Java programs
  • Where Next?
    • Books, Websites, Tutorials
java lang
java.lang
  • The real core of the Java API
    • Automatically imported by all Java classes
  • System and Runtime classes
    • Access to the virtual machine
    • System properties
    • Standard input, output, error
  • The Number classes
    • Boolean, Integer, Float, Double, Long, Short, etc
    • Provide OO version of primitive types
    • Provide conversion functions (e.g. to/from String)
  • The Class and Object classes
    • Object is the root of the Java inheritance tree
    • Class is an OO description of a Java class
java util
java.util
  • Large collection utility classes, and several sub-packages
  • Collection classes, very flexible data structures
    • Implementations of Set, List and Map interfaces
    • Arrays and Collections classes, for sorting and searching collections
  • Calendar and Date classes for providing date utilities
  • Other miscellaneous classes
    • Currency, StringTokenizer, etc
java util1
java.util
  • java.util.logging
    • Provides access to a complete logging system, for recording application progress, error messages, etc
    • Very flexible (different log levels, different log formats, different log destinations)
  • java.util.zip, java.util.jar
    • Classes for working with zip and jar files.
    • Built in compression libraries
  • java.util.regex
    • “Regular Expressions”
    • Pattern matching system adopted from Perl
    • Very flexible way to process text strings (e.g. to extract substrings, find data, etc)
java io
java.io
  • The Java I/O classes
  • InputStreams and OutputStreams
    • Reading and writing data
  • Readers and Writers
    • Reading and writing text (according to a character set)
  • File
    • OO representation of the file system (both files and directories)
java net
java.net
  • Socket
    • Standard Berkeley socket implementation for connecting to remote service
    • ServerSocket class for writing servers
  • URL
    • Describes a remote website, and gives access to its data via a Stream
  • HTTPURLConnection
    • Provides more detailed access to a remote website
    • E.g. follow redirects, write to remote website, etc
    • (but not as flexible as a true HTTP library)
java rmi
java.rmi
  • “Remote Method Invocation”
  • A standard way to call methods on objects on a remote machine
    • No need to deal with networking!
  • A Registry lists all the useful objects on the remote machine
    • Client gets reference to object from a registry, and then uses it as normal
  • Remote objects have to implement an special interface
    • All methods throw RemoteException
  • Very powerful
java sql
java.sql
  • Java database access layer
    • Known as JDBC (“Java DataBase Connectivity”)
  • Allows a Java application to
    • ..get a Connection to a database
    • …create and execute Statements to query the database
    • …and then process the ResultSet that is returned
  • All major database vendors have implemented a Java “JDBC Driver”
    • The core API describes the basic interfaces
    • The vendor implements that for their database system
java awt
java.awt
  • “Abstract Windowing Toolkit”
    • The original way to build GUI applications in Java
  • Limited capabilities
    • Few components
    • API poorly designed (particularly event handling)
    • Not entirely portable (not pure Java)
  • Still used for some applications, but has been replaced…
javax swing
javax.swing
  • Java Foundation Classes (“Swing”)
    • Replacement for AWT (but does share some common classes)
  • Much more flexible
    • 100% Java (therefore truly portable)
    • More components, more sophisticated
    • Pluggable “Look and Feel” support
    • Better graphics support
    • Support for Drag and Drop, etc
  • Some downsides, though
    • Can be slower than AWT
    • Memory hungry
    • Large and complex API (to meet all requirements)
overview1
Overview
  • Reviewing the Java API
    • Some packages we’ve seen
    • And some new ones…
  • Coding and Design Tips
    • Tips for good Java programs
  • Where Next?
    • Books, Websites, Tutorials
java coding tips
Java Coding Tips
  • Never re-invent the wheel!
  • Never write a new class, if an existing one can be extended in some way
    • Either through inheritance (or wrapping)
  • Look for third-party APIs
    • E.g. jakarta.apache.org
  • Only then write something yourself
java coding tips1
Java Coding Tips
  • Make good use of polymorphism
    • Use base class references where possible
      • Allows you to change the concrete implementation
  • Make good use of inheritance
    • Add functionality by extending. Don’t rewrite original class
    • But don’t overuse it, aggregation is often better
  • Never break encapsulation
    • Practice “defensive programming”
    • Don’t return objects you don’t want changed, copy them instead.
java coding tips2
Java Coding Tips
  • Use Collections and Iterators, not arrays and for loops
    • More functionality, easier to work with
  • Spend time thinking about your object model
    • …but don’t worry about getting it right first time
  • Learn from others
    • Read other peoples code, see how they’ve tackled similar problems
java coding tips3
Java Coding Tips
  • Best tip of all:
  • Get to know the core Java API
    • Read through the Javadoc
    • Try building simple test classes to manipulate the objects
where next
Where Next?
  • The Java Tutorial
    • Covers all the core functionality very thoroughly
    • Divided into “trails” so easy to dip into to learn about specific functionality
    • (Some bits aren’t as up to date as they might be, however)
  • “Thinking in Java” (Bruce Eckel)
    • Excellent OO introduction to Java programming
  • “Design Patterns” (Gang of Four)
    • Recipes for designing OO applications
  • “Refactoring” (Martin Fowler)
    • Improving the design of existing OO code