logo资料库

Programming in Java(2nd) 无水印pdf.pdf

第1页 / 共695页
第2页 / 共695页
第3页 / 共695页
第4页 / 共695页
第5页 / 共695页
第6页 / 共695页
第7页 / 共695页
第8页 / 共695页
资料共695页,剩余部分请下载后查看
Cover
About the Authors
Preface to the First Edition
Preface to the Second Edition
Brief Contents
Detailed Contents
1. Introduction to OOP
1.1 Introduction
1.2 Need of Object-Oriented Programming
1.2.1 Procedural Languages
1.2.2 Object-Oriented Modeling
1.2.2.1 Attributes
1.2.2.2 Behavior
1.3 Principles of Object-Oriented Languages
1.3.1 Classes
1.3.2 Objects
1.3.3 Abstraction
1.3.4 Inheritance
1.3.5 Encapsulation
1.3.6 Polymorphism
1.4 Procedural Language vs OOP
1.5 OOAD Using UML
1.6 Applications of OOP
Summary
Exercises
2. Getting Started with Java
2.1 Introduction
2.2 History of Java
2.3 Java's Journey: From Embedded Systems to Middle-Tier Applications
2.4 Java Essentials
2.5 Java Virtual Machine
2.6 Java Features
2.6.1 Platform Independence
2.6.2 Object Oriented
2.6.3 Both Compiled and Interpreted
2.6.3.1 Interpretation
2.6.3.2 Compilation
2.6.3.3 Java Approach
2.6.4 Java is Robust
2.6.5 Java Language Security Features
2.6.5.1 Java Security Model
2.6.5.2 Sandbox - Definition
2.6.6 Java is Multithreaded
2.6.7 Other Features
2.6.7.1 Automatic Memory Management
2.6.7.2 Dynamic Binding
2.6.7.3 Good Performance
2.6.7.4 Built-in Networking
2.6.7.5 No Pointers
2.6.7.6 No Global Variables
2.7 Program Structure
2.7.1 How to Execute a Java Program?
2.7.2 Why Save as Example.java?
2.7.3 Explanation
2.8 Java Improvements
2.8.1 Java 5.0 Features
2.8.1.1 Autoboxing and Unboxing
2.8.1.2 Enhanced for Loop
2.8.1.3 Enumerated Types
2.8.1.4 StringBuilder Class
2.8.1.5 Static Import
2.8.1.6 Metadata
2.8.1.7 Formatted I/O and VarArgs
2.8.1.8 Graphics System Improvements
2.8.1.9 New Concurrency Features
2.8.1.10 Generics
2.8.2 Java 6 Features
2.8.2.1 Collections API
2.8.2.2 Input/Output
2.8.2.3 Jar and Zip Enhancements
2.8.2.4 Enhancements Common to Java Web Start and Java Plug-in
2.8.2.5 Enhanced Network Interface
2.8.2.6 Splash Screen
2.8.3 Java 7 Features
2.8.3.1 String in switch...case Statement
2.8.3.2 Unicode 6.0.0 Support
2.8.3.3 Binary Literals and Numeric Literals with Underscores
2.8.3.4 Automatic Resource Management
2.8.3.5 Improved Exception Handling
2.8.3.6 nio 2.0 Non-Blocking I/O - New File System API
2.8.4 Brief Comparison of Different Releases
2.9 Differences between Java and C++
2.10 Installation of JDK 1.7
2.10.1 Getting Started with the JDK
2.10.2 JDK Installation Notes
2.10.2.1 Step 1: Run the JDK Installer
2.10.2.2 Installed Directory Structure
2.10.2.3 Step 2: Update Path and Classpath Variables
2.10.2.4 Setting the Classpath
2.10.2.5 Step 3: Testing the Installation
2.10.3 Exploring the JDK
2.10.3.1 Tools in JDK
2.10.3.2 Basic Tools
2.11 Integrated Development Environment
Summary
Exercises
3. Java Programming Constructs
3.1 Variables
3.2 Primitive Data Types
3.3 Identifier
3.3.1 Rules for Naming
3.3.2 Naming Convention
3.3.3 Keywords
3.4 Literals
3.5 Operators
3.5.1 Binary Operators
3.5.1.1 Assignment Operators
3.5.1.2 Arithmetic Operators
3.5.1.3 Relational Operators
3.5.1.4 Boolean Logical Operators
3.5.1.5 Bitwise Operators
3.5.2 Unary Operators
3.5.2.1 Increment and Decrement Operators
3.5.3 Ternary Operators
3.6 Expressions
3.7 Precedence Rules and Associativity
3.8 Primitive Type Conversion and Casting
3.9 Flow of Control
3.9.1 Conditional Statements
3.9.1.1 if...else
3.9.1.2 switch-case
3.9.2 Loops
3.9.2.1 for Loop
3.9.2.2 while Loop
3.9.2.3 do-while Loop
3.9.2.4 for-each Loop
3.9.3 Branching Mechanism
3.9.3.1 break Statement
3.9.3.2 continue Statement
Summary
Exercises
4. Classes and Objects
4.1 Classes
4.2 Objects
4.2.1 Difference between Objects and Classes
4.2.2 Why Should We Use Objects and Classes?
4.3 Class Declaration in Java
4.3.1 Class Body
4.3.1.1 Instance Variables
4.4 Creating Objects
4.4.1 Declaring an Object
4.4.2 Instantiating an Object
4.4.3 Initializing an Object
4.5 Methods
4.5.1 Why Use Methods?
4.5.2 Method Type
4.5.3 Method Declaration
4.5.4 Instance Method Invocation
4.5.5 Method Overloading
4.6 Constructors
4.6.1 Parameterized Constructors
4.6.2 Constructor Overloading
4.7 Cleaning Up Unused Objects
4.7.1 Garbage Collector
4.7.2 Finalization
4.7.3 Advantages and Disadvantages
4.8 Class Variables and Methods - static Keyword
4.8.1 Static Variables
4.8.2 Static Methods
4.8.3 Static Initialization Block
4.9 this Keyword
4.10 Arrays
4.10.1 One-Dimensional Arrays
4.10.1.1 Creation of Array
4.10.1.2 How to Use for Loops with Arrays?
4.10.2 Two-Dimensional Arrays
4.10.3 Using for-each with Arrays
4.10.4 Passing Arrays to Methods
4.10.5 Returning Arrays from Methods
4.10.6 Variable Arguments
4.11 Command-Line Arguments
4.12 Nested Classes
4.12.1 Inner Class
4.12.2 Static Nested Class
4.12.3 Why Do We Create Nested Classes?
4.13 Practical Problem: Complex Number Program
Summary
Exercises
5. Inheritance
5.1 Inheritance vs Aggregation
5.1.1 Types of Inheritance
5.1.2 Deriving Classes Using extends Keyword
5.2 Overriding Method
5.3 super Keyword
5.4 final Keyword
5.5 Abstract Class
5.6 Shadowing vs Overriding
5.7 Practical Problem: circle and cylinder Class
Summary
Exercises
6. Interfaces, Packages, and Enumeration
6.1 Interfaces
6.1.1 Variables in Interface
6.1.2 Extending Interfaces
6.1.3 Interface vs Abstract Class
6.2 Packages
6.2.1 Creating Packages
6.2.1.1 Saving, Compiling, and Executing Packages
6.2.1.2 Setting the Classpath
6.2.1.3 Subpackages
6.2.2 Using Packages
6.2.2.1 Static Import
6.2.3 Access Protection
6.3 java.lang Package
6.3.1 java.lang.Object Class
6.3.2 Java Wrapper Classes
6.3.2.1 Wrapper Classes: Constructors and Methods
6.3.2.2 Ordinary Methods
6.3.2.3 Parser Methods
6.3.2.4 Autoboxing and Unboxing of Wrappers
6.3.3 String Class
6.3.3.1 String Manipulation
6.3.3.2 String Methods
6.3.4 StringBuffer Class
6.3.5 StringBuilder Class
6.3.6 Splitting Strings
6.4 enum Type
6.4.1 Using Conditional Statements with an Enumerated Variable
6.4.2 Using for Loop for Accessing Values
6.4.3 Attributes and Methods within Enumeration
6.5 Practical Problem: Banking Example
Summary
Exercises
7. Exception, Assertions, and Logging
7.1 Introduction
7.1.1 Exception Types
7.2 Exception Handling Techniques
7.2.1 try...catch
7.2.2 throw Keyword
7.2.3 throws
7.2.4 finally Block
7.2.5 try-with-resources Statement
7.2.6 Multi catch
7.2.7 Improved Exception Handling in Java 7
7.3 User-Defined Exception
7.4 Exception Encapsulation and Enrichment
7.5 Assertions
7.6 Logging
Summary
Exercises
8. Multithreading in Java
8.1 Introduction
8.2 Multithreading in Java
8.3 java.lang.Thread
8.4 main Thread
8.5 Creation of New Threads
8.5.1 By Inheriting the Thread Class
8.5.2 Implementing the Runnable Interface
8.6 Thread.State in Java
8.7 Thread Priority
8.8 Multithreading - Using isAlive and join
8.9 Synchronization
8.9.1 Synchronized Methods
8.9.2 Synchronized Statements
8.10 Suspending and Resuming Threads
8.11 Communication between Threads
8.12 Practical Problem: Time Clock Example
Summary
Exercises
9. Input/Output, Serialization, and Cloning
9.1 Introduction
9.1.1 java.io.InputStream and java.io.OutputStream
9.2 java.io.File Class
9.3 Reading and Writing Data
9.3.1 Reading/Writing Files Using Byte Stream
9.3.2 Reading/Writing Console User Input
9.3.3 Reading/Writing Files Using Character Stream
9.3.4 Reading/Writing Using Buffered Byte Stream Classes
9.3.5 Reading/Writing Using Buffered Character Stream Classes
9.4 Randomly Accessing a File
9.5 Reading and Writing Files Using New I/O Package
9.6 Java 7 nio Enhancements
9.7 Serialization
9.8 Cloning
Summary
Exercises
Project Work
10. Generics, java.util, and other API
10.1 Introduction
10.2 Generics
10.2.1 Using Generics in Arguments and Return Types
10.2.2 Wildcards
10.2.3 Bounded Wildcards
10.2.4 Defining Your Own Generic Classes
10.3 Linked List
10.4 Set
10.4.1 HashSet Class
10.4.2 TreeSet Class
10.5 Maps
10.5.1 HashMap Class
10.5.2 TreeMap Class
10.6 Collections Class
10.7 Legacy Classes and Interfaces
10.7.1 Difference between Vector and ArrayList
10.7.2 Difference between Enumerations and Iterator
10.8 Utility Classes: Random Class
10.8.1 Observer and Observable
10.9 Runtime Class
10.10 Reflection API
Summary
Exercises
11. Network Programming
11.1 Introduction
11.1.1 TCP/IP Protocol Suite
11.2 Sockets
11.2.1 TCP Client and Server
11.2.1.1 How to Run the Client and Server?
11.2.2 UDP Client and Server
11.3 URL Class
11.4 Multithreaded Sockets
11.5 Network Interface
Summary
Exercises
12. Applets
12.1 Introduction
12.2 Applets
12.3 Applet Structure
12.4 An Example Applet Program
12.4.1 How to Run an Applet?
12.5 Applet Life Cycle
12.6 Common Methods Used in Displaying the Output
12.7 paint, update, and repaint
12.7.1 paint Method
12.7.2 update Method
12.7.3 repaint Method
12.8 More about APPLET Tag
12.9 getDocumentBase and getCodeBase Methods
12.10 AppletContext Interface
12.10.1 Communication between Two Applets
12.11 How to Use an Audio Clip?
12.12 Images in Applet
12.12.1 MediaTracker Class
12.13 Graphics Class
12.13.1 An Example Applet Using Graphics Class
12.14 Color Class
12.15 Font Class
12.16 FontMetrics Class
12.17 Practical Problem: Digital Clock
Summary
Exercises
13. Event Handling in Java
13.1 Introduction
13.2 Event Delegation Model
13.3 java.awt.event Package
13.3.1 Event Classes
13.3.1.1 ActionEvent Class
13.3.1.2 AdjustmentEvent Class
13.3.1.3 KeyEvent Class
13.3.1.4 MouseEvent Class
13.3.1.5 FocusEvent Class
13.3.1.6 ItemEvent Class
13.3.1.7 TextEvent Class
13.4 Sources of Events
13.5 Event Listeners
13.6 How Does the Model Work?
13.7 Adapter Classes
13.7.1 How to Use Adapter Classes?
13.7.2 Adapter Classes in Java
13.8 Inner Classes in Event Handling
13.9 Practical Problem: Cartoon Applet
13.9.1 Smiling Cartoon with Blinking Eyes Part 1
13.9.2 Smiling Cartoon with Blinking Eyes Part 2
13.9.3 Smiling Cartoon Part 3
Summary
Exercises
14. Abstract Window Toolkit
14.1 Introduction
14.1.1 Why AWT?
14.1.2 java.awt Package
14.2 Components and Containers
14.2.1 Component Class
14.2.2 Components as Event Generator
14.3 Button
14.4 Label
14.5 Checkbox
14.6 Radio Buttons
14.7 List Boxes
14.8 Choice Boxes
14.9 TextField and TextArea
14.10 Container Class
14.10.1 Panels
14.10.1.1 How to Use Panels?
14.10.2 Window
14.10.3 Frame
14.11 Layouts
14.11.1 FlowLayout
14.11.2 BorderLayout
14.11.3 CardLayout
14.11.4 GridLayout
14.11.5 GridBagLayout
14.11.5.1 gridx and gridy
14.11.5.2 gridwidth and gridheight
14.11.5.3 fill
14.11.5.4 ipadx and ipady
14.11.5.5 insets
14.11.5.6 anchor
14.11.5.7 weightx and weighty
14.12 Menu
14.13 Scrollbar
14.14 Practical Problem: City Map Applet
Summary
Exercises
15. Swing
15.1 Introduction
15.1.1 Features of Swing
15.1.2 Differences between Swing and AWT
15.2 JFrame
15.3 JApplet
15.4 JPanel
15.5 Components in Swings
15.6 Layout Managers
15.6.1 SpringLayout
15.6.2 BoxLayout
15.7 JList and JScrollPane
15.8 Split Pane
15.9 JTabbedPane
15.10 JTree
15.11 JTable
15.12 Dialog Box
15.13 JFileChooser
15.14 JColorChooser
15.15 Pluggable Look and Feel
15.16 Inner Frames
15.17 Practical Problem: Mini Editor
Summary
Exercises
16. Introduction to Advanced Java
16.1 Introduction to J2EE
16.2 Database Handling Using JDBC
16.2.1 Load the Driver
16.2.1.1 Type 1: JDBC ODBC Bridge Driver
16.2.1.2 Type 2: Native-API/Partly Java Driver
16.2.1.3 Type 3: Net-Protocol Driver
16.2.1.4 Type 4: Pure Java Driver
16.2.2 Establish Connection
16.2.3 Create Statements
16.2.4 Execute Query
16.2.5 Iterate ResultSet
16.2.6 Scrollable ResultSet
16.2.7 Transactions
16.3 Servlets
16.3.1 Lifecycle of Servlets
16.3.2 First Servlet
16.3.2.1 How to Run the Servlet?
16.3.3 Reading Client Data
16.3.4 HTTP Redirects
16.3.5 Cookies
16.3.6 Session Management
16.3.6.1 Hidden Fields
16.3.6.2 URL Rewriting
16.3.6.3 Cookies
16.3.6.4 Session API
16.4 Practical Problem: Login Application
16.5 Introduction to Java Server Pages
16.5.1 JSP Life Cycle
16.5.2 Steps in JSP Page Execution
16.5.3 JSP Elements
16.5.3.1 Directives
16.5.3.2 Expressions
16.5.3.3 Scriptlets
16.5.3.4 Declarations
16.5.3.5 Actions
16.5.4 Placing Your JSP in the Webserver
16.6 Java Beans
16.6.1 Properties of a Bean
16.6.1.1 Basic Properties
16.6.1.2 Indexed Properties
16.6.1.3 Bound Properties
16.6.1.4 Constrained Properties
16.6.2 Using Beans through JSP
16.6.2.1 Accessing Bean Properties in JSP
16.6.2.2 Setting Bean Properties through JSP
16.6.3 CalculateBean Example
16.6.3.1 Directory Structure for the Example
16.7 JAR Files
16.7.1 Creating a JAR File
16.7.2 Viewing the Contents of a JAR File
16.7.3 Extracting the Contents of JAR
16.7.4 Manifest Files
16.7.4.1 Modifying a Manifest File
16.7.4.2 Application Bundled in JAR
16.8 Remote Method Invocation
16.8.1 RMI Networking Model
16.8.1.1 Stub and Skeleton
16.8.2 Creating an RMI Application
16.8.2.1 Server Class
16.8.2.2 Executing RMI Server and Client
16.9 Introduction to EJB
16.9.1 Types of EJB
16.9.1.1 Entity Bean
16.9.1.2 Session Beans
16.9.1.3 Message-Driven Beans
16.9.2 EJB Architecture
16.10 Hello World - EJB Example
Summary
Exercises
Features of the Book
Appendices
Appendix A: Lab Manual - Java Lab Exercises
A.1 Introduction, Compiling, and Executing a Java Program
A.2 Program with Data Types and Variables
A.3 Program with Decision Control Structures: if, nested-if, etc.
A.4 Program with Loop Control Structures: do, while, for, etc.
A.5 Program on Usage of switch-case and if Conditional Statements
A.6 Program with Classes and Objects
A.7 Copy Constructor and Constructor Overloading
A.8 A Program on Function Overloading
A.9 Implementing Inheritance
A.9.1 Single Inheritance
A.9.2 Multiple Inheritance
A.9.3 Multilevel Inheritance
A.9.4 Use of Abstract Classes
A.10 Implementing Interfaces
A.10.1 Developing User-Defined Interfaces and Implementation
A.10.2 Use of Predefined Interfaces
A.11 Handling Strings
A.12 Implementing Packages
A.13 Implementing Wrapper Classes
A.14 Exception Handling Mechanism in Java
A.14.1 Handling Predefined Exceptions
A.14.2 Handling User-Defined Exceptions
A.15 Concept of Threading
A.15.1 Creation of Thread in Java Applications
A.15.2 Multithreading
A.16 Working with Files
A.17 Implementing Generics
Appendix B: Interview Questions
Index
#
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Programming in Java Second Edition SACHIN MALHOTRA Associate Professor IMS, Ghaziabad SAURABH CHOUDHARY Formerly, Head IT Department IMS, Ghaziabad 1
3 Oxford University Press is a department of the University of Oxford. It furthers the University’s objective of excellence in research, scholarship, and education by publishing worldwide. Oxford is a registered trade mark of Oxford University Press in the UK and in certain other countries. Published in India by Oxford University Press YMCA Library Building, 1 Jai Singh Road, New Delhi 110001, India © Oxford University Press 2010, 2014 The moral rights of the author/s have been asserted. First Edition published in 2010 Second Edition published in 2014 All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, without the prior permission in writing of Oxford University Press, or as expressly permitted by law, by licence, or under terms agreed with the appropriate reprographics rights organization. Enquiries concerning reproduction outside the scope of the above should be sent to the Rights Department, Oxford University Press, at the address above. You must not circulate this work in any other form and you must impose this same condition on any acquirer. ISBN-13: 978-0-19-809485-2 ISBN-10: 0-19-809485-X Typeset in Times New Roman by Sukuvisa Enterprises Printed in India by Yash Printographics, Noida 201301
Dedicated to Our Parents
About the Authors Sachin Malhotra is currently Associate Professor in the IT department of IMS Ghaziabad. He has more than a decade long experience in mentoring students on developing Java applications as well as training practising professionals in the fi eld of Java. He has also designed and conducted various corporate trainings in Java and networking. Saurabh Choudhary is currently a practising IT consultant and corporate trainer. He has more than 12 years of experience in industry, academia, and consultancy. He has worked on positions of eminence at IMS Ghaziabad as Head of IT department and Dean Academics (University Campus). His areas of expertise include Java, Database Management System, and Information Systems. Testimonials From pervasive computing to communications industry, medical science to aeros pace, Java is gaining a foothold in every domain. Programming in Java has been written to arouse the interest even in a novice computer programmer to an expert, craving to sharpen his programming skills. Pankaj Verma | Senior Software Engineer | OSI Inc. It is defi nitely the best textbook on Java that I have run into. I highly recommend it. Sachin Dhama | Team Lead | Accenture Java is a very powerful language for developing enterprise applications. I am hopeful that this book will provide a basic building platform for Java programmers to enhance their knowledge. Awadhesh Kumar Katiyar | Technical Lead | HCL Technologies Ltd. Java enables users to develop applications on the Internet for servers, desktops computers, and small handheld devices. The future of computing is being infl uenced by the Internet, and Java promises to play a big part in it. This book is perfect for those who are seeking a clear understanding of Java. It should allow the readers to create codes that are a lot clearer and are far more effective than before. Saurabh Moondhra | Sr. Technical Consultant | SGT Inc This is the most interesting Java programming book for beginners; at the same time, it is equally good for intermediate readers as well. This should be your fi rst Java book if you are learning from scratch. Pankaj Jain | Senior Manager | Bank of America When you go through this book, you will gain confi dence after completing each chapter. The authors have written it in such a simple way covering each and every aspect of Java that anyone can learn how to develop effective codes. Rajeev Varshney | Lead Consultant | HCL NZ Ltd.
Preface to the First Edition Java was primarily designed as a platform-independent language for usage in small consumer electronic devices. It was derived from C++ but with a lot of difference. Java’s platform independence originally addressed the problem that applications for embedded devices must run on a wide variety of hardware. But since the Internet was emerging at the same time, Java soon got adopted as an Internet language because of its portable nature. Major Internet browsers such as Netscape Navigator and Microsoft Internet Explorer became Java-compatible, as it effectively addressed the concerns for security by providing a fi rewall between web applications and the computer. Eventually it became a standard programming language and is now being used for creating a variety of applications including standalone applications, web applications, enterprise-wide applications, and mobile games. It can therefore be inferred that since its inception, Java has emerged as the most important programming language. As the domain of Java is quite vast and a bit more complex than other programming languages such as C, C++, and Visual Basic, it is observed that students and novice programmers strive hard to comprehend its core concepts. Hence, a need for a book in this area, which is both concise and simple, is a necessity. About the Book The book encapsulates the concepts of the latest version of Java, i.e. Java 6, encompassing a comprehensive coverage of curriculum and industry expectations. It is useful for the students of undergraduate and postgraduate courses of computer science and engineering and information technology disciplines as well as for the instructors at various levels. The book provides a thorough understanding of the basic concepts of object-oriented programming principles and gradually moves on to the advanced concepts in Java. It includes numerous examples, line-by-line description of examples, fi gures, explanation of concepts, and key notes. Review questions and programming exercises are included as chapter-end exercises to assess the learning outcomes. Every topic in the book is supported by examples followed by an output and explanation. It also offers an appendix on general interview questions which provides students an insight into the current requirements of the industry and allows them to prepare accordingly. The main features of this book include the following:  an exhaustive coverage of Java features such as operators, classes, objects, inheritance, packages, and exception handling  comprehensive discussion on the latest features of Java such as enumerations, generics, logging API, console class, StringBuilder class, NetworkInterface class, and assertions  latest features combined with core concepts such as multithreading, applets, AWT, and swings  an introduction to the advanced concepts in Java such as servlets, RMI, and JDBC    
Preface to the First Edition xi Appendix A: Lab Manual—Java Lab Exercises XI ACKNOWLEDGEMENTS Several people have been instrumental throughout this tiring yet wonderful journey. First of all, we would like to express our sincere gratitude to our families without whose support, patience, and cooperation, this would not have been possible and we would not have been what we are today. We are very thankful to Dr R. K. Bharadwaj, Head of our institution, for his inspirational thoughts which inculcated urgency for writing this book. We are also thankful to our colleagues for their endless support and suggestions during the entire process of writing this book. Sachin Malhotra Saurabh Choudhary
Preface to the Second Edition Java is an easy-to-learn, versatile, robust, portable, and secure language with rich user interfaces. It has set up new benchmarks in the software development world ranging from desktop to web- based enterprise applications to mobile and embedded applications. Since its inception in 1995, it has come a long way by continuously evolving itself and in the process, changing the style of programming the world over. Java is not only found in laptops or data centres, it is also widely used in cell phones, SIM cards, smart cards, printers, routers and switches, set-top boxes, ATMs, and navigation systems, to name a few. According to Oracle, a staggering 1.1 billion desktops and 3 billion cell phones are based on Java. This second edition of Programming in Java confi rms to Java Standard Edition 7, the latest release since Oracle took over Sun Microsystems. It is signifi cant in the sense that the last update was six years back and this major release comes bundled with plenty of enhancements which were overdue. To list a few noticeable enhancements, Java 7 includes support for strings in switch and try-with-resources statements, improved multi-catch, binary numeric literals, numeric literals with underscores, new APIs in NIO such as path and fi les, automatic resource management, and much more. All the new topics are appropriately explained with suitable examples. New to the Second Edition This revised edition has been updated thoroughly with greater topical coverage as well as more programming examples in every chapter, in addition to the confi rmation to Java 7. Practically every chapter, with the exception of Chapter 11, has been revisited to refi ne the text as much as possible. The most noticeable changes are as follows:  New practical programming examples to show how Java is used in practice.  Enhanced coverage of servlets and JDBC along with an introduction to JSP, Java beans, Jar fi les and enterprise Java beans  Enhanced coverage of swing components like JTree, JTable, layered pane, JDesktopPane, internal frames, JColorChooser, JFileChooser, and JEditorPane  New classes of java.nio package and project coin language enhancements  Enhanced coverage of utility classes  Appendix B contains more interview questions to help students prepare for their interviews.  The second edition is supplemented with a rich online resource centre that contains chapter- wise PPTs for teachers and additional practical programming examples for students. Key Features The most prominent feature of this book has been the line-by-line explanation section under each program. They facilitate in-depth understanding of the whole program. We have retained this feature in the second edition as it has been well appreciated by the users. Other noticeable features include the following:  
 Preface to the Second Edition vii  A recap of object-oriented programming concepts before introducing the concepts of Java  Plenty of user-friendly programs and key notes at appropriate places to highlight important concepts  A variety of end-chapter exercises that includes subjective as well as objective questions Extended Chapter Material The second edition includes the following changes: Chapter 1, Introduction to OOP: Enhanced coverage of UML and its application in pictorial representation of OOP concepts. Chapter 2, Getting Started with Java: New sections about the features of Java 7 and how to install JDK 1.7. Chapter 3, Java Programming Constructs: Numeric literals with underscores, binary numeric literals, and how to use strings in switch statements. Chapter 4, Classes and Objects: New topics such as inner classes, variable length arguments, arrays as return values from methods, and objects as arguments to and return type from methods. It contains a practical problem on complex numbers to demonstrate how OOP concepts can be put to practise. Chapter 5, Inheritance: New section that highlights the differences between shadowing and overriding. At the end of the chapter, there is a practical programming example on circle and cylinder class. Chapter 6, Interfaces, Packages, and Enumeration: Practical problem on banking concepts to demonstrate the usage of packages in creating applications. Chapter 7, Exception, Assertions, and Logging: try-with-resources and catching multiple exceptions features which are new enhancements of Java 7. Chapter 8, Multithreading in Java: Concrete practical example to show the use of threads in applications. Chapter 9, Input/Output, Serialization, and Cloning: New classes included in java.nio package and how to perform cloning of objects. Chapter 10, Generics, java.util and other API: Utility classes like Random class, Runtime class, Observer and Observable and refl ection API. Chapter 12, Applets: how to use threads and images in applets. The practical problem at the end of the chapter explains how to display a digital clock. Chapter 13, Event Handling in Java: Practical programming example that explains how to create a cartoon on applet and performs its event handling. This is actually a series of examples with gradual and step-by-step revision in all of them in order to enhance their functionality and then eliminate their drawbacks. Chapter 14, Abstract Window Toolkit: Mini project like programming example on CityMap Applet. The applet shows the map of a city from top angle with fi ve buttons, namely, Hospitals, Shopping Malls, Police station, Post Offi ce, and Stadium. If a user presses the Hospital button, all the hospitals are shown on the map with a specifi c color and likewise for Malls, Police station, Post offi ce and Stadium. Chapter 15, Swing: Explanation of new classes with examples and also includes a practical programming example to create a mini text editor. Chapter 16, Introduction to Advanced Java: Introductory sections on JSP, Java Beans, Jar fi les and enterprise Java beans with lots of examples apart from enhanced coverage of servlets and JDBC. This chapter also encompasses a login application built using servlets and database to demonstrate how to create and use a web application.
分享到:
收藏