Java Fundamental Classes Reference



Similar documents
The Java I/O System. Binary I/O streams (ascii, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)

INPUT AND OUTPUT STREAMS

Socket Programming in Java

NETWORK PROGRAMMING IN JAVA USING SOCKETS

Programming in Java

CS 1302 Ch 19, Binary I/O

J2ME Building Blocks for Mobile Devices

Principles of Software Construction: Objects, Design, and Concurrency. Design Case Study: Stream I/O Some answers. Charlie Garrod Jonathan Aldrich

JAVA IN A NUTSHELL O'REILLY. David Flanagan. Fifth Edition. Beijing Cambridge Farnham Köln Sebastopol Tokyo

What is an I/O Stream?

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0

File I/O - Chapter 10. Many Stream Classes. Text Files vs Binary Files

Readings and References. Topic #10: Java Input / Output. "Streams" are the basic I/O objects. Input & Output. Streams. The stream model A-1.

WRITING DATA TO A BINARY FILE

Socket Programming. A er learning the contents of this chapter, the reader will be able to:

An Overview of Java. overview-1

public static void main(string[] args) { System.out.println("hello, world"); } }

Creating a Simple, Multithreaded Chat System with Java

CS 111 Classes I 1. Software Organization View to this point:

Java Card 2.2 Virtual Machine Specification. Sun Microsystems, Inc. 901 San Antonio Road Palo Alto, CA USA fax

Lesson: All About Sockets

Java from a C perspective. Plan

Java Network Programming. The java.net package contains the Socket class. This class speaks TCP (connection-oriented protocol).

Input / Output Framework java.io Framework

Chapter 20 Streams and Binary Input/Output. Big Java Early Objects by Cay Horstmann Copyright 2014 by John Wiley & Sons. All rights reserved.

Building a Multi-Threaded Web Server

C# Cookbook. Stephen Teilhet andjay Hilyard. O'REILLY 8 Beijing Cambridge Farnham Köln Paris Sebastopol Taipei Tokyo '"J""'

Files and input/output streams

Network-based Applications. Pavani Diwanji David Brown JavaSoft

Fundamentals of Java Programming

D06 PROGRAMMING with JAVA

CS506 Web Design and Development Solved Online Quiz No. 01

Interview Questions in Core Java

Files and Streams. Writeappropriatecodetoread,writeandupdatefilesusingFileInputStream, FileOutputStream and RandomAccessFile objects.

JAVA. EXAMPLES IN A NUTSHELL. O'REILLY 4 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo. Third Edition.

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

JAVA INTERVIEW QUESTIONS

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

Stream Classes and File I/O

Web Development in Java

Chapter 10. A stream is an object that enables the flow of data between a program and some I/O device or file. File I/O

Quick Introduction to Java

!"# $ %!&' # &! ())*!$

Smallest Java Package? Java.applet.* having 1 class and 3 interfaces. Applet Class and AppletContext, AppletStub, Audioclip interfaces.

Today s Outline. Computer Communications. Java Communications uses Streams. Wrapping Streams. Stream Conventions 2/13/2016 CSE 132

JAVA - FILES AND I/O

PYTHON IN A NUTSHELL. O'REILLY Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo. Alex Martelli. Second Edition

Java Interview Questions and Answers

Question1-part2 What undesirable consequences might there be in having too long a DNS cache entry lifetime?

CISC 4700 L01 Network & Client- Server Programming Spring Harold, Chapter 8: Sockets for Clients

Mail User Agent Project

Schneps, Leila; Colmez, Coralie. Math on Trial : How Numbers Get Used and Abused in the Courtroom. New York, NY, USA: Basic Books, p i.

Package java.net. Interfaces. Classes. Exceptions. Package java.net Page 1 of 1. All Packages

READING DATA FROM KEYBOARD USING DATAINPUTSTREAM, BUFFEREDREADER AND SCANNER

Java Programming Fundamentals

AVRO - SERIALIZATION

Introduction to Java. Module 12: Networking (Java Sockets) Prepared by Costantinos Costa for EPL 233. ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1

Crash Course in Java

SSC - Communication and Networking Java Socket Programming (II)

Contents. 9-1 Copyright (c) N. Afshartous

Java Application Developer Certificate Program Competencies

The difference between TCP/IP, UDP/IP and Multicast sockets. How servers and clients communicate over sockets

String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivepacket.getaddress(); int port = receivepacket.

Learning Outcomes. Networking. Sockets. TCP/IP Networks. Hostnames and DNS TCP/IP

Application Programming Interface

1 of 1 24/05/ :23 AM

How to program Java Card3.0 platforms?

AP Computer Science Java Subset

J2ME: Step by step. Presented by developerworks, your source for great tutorials ibm.com/developerworks

Network Communication

INFORMATION BROCHURE

Java the UML Way: Integrating Object-Oriented Design and Programming

Advanced Network Programming Lab using Java. Angelos Stavrou

Event-Driven Programming

Assignment 4 Solutions

Introduction to Java. CS 3: Computer Programming in Java

Transport layer protocols. Message destination: Socket +Port. Asynchronous vs. Synchronous. Operations of Request-Reply. Sockets

Java Network. Slides prepared by : Farzana Rahman

The Interface Concept

Windows PowerShell Cookbook

core 2 Basic Java Syntax

Serializing Data with Protocol Buffers. Vinicius Vielmo Cogo Smalltalks, DI, FC/UL. February 12, 2014.

Network/Socket Programming in Java. Rajkumar Buyya

C#5.0 IN A NUTSHELL. Joseph O'REILLY. Albahari and Ben Albahari. Fifth Edition. Tokyo. Sebastopol. Beijing. Cambridge. Koln.

JAVA - EXCEPTIONS. An exception can occur for many different reasons, below given are some scenarios where exception occurs.

CHAPTER 6. Transmission Control Protocol. 6.1 Overview

RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE. CISY 105 Foundations of Computer Science

public static void main(string args[]) { System.out.println( "f(0)=" + f(0));

D06 PROGRAMMING with JAVA

! "# $%&'( ) * ).) "%&' 1* ( %&' ! "%&'2 (! ""$ 1! ""3($

JAVA r VOLUME II-ADVANCED FEATURES. e^i v it;

Socket-based Network Communication in J2SE and J2ME

2 Categories of Constraints

Transcription:

Java Fundamental Classes Reference Mark Grand and Jonathan Knudsen O'REILLY Cambridge Köln Paris Sebastopol Tokyo

v Table of Contents Preface xv 1. Introduction 1 1.1 The java.lang Package 2 1.2 The java.lang.reflect Package 3 1.3 The java.io Package 3 1.4 Thejava.net Package 5 1.5 The java.util Package 5 1.6 The java.text Package 6 1.7 The java.math Package...-. 7 1.8 The javautil.zip Package 7 1. USING THE FUNDAMENTAL CLASSES 9 2. Strings and Related Classes 11 2.1 String 11 2.2 StringBuffer 13 2.3 String Concatenation 14 2.4 StringTokenizer 15 3. Threads 17 3.1 Using Thread Objects 18 3.2 Synchronizing Multiple Threads 24

VI TABLE OF CONTENTS 4. Exception Handling 32 4.1 Handling Exceptions 32 4.2 Declaring Exceptions., 33 4.3 Generating Exceptions 35 5. Collections 39 5.1 Enumerations 39 5.2 Vectors 40 5.3 Stacks 42 5.4 Hashtables,., 42 6. I/O 46 6.1 Input Streams and Readers 46 6.2 Output Streams and Writers 55 6.3 File Manipulation 63 7. Object Serialization 67 7.1 Object Serialization Basics, 67 7.2 Writing Classes to Work with Serialization. 68 7.3 Versioning of Classes. 71 8. Networking 75 8.1 Sockets 75 8.2 URL Objects 85 9. Security 89 9.1 SecurityManager».89 9.2 ClassLoader 91 10. Accessing the Environment 93 10.1 I/O, 93 10.2 System Properties 94 10.3 Environment Variables, 96 10.4 External Program Execution 96 10.5 Garbage Collection 97 10.6 Self Termination 97

TABLE OF CONTENTS vii II. REFERENCE 99 11. The java.io Package 101 11.1 BufferedlnputStream 102 11.2 BufferedOutputStream 108 11.3 BufferedReader Ill 11.4 BufferedWriter 115 11.5 ByteArraylnputStream 119 11.6 ByteArrayOutputStream."....122 11.7 CharArrayReader 126 11.8 CharArrayWriter 131 11.9 CharConversionException 135 11.10 Datalnput 136 11.11 DatalnputStream 140 11.12 DataOutput 749 11.13 DataOutputStream 152 11.14 EOFException 757 11.15 Externalizable 759 11.16 File.'. 767 11.17 FileDescriptor 769 11.18 FilelnputStream 777 11.19 FilenameFilter.775 11.20 FileNotFoundException 776 11.21 FileOutputStream...778 11.22 FileReader 782 11.23 FileWriter 784 11.24 FilterlnputStream 787 11.25 FilterOutputStream 797 11.26 FilterReader 794 11.27 FilterWriter 798 11.28 InputStream 207 11.29 InputStreamReader 205 11.30 InterruptedlOException 208 11.31 InvalidClassException 270 11.32 InvalidObjectException 272

viii TABLE OF CONTENTS 11.33 IOException. ;... 213 11.34 LineNumberlnputStream 215 11.35 LineNumberReader, 218 11.36 NotActiveException... 222 11.37 NotSerializableException 223 11.38 Objectlnput...225 11.39 ObjectJnputStream 227 11.40 ObjectlnputValidation 240 11.41 ObjectOutput 242 11.42 ObjectOutputStream, 244 11.43 ObjectStreamClass 253 11.44 ObjectStreamException 255 11.45 OptionalDataException 256 11.46 OutputStream 258 11.47 OutputStreamWriter...260 11.48 PipedlnputStream 264 11.49 PipedOutputStream 268 11.50 PipedReader..". 271 11.51 PipedWriter 274 11.52 PrintStream 276 11.53 PrintWriter...283 11.54 PushbacklnputStream 297 11.55 PushbackReader 295 11.56 RandomAccessFile 298 11.57 Reader 311 11.58 SequencelnputStream 315 11.59 Serializable 318 11.60 StreamCorruptedException 320 11.61 StreamTokenizer 321 11.62 StringBufferlnputStream 329 11.63 StringReader 332 11.64 StringWriter 336 11.65 SyncFailedException 339 11.66 UnsupportedEncodingException 340

TABLE OF CONTENTS ix * 11.67 UTFDataFormatException 342 11.68 WriteAbortedException..;... 343 11.69 Writer...,. 345 12. Thejava.lang Package 350 12.1 AbstractMethodError 352 12.2 ArithmeticException 354 12.3 ArraylndexOutOfBoundsException 355 12.4 ArrayStoreException 357 12.5 Boolean...,. 358 12.6 Byte..... 361 12.7 Character 368 12.8 Class..!.,.. 386 12.9 ClassCastException 401 12.10 ClassCircularityError 403 12.11 ClassFormatError 404 12.12 ClassLoader 405 12.13 ClassNotFoundException 413 12.14 Cloneable 414 12.15 CloneNotSupportedException 415 12.16 Compiler 417 12.17 Double 419 12.18 Error...!...'..!...'. 428 12.19 Exception 430 12.20 ExceptionlnlnitializerError 432 12.21 Float 433 12.22 IllegalAccessError.1... 442 12.23 IllegalAccessException 444 12.24 IllegalArgumentException 445 12.25 IllegalMonitorStateException 446 12.26 IllegalStateException 448 12.27 IllegalThreadStateException 449 12.28 IncompatibleClassChangeError 450 12.29 IndexOutOfBoundsException 452 12.30 Integer 453

x TABLE OF CONTENTS 12.31 InstantiationError 463 12.32 InstantiationException 464 12.33 InternalError 466 12.34 InterruptedException...467 12.35 LinkageError 468 12.36 Long 470 12.37 Math.. 479 12.38 NegativeArraySizeException 497 12.39 NoClassDefFoundError 493 12.40 NoSuchFieldError 494 12.41 NoSuchFieldException 495 12.42 NoSuchMethodError 497 12.43 NoSuchMediodException 498 12.44 NullPointerException 499 12.45 Number 501 12.46 NumberFormatException 503 12.47 Object 504 12.48 OutOfMemoryError 514 12.49 Process...515 12.50 Runnable 518 12.51 Runtime 519 12.52 RuntimeException 527 12.53 SecurityException.529 12.54 SecurityManager 530 12.55 Short 547 12.56 StackOverflowError 554 12.57 String 555 12.58 StringBuffer 575 12.59 StringlndexOutOfBoundsException 585 12.60 System 587 12.61 Thread 598 12.62 ThreadDeatii.612 12.63 ThreadGroup 613 12.64 Throwable 621

TABLE OF CONTENTS xi 12.65 UnknownError 624 12.66 UnsatisfiedLinkError 625 12.67 VerifyError 627 12.68 VirtualMachineError 628 12.69 Void 630 13. The java.lang.reflect Package 637 13.1 Array 632 13.2 Constructor 643 13.3 Field 647 13.4 InvocationTargetException 658 13.5 Member 659 13.6 Method 661 13.7 Modifier 665 14. The java.math Package 671 14.1 BigDecimal 671 14.2 Biglnteger 683 15. The java.net Package 697 15.1 BindException 697 15.2 ConnectException 700 15.3 ContentHandler 701 15.4 ContentHandlerFactory,. 702 15.5 DatagramPacket 704 15.6 DatagramSocket 707 15.7 DatagramSocketlmpl 711 15.8 FileNameMap 715 15.9 HttpURLConnection, 716 15.10 InetAddress 726 15.11 MalfonnedURLException 730 15.12 MulticastSocket 731 15.13 NoRouteToHostException 735 15.14 ProtocolException 736 15.15 ServerSocket 737 15.16 Socket 743

xii TABLE OF CONTENTS 15.17 SocketException... i 752 15.18 Socketlmpl 753 15.19 SocketlmplFactory...».,...,. 758 15.20 URL u 759 15.21 URLConnection....767 15.22 URLEncoder 782 15.23 URLStreamHandler 784 15.24 URLStreamHandlerFactory 787 15.25 UnknownHostException 788 15.26 UnknownServiceException 789 16. Thejava.text Package 797 16.1 Breaklterator * 793 16.2 Characterlterator 799 16.3 ChoiceFormat 802 16.4 CollationElementlterator 808 16.5 CollationKey 811 16.6 Collator 813 16.7 DateFormat i 819 16.8 DateFormatSymbols 831 16.9 DecimalFormat 836 1-6.10 DecimalFormatSymbols» 844 16.11 FieldPosition 850 16.12 Format 852 16.13 MessageFormat.:.,... 854 16.14 NumberFormat.-....; 861 16.15 ParseException 870 16.16 ParsePosition 872 16.17 RuleBasedCollator 873 16.18 SimpleDateFormat 877 16.19 StringCharacterlterator.,...;...; 882

TABLE OF CONTENTS xiii 17. Thejava.util Package 888 17.1 BitSet....890 17.2 Calendar. 894 17.3 Date, 972 17.4 Dictionary 921 17.5 EmptyStackException 923 17.6 Enumeration 924 17.7 EventListener 926 17.8 EventObject 927 17.9 GregorianCalendar 929 17.10 Hashtable 937 17.11 ListResourceBundle 943 17.12 Locale 945 17.13 MissingResourceException 955 17.14 NoSuchElementException 956 17.15 Observable 958 17.16 Observer 961 17.17 Properties 962 17.18 PropertyResourceBundle 966 17.19 Random 968 17.20 ResourceBundle 971 17.21 SimpleTimeZone 976 17.22 Stack 981 17.23 StringTokenizer 983 17.24 TimeZone 987 17.25 TooManyListenersException 991 17.26 Vector 993 18. The java.util.zip Package 1001 18.1 Adler32 1003 18.2 CheckedlnputStream 1005 18.3 CheckedOutputStream 7007 18.4 Checksum 7009 18.5 CRC32 7077 18.6 DataFormatException 7073

xiv TABLE OF CONTENTS 18.7 Deflater J 1014 18.8 DeflaterOutputStream...1021 18.9 GZIPInputStream 1:1 1025 18.10 GZIPOütpütStream...:.. 1028 18.11 Inflater...:... 1030 18.12 InflaterlnputStream 7035 18.13 ZipEntry 7039 18.14 ZipException '.. 7044 18.15 ZipFile 7045 * 18.16 ZipInputStream...: 7048 18.17 ZipOutputStream 7057 III. APPENDIXES i 7057 A. The Unicode 2.0 Character Set 7059 B. The UTF-8 Encoding 7063 Index 7065