We use cookies to enhance your experience on our website. By continuing to use our website, you are agreeing to our use of cookies. You can change your cookie settings at any time. Find out more
Cover

Advanced Java Programming

Uttam K. Roy

May 2015

ISBN: 9780199455508

880 pages
Paperback
246x189mm

In Stock

Price: £30.99

Share:

Description

Advanced Java Programming is a textbook specially designed for undergraduate and postgraduate students of Computer Science, Information Technology, and Computer Applications (BE/BTech/BCA/ME/M.Tech/MCA). Divided into three parts, the book provides an exhaustive coverage of topics taught in advanced Java and other related subjects.

  • Exhaustive coverage of advanced topics on Java from tools to enterprise Java
  • Provides ample application-based examples, with step-by-step explanations
  • Provides thorough understanding of each topic through extensive examples along with the program codes and screenshots
  • Provides relevant software installation and configuration information wherever necessary
  • Comprises keywords, objective-type questions (with answers) and subjective-type questions for students at the end of all the chapters

About the Author(s)

Uttam K. Roy

Uttam K. Roy is working as a faculty in the Department of Information Technology, Jadavpur University, Kolkata. He completed his PhD in engineering from the same university and has nearly 11 years of teaching experience. He has contributed numerous research papers to various international journals. His research interests include Bio-informatics, Voice processing, Optimization, Quantum Computing.

Table of Contents

    PART I: INSIDE JAVA 1
    1. Java Tools 3
    1.1 Introduction 3
    1.2 Javadoc 3
    1.3 Javap 7
    1.4 Jcmd 9
    1.5 Jhat 12
    1.6 Jdb 13
    1.7 Jar 18
    1.7.1 Syntax 19
    1.7.2 Creating a JAR File 19
    1.7.3 Viewing Contents of a JAR File 20
    1.7.4 Extracting the Content 20
    1.7.5 Updating a JAR File 21
    1.7.6 Manifest File 21
    2. Exception Handling 26
    2.1 Exceptions 26
    2.2 Handling Exceptions 27
    2.3 An Example 28
    2.4 Types of Exceptions 28
    2.4.1 Checked Exceptions 29
    2.4.2 Unchecked/Runtime Exceptions 29
    2.5 Catching Exception 29
    2.6 Tracing Stack 30
    2.6.1 Multiple Catch Blocks 30
    2.6.2 throw 31
    2.6.3 throws 33
    2.6.4 finally 34
    2.6.4.1 An example 35
    2.6.4.2 Some properties 36
    2.6.5 try-with-resources Statement 37
    2.6.6 Nested try-catch 39
    2.7 Custom Exception Classes 40
    3. Multi-threading 45
    3.1 Introduction 45
    3.2 Main Thread 45
    3.3 Using Sleep 46
    3.4 Creating Thread 47
    3.4.1 Extending Thread 47
    3.4.2 Implementing Runnable 48
    3.5 Interrupting Thread 49
    3.6 Suspending and Resuming 51
    3.7 Thread Priority 52
    3.8 Using join() 53
    3.9 Synchronization 55
    3.9.1 Synchronization and Atomicity 59
    4.13 Accessing GC from Java Program 83
    4.13.1 Inspecting GC Parameters 83
    4.13.2 Explicit Garbage Collection 84
    4.13.3 finalize() 84
    4.14 Appendix 84
    5. Collection Framework 92
    5.1 Introduction 92
    5.2 Benefits 93
    5.3 Collection Interfaces 94
    5.4 Collection Implementation 95
    5.4.1 Set 95
    5.4.1.1 HashSet 96
    5.4.1.2 LinkedHashSet 97
    5.4.2 SortedSet 98
    5.4.2.1 TreeSet 98
    5.4.3 List 98
    5.4.3.1 ArrayList 99
    5.4.3.2 LinkedList 100
    5.4.4 Queue 100
    5.4.4.1 LinkedList 101
    5.4.4.2 PriorityQueue 102
    5.4.5 Map 102
    5.4.5.1 HashMap 103
    5.4.5.2 LinkedHashMap 104
    5.4.6 SortedMap 105
    5.4.6.1 TreeMap 105
    5.5 Algorithms 105
    5.5.1 Sorting 106
    5.5.1.1 Custom sort 106
    5.5.2 Shuffling 106
    5.5.3 Manipulation 107
    5.5.3.1 Reversing 107
    5.5.3.2 Swapping 107
    5.5.3.3 Copying 107
    5.5.3.4 Filling 107
    5.5.3.5 Adding 107
    5.5.4 Searching 108
    5.5.5 Finding Extreme Values 108
    5.5.6 Counting Frequency 108
    6. Generic Programming 113
    6.1 Introduction 113
    6.2 Motivation 114
    6.3 Solution 114
    6.4 Collection Framework and Generics 116
    6.5 Type Naming 117
    6.6 Generic Methods and Constructors 117
    6.7 Type Inference 118
    6.7.1 Generic Methods 118
    6.7.2 Constructors 119
    6.7.3 Classes 19
    6.8 Bounded Type Parameters 119
    6.8.1 Multiple Bounds 120
    6.9 Generics and Sub-type 121
    6.10 Wildcards 122
    6.10.1 Upper-bound Wildcard 123
    6.10.2 Lower-bound Wildcard 124
    6.10.3 Unbounded Wildcard 124
    6.10.4 Wildcard and Sub-typing 125
    6.11 Type Erasure 125
    6.12 Backward Compatibility 126
    6.13 Restrictions on Generics 127
    6.13.1 Cannot Specify Primitive Type Arguments 127
    6.13.2 Cannot Declare Static Fields of Type Parameters 127
    6.13.3 Cannot Create Instances of Type Parameters 127
    6.13.4 Cannot Use instanceof 128
    6.13.5 Cannot Create Generic Arrays 128
    6.13.6 Limitations on Exception 128
    6.13.7 Cannot Use .class 129
    7. Reflection 133
    7.1 Introduction 133
    7.1.1 Pros and Cons of Reflection 133
    7.2 Classes 134
    7.2.1 Class 134
    7.2.1.1 Using getClass() 134
    7.2.1.2 Using .class 135
    7.2.1.3 Using forName() 135
    7.2.1.4 Using TYPE field 136
    7.2.2 Modifier 136
    7.3 Inspecting Class 137
    7.3.1 Getting Class Information 137
    7.3.2 Getting Class Modifiers 138
    7.3.3 Finding Implemented Interfaces 138
    7.3.4 Finding Inheritance Hierarchy 139
    7.3.5 Finding Annotations 139
    7.4 Finding Class Members 140
    7.4.1 Getting Fields 140
    7.4.2 Getting Methods 142
    7.4.3 Getting Constructors 143
    7.5 Working with Class Members 143
    7.5.1 Field Type 143
    7.5.2 Field Modifiers 144
    7.5.3 Accessing Fields 144
    7.5.3.1 Accessing forbidden fields 145
    7.5.3.2 Modifying final fields 145
    7.5.4 Method Modifiers 146
    7.5.5 Method Information 146
    7.5.6 Invoking Methods 147
    7.5.6.1 Accessing forbidden methods 147
    7.5.7 Debugging with Reflection 148
    7.5.8 Getting Constructor Modifiers 149
    7.5.9 Instantiating Objects 149
    7.5.10 Arrays 150
    7.5.10.1 Checking array types 150
    7.5.10.2 Creating new arrays 151
    7.6 Dynamic Proxy 151
    7.6.1 Designing Dynamic Proxy 151
    7.6.2 Invocation Handlers 153
    7.7 Disadvantage of Reflection 155
    8. Java Native Interface 158
    8.1 Introduction 158
    8.2 Java Program with C/C++ 159
    8.2.1 Writing Java Program 159
    8.2.2 Compiling Java Program 160
    8.2.3 Create Header File 160
    8.2.4 Implement Native Method 161
    8.2.5 Create Shared Library 162
    8.2.6 Running the Program 162
    8.3 Using C++ 163
    8.4 Syntax Difference in C/C++ 163
    8.5 Using Java Package 164
    8.5.1 JNI Types and Data Structures 165
    8.6 Passing Arguments 167
    8.6.1 Passing Primitives 167
    8.6.2 Passing Strings 168
    8.6.3 Passing Primitive Array 169
    8.7 Accessing Java Code from Native Program 171
    8.7.1 Passing Object Array 172
    8.8 Creating Objects 174
    8.9 Exception Handling in JNI 174
    8.10 Appendix 177
    9. AWT and Swing 182
    9.1 Introduction 182
    9.2 AWT Class Hierarchy 183
    9.2.1 Component 183
    9.2.2 Container 183
    9.2.3 Controls 185
    9.3 Creating Container 185
    9.3.1 Empty Frame 185
    9.3.2 Frame with a Title 185
    9.4 Adding Components 186
    9.4.1 Adding a Label 186
    9.4.2 Adding a Button 186
    9.5 Layout 187
    9.5.1 FlowLayout 187
    9.5.2 GridLayout 187
    9.5.3 BorderLayout 188
    9.6 Using Panel 189
    9.7 Text Field 189
    9.8 TextArea 190
    9.9 List 190
    9.10 Checkbox 191
    9.11 Check Box Group 191
    9.12 Choice 192
    9.13 Event Handling 192
    9.13.1 Event Sources 192
    9.13.2 Event Classes 192
    9.13.3 Event Listeners 194
    9.13.4 Example 194
    9.13.5 Adapter Classes 197
    9.14 Dialog Boxes 198
    9.14.1 Simple Dialog 198
    9.14.2 File Dialog 199
    9.15 ScrollBar 200
    9.16 Menu 200
    9.16.1 Popup Menu 201
    9.17 Swing 202
    9.17.1 Containment Hierarchy 203
    9.17.2 Adding Components 203
    9.17.3 JTextField 203
    9.17.4 JPasswordField 204
    9.17.5 JTable 204
    9.17.6 JComboBox 205
    9.17.7 JProgressBar 205
    9.17.8 JList 206
    9.17.9 JTree 207
    9.17.10 JColorChooser 209
    9.17.11 Dialogs 210
    9.17.12 Appendix A: Methods of Important Event Listener Interfaces 212
    10. Java and XML 217
    10.1 Introduction 217
    10.2 XML and DOM 217
    10.3 DOM Nodes 219
    10.4 The Node Interface 221
    10.4.1 Node Properties 221
    10.5 Document Node 225
    10.5.1 Document Node Properties 225
    10.5.2 Document Node Methods 225
    10.6 Element Node 227
    10.6.1 Element Node Properties 227
    10.6.2 Element Node Methods 227
    10.7 Text Node 228
    10.7.1 Text Node Properties 228
    10.7.2 Text Node Methods 228
    10.8 Attr Node 229
    10.8.1 Attr Node Properties 229
    10.9 Parsing XML 229
    10.9.1 Creating Document 230
    10.9.2 Navigating DOM Tree 230
    10.9.2.1 Using root node 230
    10.9.2.2 Getting all child nodes 231
    10.9.2.3 Using getElements ByTagName 232
    10.9.2.4 Using getElementById 233
    10.9.2.5 Getting attributes of an element 233
    10.9.2.6 Viewing DOM 235
    10.9.3 Manipulating DOM Tree 236
    10.9.3.1 Creating a node 236
    10.9.3.2 Setting an attribute 237
    10.9.3.3 Adding a node 237
    10.9.3.4 Inserting a node 238
    10.9.3.5 Deleting a node 239
    10.9.3.6 Cloning a node 240
    10.9.4 Java DTD Validation 241
    11. Input/Output 247
    11.1 Introduction 247
    11.2 Streams 247
    11.2.1 Byte Stream 249
    11.2.2 Character Stream 251
    11.2.3 Bridging Stream 251
    11.2.4 Buffered Stream 252
    11.2.4.1 Buffered byte stream 252
    11.2.4.2 Buffered character stream 252
    11.2.5 Reading from Keyboard 253
    11.2.5.1 Reading character 253
    11.2.5.2 Reading string 253
    11.2.6 Console 254
    11.3 Formatting 254
    11.4 Data Streams 255
    11.5 Object Stream 255
    11.6 Reading/writing Arrays via Streams 256
    11.7 Pipes 256
    11.8 File I/O 258
    11.9 Path 258
    11.9.1 Creating a Path 258
    11.9.2 Retrieving Path Information 258
    11.9.3 Path Operations 259
    11.9.3.1 Removing redundancy 259
    11.9.3.2 Converting to URI 259
    11.9.3.3 Joining paths 259
    11.9.4 Comparing Paths 259
    11.10 File 260
    11.10.1 Checking Existence 260
    11.10.2 Creating File 260
    11.10.3 Deleting File 260
    11.10.4 Copying a File 260
    11.10.5 File Attribute 261
    11.10.6 Reading, Writing, Creating Files 261
    11.10.7 Random Access Files 262
    11.10.8 W orking with Directories 263
    11.10.8.1 Listing Directory Contents 263
    11.10.9 Walking Directory Tree 263
    11.10.10 Watching Directory 264
    PART II: NETWORK PROGRAMMING 271
    12. Basic Networking 273
    12.1 Java and the Net 273
    12.2 Java Networking Classes and Interfaces 273
    12.3 Getting Network Interfaces 274
    12.3.1 Getting Interface Addresses 275
    12.3.2 Getting Interface Properties 276
    12.4 URL 277
    12.4.1 Creating URL 277
    12.4.2 Parsing URL 277
    12.4.3 Web Page Retrieval 278
    12.5 URLConnection 279
    12.6 HttpURLConnection 280
    12.6.1 URLEncoder/URLDecoder 281
    12.7 Proxy 283
    12.7.1 Using Command Line Arguments 283
    12.7.2 Using System Properties 283
    12.7.3 Using Proxy Class 283
    12.8 ProxySelector 283
    13. Socket Programming 287
    13.1 Introduction 287
    13.2 Client/server Programs 288
    13.3 Sockets 289
    13.3.1 Types of Socket 290
    13.3.2 Ports 290
    13.3.3 Socket Address 290
    13.3.4 Socket Address and Java 291
    13.3.5 Reserved Ports 291
    13.4 TCP Sockets 292
    13.4.1 The ServerSocket Class 294
    13.4.2 The Socket Class 296
    13.4.3 An Application 297
    13.4.4 Complete Example 298
    13.4.5 Running Example Program 299
    13.4.6 Handling Multiple Client Requests 300
    13.4.6.1 Iterative solution 300
    13.4.7 Concurrently Solution 302
    13.4.8 Sending and Receiving Objects Using TCP 306
    13.4.8.1 Serializing an object 306
    13.4.8.2 Reconstructing objects 308
    13.4.9 An Example 309
    13.4.10 Writing the Server 310
    13.4.10.1 Writing interfaces 310
    13.4.10.2 Implementing interfaces 310
    13.4.10.3 Implementing server 311
    13.4.10.4 Implementing client 312
    13.4.10.5 Running the example 313
    13.5 UDP Sockets 313
    13.5.1 Datagram Packets 315
    13.5.2 Datagram Server 315
    13.5.3 Datagram Client 317
    13.5.4 Receiving Multiple Datagrams 319
    13.5.5 Sending and Receiving Objects Using UDP 321
    13.5.6 Sending an Object 321
    13.5.7 Reconstructing the Object 322
    13.5.8 Running the Application 323
    13.6 Multicasting 323
    13.7 Multicast Sockets 323
    13.7.1 Multicast Addresses 324
    13.7.2 MulticastSocket Class 325
    13.7.3 Sending Data 326
    13.7.4 Receiving Data 326
    13.7.5 Complete Example 327
    13.7.6 Another Multicasting Example 328
    13.7.7 A Text Conference Example 330
    13.8 Appendix A (Useful Methods of ServerSocket Class) 332
    13.8.1 Constructors 332
    13.8.2 Methods 332
    13.9 Appendix B (Useful Methods of Socket Class) 334
    13.9.1 Constructors 334
    13.9.2 Methods 335
    13.10 Appendix C (Useful Methods of DatagramSocket Class) 338
    13.10.1 Constructors 338
    13.10.2 Methods 338
    13.11 Appendix D (Useful Methods of DatagramPacket Class) 341
    13.11.1 Constructors 341
    13.11.2 Methods 342
    13.12 Appendix E (Useful Methods of MulticastSocket Class) 343
    13.12.1 Constructors 343
    13.12.2 Methods 343
    14. Remote Method Invocation 348
    14.1 Introduction 348
    14.2 Remote Method Invocation 348
    14.2.1 Application Components 349
    14.2.2 Basic Steps 350
    14.3 Java RMI Interfaces and Classes 351
    14.4 An Application 352
    14.4.1 Writing an Interface 352
    14.4.2 Writing Implementation class 354
    14.4.2.1 Implementing the remote interface 354
    14.4.2.2 Providing method implementation 355
    14.4.2.3 Writing Constructor 356
    14.4.3 Writing an RMI Server 356
    14.4.3.1 Creating a remote object 357
    14.4.3.2 Exporting the object 357
    14.4.3.3 Registering the stub 360
    14.4.4 Writing an RMI Client 361
    14.5 Compiling the Program 363
    14.5.1 Compiling Server 363
    14.5.2 Compiling Client 363
    14.6 Generating Stub Classes 364
    14.7 Running the Program 364
    14.7.1 Start Server 364
    14.7.2 Start Client 365
    14.7.3 Understanding Object Registry 365
    14.7.4 Using RMI URL 367
    14.8 Callback 369
    14.8.1 Creating Interfaces 370
    14.8.2 Implementing Interfaces 371
    14.8.3 Writing the Server 371
    14.8.4 Writing the Client 372
    14.8.5 Compiling the Application 372
    14.8.6 Running the Application 372
    14.9 Another Callback Application 373
    14.10 Dynamic Object Activation 375
    14.10.1 Basic Idea 375
    14.10.2 Implementation 375
    14.10.3 The Activation Protocol 375
    14.10.4 An Example 376
    14.10.4.1 Writing implementation class 376
    14.10.4.2 Writing server class 377
    14.10.4.3 Compiling and running the program 379
    14.11 Dynamic Class Downloading 379
    14.12 An Example 380
    14.12.1 Writing an RMI Server 381
    14.12.1.1 Write an interface 381
    14.12.1.2 Implement the interface 381
    14.12.1.3 Implement the server 382
    14.12.2 Writing a Client 384
    14.12.3 Compiling the Program 385
    14.12.3.1 Creating interface classes 386
    14.12.3.2 Compiling server 386
    14.12.3.3 Compiling client 387
    14.12.4 Running the Application 387
    14.12.5 Start Client 388
    15. Java Mail API 392
    15.1 E-mail 392
    15.2 JavaMail API 392
    15.3 Installing JavaMail API 393
    15.4 Sending Emails 393
    15.4.1 Creating a Session Object 394
    15.4.2 Compose a Message 395
    15.4.3 Sending the Mail 396
    15.4.4 Compiling and Running the Program 397
    15.5 Sending Emails Directly Using Socket 397
    15.6 Secured SMTP 398
    15.6.1 Using SSL 399
    15.6.2 Using TLS 399
    15.6.3 Providing Authentication Information 400
    15.7 Email Message Revisited 403
    15.7.1 MIME 403
    15.7.2 Single-part Message 404
    15.7.3 Multi-part MIME Message 405
    15.7.4 Composing a Mixed Message 406
    15.7.5 Compiling the Program 407
    15.8 Email with HTML Content 408
    15.9 Accessing Email 409
    15.9.1 POP 409
    15.9.2 IMAP 410
    15.9.3 Secured Mail Access 411
    15.9.4 JavaMail API Support 411
    15.9.5 Reading Email 411
    15.9.6 Using Authenticator 413
    15.10 Deleting Mails 413
    15.11 Replying to Mails 414
    15.12 Forwarding Mails 414
    15.13 Copying Emails 415
    15.14 List of SMTP, POP3 and IMAP Servers 416
    16. Applets 421
    16.1 Client Side Java 421
    16.2 Life Cycle 422
    16.2.1 init() 423
    16.2.2 start() 423
    16.2.3 paint() 424
    16.2.4 stop() 425
    16.2.5 destroy() 425
    16.3 Writing an Applet 426
    16.4 Generating Class File 426
    16.5 Running the Applet 426
    16.5.1 The Applet Tag 426
    16.6 Security 430
    16.7 Utility Methods 431
    16.8 Using Status Bar 432
    16.9 AppletContext Interface 432
    16.10 Document Base and Code Base 433
    16.11 Passing Parameter 434
    16.11.1 Retrieving Parameter 434
    16.12 Event Handling 435
    16.13 Communication Between Two Applets 436
    16.13.1 Using getApplet() Method 436
    16.13.2 Using getApplets() Method 437
    16.13.3 A Sample Application 438
    16.14 Loading Web Pages 439
    16.15 Interacting with JavaScript Code 440
    17. Java XML-RPC 445
    17.1 Introduction 445
    17.2 XML-RPC Operational Principle 446
    17.3 Data Types 447
    17.3.1 Basic Data Types 447
    17.3.2 Compound Data Types 449
    17.4 XML-RPC Messages 451
    17.4.1 Request Message 452
    17.4.2 Response Message 453
    17.4.3 Fault Message 454
    17.5 Java XML-RPC 454
    17.6 Installing the Apache XML-RPC Java Library 455
    17.7 XML-RPC versus Java Data Types 455
    17.8 Example 456
    17.8.1 Writing the Server 456
    17.8.2 Writing the Client 457
    17.8.3 Running the Application 459
    17.9 Dynamic Proxies 460
    17.10 Using XmlRpcServlet 462
    17.11 Using ServletWebServer 464
    17.12 Introspection 466
    17.12.1 Example 467
    17.12.1.1 Listing methods 468
    17.12.1.2 Finding method signature 469
    17.12.1.3 Getting help 470
    17.13 Limitations of XML-RPC 471
    18. Java and Soap 475
    18.1 Introduction 475
    18.2 Differences with XML-RPC 475
    18.3 Soap Architecture 476
    18.4 SOAP Flavors 477
    18.5 SOAP Messages 477
    18.6 SOAP Binding 479
    18.7 RPC Using SOAP 479
    18.8 Web Service 480
    18.9 JAX-WS 480
    18.9.1 Developing Web Service 481
    18.9.2 Deploying Web Service 482
    18.9.3 Invoking Web Service 483
    18.9.4 Tracking SOAP messages 485
    18.9.5 Using WSDL 486
    18.9.6 Document Style 489
    18.9.7 Using Tomcat to Deploy Web Service 490
    18.9.8 Using Ant to Build War File 492
    18.9.9 Asynchronous Client 493
    18.9.9.1 Polling 494
    18.9.9.2 Callback 495
    PART III: ENTERPRISE JAVA 501
    19. Security 503
    19.1 Introduction 503
    19.2 Java Security Architecture 504
    19.2.1 Language Security 504
    19.2.2 Basic Security 504
    19.2.3 Java Cryptography Architecture (JCA) 505
    19.2.3.1 Secret-key cryptography 505
    19.2.3.2 Public-key cryptography 506
    19.2.4 Public Key Infrastructure (PKI) 506
    19.2.4.1 Public key certificates 506
    19.2.4.2 Certificate format 506
    19.2.4.3 Digital signature 507
    19.2.4.4 Key and certificate store 507
    19.2.5 PKI Tools 507
    19.3 Secure Communication 508
    19.4 SSL 508
    19.4.1 What does SSL do? 508
    19.4.2 How does it do? 508
    19.4.3 An Example 509
    19.4.3.1 Writing the server 509
    19.4.3.2 Writing the client 510
    19.4.3.3 Compiling and running the application 510
    19.4.4 Using Client Authentication 514
    19.4.5 Using KeyStore 515
    19.4.6 Ignoring Server Certificates 517
    19.4.7 Working with HTTPS 517
    19.5 keytool Revisited 519
    19.5.1 KeyStore 519
    19.5.2 Keystore Entries 520
    19.5.2.1 Truststore 520
    19.5.3 Keystore Aliases 520
    19.5.4 Public Key Generation 520
    19.5.5 Changing Password 521
    19.5.6 Generating a Certificate Chain 521
    19.5.7 Generating a Certificate Using Openssl 522
    19.6 Generating Keys 524
    19.6.1 Public Key Generation 524
    19.6.2 Private Key Generation 524
    19.7 Working with Keystore 525
    19.7.1 Reading Keystore 525
    19.7.2 Extracting Private Keys from Keystore 525
    19.7.3 Storing Private Key and Certificate in Keystore 526
    19.8 Working with Certificates 526
    19.8.1 Reading Certificate Information 527
    19.8.2 Creating Certificate 527
    19.8.3 Converting Certificates 528
    19.8.4 SignedObject 529
    19.8.5 SealedObject 531
    19.8.6 GuardedObject 534
    19.9 Secure RMI 535
    19.9.1 Writing Custom Socket Factories 538
    19.10 Secure XML-RPC 539
    19.10.1 Using XmlRpcServlet 539
    19.10.2 Using Secure XML-RPC 540
    19.11 Signing and Verifying JAR 542
    19.11.1 Signing JAR 542
    19.11.1.1 Signature (.SF) file 543
    19.11.1.2 Signature block file 544
    19.11.2 Verifying JAR 544
    19.12 Multiple Signatures for a JAR File 544
    19.13 Access Control 545
    19.13.1 Installing Built-in Security Manager 546
    19.13.2 Policy Files 546
    19.13.3 Policy File Syntax 547
    19.13.3.1 Keystore entry 547
    19.13.3.2 Grant entry 548
    19.13.3.3 Permission entry 549
    19.13.4 Custom Permission Class 549
    19.14 An application 550
    20. Servlet 557
    20.1 Server-side Java 557
    20.2 Advantages Over Applets 558
    20.3 Servlet Alternatives 558
    20.3.1 Common Gateway Interface (CGI) 558
    20.3.2 Proprietary APIs 558
    20.3.3 Active Server Pages (ASP) 559
    20.3.4 Server-side JavaScript 559
    20.4 Servlet Strengths 559
    20.4.1 Efficient 559
    20.4.2 Persistent 559
    20.4.3 Portable 559
    20.4.4 Robust 559
    20.4.5 Extensible 559
    20.4.6 Secure 560
    20.4.7 Cost-effective 560
    20.5 Servlet Architecture 560
    20.6 Servlet Life Cycle 561
    20.6.1 init() 562
    20.6.2 service() 562
    20.6.3 destroy() 562
    20.6.4 Other Methods 563
    20.7 GenericServlet 563
    20.8 HttpServlet 563
    20.9 First Servlet 564
    20.9.1 Installing Apache Tomcat Web Server 565
    20.9.2 Building and Installing Servlet 566
    20.9.3 Invoking Servlet 567
    20.10 Passing Parameters to Servlets 568
    20.10.1 Passing Parameters Directly to a Servlet 568
    20.10.2 Passing Parameters Directly to a Servlet 568
    20.11 Retrieving Parameters 569
    20.12 Server-Side Include 571
    20.13 Cookies 574
    20.13.1 Limitations of Cookies 575
    20.14 Filters 575
    20.14.1 Deploying Filter 577
    20.15 Problems with Servlet 577
    20.16 Security Issues 578
    20.17 Appendix A: List of SSI Servlet Variables 578
    21. Java Server Pages 583
    21.1 Introduction and Marketplace 583
    21.2 JSP and HTTP 584
    21.3 JSP Engines 584
    21.3.1 Tomcat 584
    21.3.2 Java Web Server 586
    21.3.3 WebLogic 586
    21.3.4 WebSphere 586
    21.4 How JSP Works 586
    21.5 JSP and Servlet 587
    21.5.1 Translation and Compilation 587
    21.6 Anatomy of a JSP Page 590
    21.7 JSP Syntax 591
    21.8 JSP Components 591
    21.8.1 Directives 591
    21.8.1.1 Page directive 592
    21.8.1.2 Include directive 594
    21.8.2 Comments 594
    21.8.3 Expressions 595
    21.8.4 Scriptlets 595
    21.8.4.1 Conditional processing 596
    21.8.5 Declarations 596
    21.8.6 Scope of JSP Objects 597
    21.8.7 Implicit Objects 598
    21.8.8 Variables, Methods, and Classes 600
    21.8.8.1 Synchronization 601
    21.8.9 Standard Actions 602
    21.8.10 Tag Extensions 606
    21.8.10.1 Tag type 606
    21.8.10.2 Writing tags 606
    21.8.11 Iterating a Tag Body 609
    21.8.12 Sharing Data Between JSP Pages 611
    21.9 Beans 612
    21.9.1 useBean 612
    21.9.2 setProperty 613
    21.9.3 getProperty 613
    21.9.4 Complete Example 613
    21.9.5 Other Usage 614
    21.10 Session Tracking 614
    21.10.1 Hidden fields 614
    21.10.2 URL Rewriting 616
    21.10.3 Cookies 616
    21.10.4 Session API 617
    21.11 Users Passing Control and Data between Pages 619
    21.11.1 Passing Control 619
    21.11.2 Passing Data 619
    21.12 Sharing Session and Application Data 620
    22. Java Database Connectivity (JDBC) 625
    22.1 Introduction 625
    22.2 JDBC Drivers 625
    22.2.1 JDBC-ODBC Bridge (Type 1) 626
    22.2.2 Native-API, Partly Java (Type 2) 626
    22.2.3 Middleware, Pure Java (Type 3) 626
    22.2.4 Pure Java Driver (Type 4) 626
    22.3 JDBC Architecture 626
    22.4 JDBC Classes and Interfaces 627
    22.5 Basic Steps 627
    22.6 Loading a Driver 628
    22.7 Making a Connection 629
    22.8 Execute SQL Statement 631
    22.9 SQL Statements 631
    22.9.1 Simple Statement 632
    22.9.2 Atomic Transaction 635
    22.9.3 Pre-compiled Statement 637
    22.9.4 SQL Statements to Call Stored Procedures 638
    22.10 Retrieving Result 640
    22.11 Getting Database Information 641
    22.12 Scrollable and Updatable ResultSet 642
    22.12.1 Scrollability Type 643
    22.12.2 Concurrency Type 643
    22.12.3 Examples 643
    22.13 Result Set Metadata 647
    23. Hibernate 657
    23.1 Introduction 657
    23.2 Installing Hibernate 658
    23.3 Basic Steps 658
    23.4 Writing POJO Class 658
    23.5 Creating a Table 659
    23.6 Writing a Hibernate Application 659
    23.7 Compiling and Running Application 663
    23.8 Using Annotation 664
    23.9 Environment Setup for Hibernate Annotation 664
    23.10 Book Application Using Annotation 664
    23.11 Function of Different Annotations 665
    23.12 Object Life Cycle 666
    23.13 Hibernate Query Language 667
    23.13.1 From 667
    23.13.2 Select 667
    23.13.3 Where 668
    23.13.4 Filtering 668
    23.13.5 Order by 668
    23.13.6 Group by 668
    23.13.7 Parameter Binding 668
    23.13.8 Update 669
    23.13.9 Delete 669
    23.13.10 Insert 669
    23.13.11 Aggregate Methods 70
    23.14 Using Native SQL Query 670
    23.15 Named Queries 670
    23.15.1 Defining Named Queries 671
    23.15.2 Calling Named Queries 672
    23.16 Generating DDL 673
    23.17 Syntax of O/R Mapping File 674
    23.18 Generator Class 676
    23.19 Hibernate Tools 677
    23.19.1 Using Hibernate Tools with Ant 677
    23.19.2 Ant Task 678
    23.19.3 Configuring Task 678
    23.19.4 Exporters 679
    23.19.5 Controlling Reverse Engineering 683
    23.19.6 Controlling POJO Code Generation 685
    24. Java Naming and Directory Interface 692
    24.1 Naming Concepts 692
    24.1.1 Naming Convention 693
    24.1.2 Naming Context 693
    24.1.3 Binding 693
    24.2 Directory Concepts 694
    24.2.1 Directory Context 694
    24.3 Java Naming and Directory Interface 694
    24.4 An Example 695
    24.4.1 Writing the Server 695
    24.4.2 Writing the Client 696
    24.4.3 Running Application 696
    24.5 Specifying JNDI Properties 697
    24.6 Name Servers 697
    24.7 Using ApacheDS 698
    24.7.1 Installing and Starting ApacheDS 698
    24.7.2 JNDI Properties for ApacheDS 699
    24.8 Calculator RMI Application Using LDAP 699
    24.9 Calculator RMI-IIOP Application Using JNDI 699
    24.9.1 Server 699
    24.9.2 Client 700
    24.9.3 Running the Application 700
    24.10 Naming Operations 700
    24.10.1 Adding, Replacing and Removing Binding 701
    24.10.2 Looking Up 701
    24.10.3 Renaming 701
    24.10.4 Listing 702
    24.10.4.1 Using list() 702
    24.10.4.2 Using listBindings() 702
    24.11 Working with Subcontext 703
    24.12 Working with Directory 703
    24.12.1 Reading Attributes 703
    24.12.2 Binding with Attributes 704
    24.12.3 Creating Subcontext with Attributes 705
    24.12.4 Adding Attributes 705
    24.12.5 Modifying Attributes 706
    24.12.6 Removing Attributes 706
    24.12.7 Batch Operation on Attributes 707
    24.12.8 Search 707
    24.12.8.1 Basic search 707
    24.12.8.2 Filters 709
    25. Java Message Service 714
    25.1 Messaging 714
    25.2 JMS API 714
    25.3 JMS Components 715
    25.4 Messaging Models 715
    25.4.1 Point-to-Point 716
    25.4.2 Publish/Subscribe 716
    25.5 Message Consumption 717
    25.5.1 Synchronous 717
    25.5.2 Asynchronous 717
    25.6 Programming Model 717
    25.7 Installing Open MQ 720
    25.8 Writing JMS Application 722
    25.9 Writing a P2P Producer 722
    25.9.1 Running Example 723
    25.10 Writing a P2P Synchronous Consumer 724
    25.11 Writing a P2P Asynchronous Consumer 725
    25.12 Writing a Pub/Sub Producer 726
    25.13 Writing a Pub/Sub Synchronous Consumer 726
    25.14 Running this Example 727
    25.15 Writing a Pub/Sub Asynchronous Consumer 727
    25.16 Browsing Queue 728
    25.17 Using JNDI 729
    25.18 Reliability Mechanisms 731
    25.18.1 Acknowledgement 732
    25.18.2 Message Persistence 732
    25.18.3 Message Priority 732
    25.18.4 Message Expiration 732
    25.18.5 Temporary Destinations 733
    25.19 Transacted Session 733
    26. Introduction to J2EE 739
    26.1 Overview of J2EE 739
    26.2 Introduction to JavaBeans 740
    26.2.1 Properties 741
    26.2.2 Accessor Methods 741
    26.3 Bean Builder 741
    26.4 Advantages of JavaBeans 742
    26.5 BDK Introspection 742
    26.5.1 Design Patterns 743
    26.6 Properties 744
    26.6.1 Simple Properties 744
    26.6.2 Bound Properties 745
    26.6.3 Constrained Properties 748
    26.6.3.1 Implementing constrained property support 748
    26.6.3.2 Implementing constrained property Listener 749
    26.6.3.3 Example 750
    26.6.4 Indexed Properties 751
    26.7 BeanInfo Interface 752
    26.8 Persistence 756
    26.9 Customizer 758
    26.10 JavaBeans API 759
    26.11 EJB 761
    26.11.1 Benefits of EJB 761
    26.11.2 Usage Scenario 761
    26.11.3 EJB Architecture 761
    26.11.4 Session Beans 762
    26.11.4.1 Stateless session beans 762
    26.11.4.2 Stateful session beans 762
    26.11.5 Entity Beans 762
    26.11.6 Message Driven Beans 763
    26.12 Introduction to Struts Framework 763
    26.12.1 Basic Idea 763
    27. Java and CORBA 770
    27.1 Introduction 770
    27.2 CORBA Architecture 770
    27.2.1 IDL 771
    27.2.2 ORB 771
    27.2.3 IIOP 771
    27.2.4 IOR 771
    27.3 Java IDL 772
    27.4 Developing CORBA Applications 772
    27.4.1 Write an Interface Using IDL 772
    27.4.2 Mapping IDL Interface to Java 773
    27.4.3 Implementing the Interface 774
    27.4.4 Writing the Server 774
    27.4.4.1 Binding IOR to naming service 775
    27.4.5 Writing the Client 776
    27.5 Compiling Applications 777
    27.6 Running the Application 777
    27.7 Using Properties 778
    27.8 Stringified Object Reference 779
    27.9 Using URL 780
    27.9.1 Using corbaloc 780
    27.9.2 Using corbaname 781
    27.10 Using Tie 782
    27.11 Persistent Objects 782
    27.11.1 Running Persistent Application 784
    27.12 Callback 784
    27.13 Using Dynamic Invocation Interface (DII) 787
    27.14 Using Dynamic Skeleton Interface (DSI) 789
    27.14.1 Basic Steps 789
    27.14.2 An Example 789
    27.15 Using Out and Inout Parameter 791
    27.15.1 Invoking Operation Using Holder Classes 792
    27.15.2 An Example 792
    27.16 RMI-IIOP 793
    27.16.1 An Example 793
    27.16.1.1 Writing an interface 793
    27.16.1.2 Implementing the interface 794
    27.16.1.3 Writing the server 794
    27.16.1.4 Writing the client 794
    27.16.1.5 Compiling server files 794
    27.16.1.6 Compiling client files 795
    27.16.1.7 Running the application 795
    27.17 IDL to Java Language Mapping 795
    28. Java Server Faces 801
    28.1 Introduction 801
    28.2 First Application 802
    28.2.1 Installing JSF 802
    28.2.2 Writing a JSF Page 803
    28.2.3 Deploying the Application 804
    28.2.4 Testing the Application 805
    28.3 Request Processing Life-cycle 806
    28.3.1 Restore View 806
    28.3.2 Apply Request Values 807
    28.3.3 Process Validations 807
    28.3.4 Update Model Values 808
    28.3.5 Invoke Application 808
    28.3.6 Render Response 808
    28.4 Tracing Phases 808
    28.5 Managed Bean 809
    28.5.1 Using faces-config.xml File 810
    28.5.2 Using @ManagedBean Annotation 811
    28.5.3 Scope Annotations 811
    28.5.4 @ManagedProperty Annotation 812
    28.6 Accessing Managed Bean Programmatically 813
    28.6.1 Using javax.faces.context. ExternalContext 813
    28.6.2 Using javax.el.ELContext 813
    28.6.3 Using evaluateExpressionGet() Method 814
    28.7 Basic JSF Tags 814
    28.8 Expression Language 817
    28.8.1 Value Expression 818
    28.8.2 Method Expression 819
    28.8.3 Facelets 820
    28.8.3.1 Templates 820
    28.8.3.2 Custom tags 821
    28.8.3.3 Composite components 823
    28.8.3.4 Remove 824
    28.8.4 Converter Tags 824
    28.8.5 Displaying Messages 827
    28.8.6 Validations 828
    28.9 AJAX 830
    28.10 Event Handling 831
    28.10.1 Value Change Listener 831
    28.10.1.1 Using value- ChangeListener attribute 831
    28.10.2 Using Tag 832
    28.10.3 Action Listener 832
    28.10.3.1 Using actioneListener attribute 832
    28.10.4 Using Tag 833
    28.11 An Event Handling Example 833
    28.12 Page Navigation 834
    28.12.1 Auto Navigation 834
    28.12.2 Using Managed Bean 835
    28.12.3 Using Navigation Rule in Faces-config.xml 835
    Answers to Objective-type Questions 841