Core Java An Integrated Approach 2nd R Nageswara Rao
Core Java An Integrated Approach 2nd R Nageswara Rao
Core Java An Integrated Approach 2nd R Nageswara Rao
Core Java An Integrated Approach 2nd R Nageswara Rao
1. Core Java An Integrated Approach 2nd R Nageswara
Rao download
https://ebookbell.com/product/core-java-an-integrated-
approach-2nd-r-nageswara-rao-7038772
Explore and download more ebooks at ebookbell.com
2. Here are some recommended products that we believe you will be
interested in. You can click the link to download.
Java Programming A Step By Step Beginners Guide To Code With An
Objectoriented Program Megane Noel
https://ebookbell.com/product/java-programming-a-step-by-step-
beginners-guide-to-code-with-an-objectoriented-program-megane-
noel-47526070
Java Programming For Beginners Improve Your Software Engineering
Skills By Learning To Code Using An Objectoriented Program Learn About
The Virtual Machine Javascript And Machine Code 2022 Vergil Silva
https://ebookbell.com/product/java-programming-for-beginners-improve-
your-software-engineering-skills-by-learning-to-code-using-an-
objectoriented-program-learn-about-the-virtual-machine-javascript-and-
machine-code-2022-vergil-silva-46408466
Core Java Volume I Fundamentals 12th Horstmann Cay
https://ebookbell.com/product/core-java-volume-i-fundamentals-12th-
horstmann-cay-46173296
Core Java Volume Ii Advanced Features 12th Cay S Horstmann
https://ebookbell.com/product/core-java-volume-ii-advanced-
features-12th-cay-s-horstmann-46173298
3. Core Java For The Impatient 3rd Edition Cay Horstmann
https://ebookbell.com/product/core-java-for-the-impatient-3rd-edition-
cay-horstmann-48456364
Core Java Interview Questions Youll Most Likely Be Asked Job Interview
Questions Series 2nd Edition Vibrant Publishers
https://ebookbell.com/product/core-java-interview-questions-youll-
most-likely-be-asked-job-interview-questions-series-2nd-edition-
vibrant-publishers-49183978
Core Java Made Simple Som Prakash Rai
https://ebookbell.com/product/core-java-made-simple-som-prakash-
rai-49422914
Core Java Volume Ifundamentals Cay S Horstmann
https://ebookbell.com/product/core-java-volume-ifundamentals-cay-s-
horstmann-49541448
Core Java Vol Iiadvanced Features 12th Edition Cay S Horstmann
https://ebookbell.com/product/core-java-vol-iiadvanced-features-12th-
edition-cay-s-horstmann-49554648
6. About the Author
Mr. R Nageswara Rao has been associated with teaching Computer Science since 1993. He has
worked at various colleges as HOD (Dept. of Computers) and as a free-lance developer for some time
for a cpuple of organizations. He has been teaching Java since 2000, and is currently associated
with INet Solv Solutions, Hyderabad, a prestigious training division, imparting specialized training
in Java.
Mr. R Nageswara Rao is teaching and interacting with more than 1000 new students every month,
including software developers and foreign students.
Since 1998, Mr. Rao is associated with 'Computer Vignanam', a widely circulated monthly
magazine, published in Telugu. He has been on the editorial board of this magazine for the past six
years. He published several articles, including articles on Virtual Reality, Mobile communications,
Blue tooth technology and Global positioning systems. He also published hundreds of articles on
C/C++ and Java.
7. Content at a Glance
Core Java - An Integrated Approach
Chapter 1 - All about Networks 1
Chapter 2 - Introduction to Java 7
Chapter 3 - First Step Towards Java Programming 15
Chapter 4 - Naming Conventions and Data Types : 27
Chapter 5 - Operators in J§l-va 33
Chapter 6 - Control Statements in Java 47
Chapter 7 - Input and Output 65
Chapter 8 - Arrays 81
Chapter 9 - Strings 95
Chapter 10 - StringBuffer and String Builder 107
Chapter 11 - Introduction to OOPs ~ 115
Chapter 1j; Classes and Objects 123
Chapter 1J.-- Methods in Java : ,' :. 139
Chapter 14 - Relationship Between Objects 169
Chapter~-Inheritance 183
Chapter ~ Polymorphism ,' 197
Chapter 17 - Type Casting -. 209
Chapter(Bl7- Abstract Classes -. 223
Chapter 19""- Interfaces 233
Chapter ~Packages 245
Chapter@- Exception Handling 265
Chapter 22 - Wrapper Classes 283
Chapter 23 - The Collection framework 297
Chapter 24 - Streams and Files 333
Chapter 25 - Networking in Java 357
Chapter&- Threads 375
Chapter 27 - Graphics Programming using AWT 409
Chapter 28 - Graphics Programming using Swing 459
Chapter 29 - Graphics Programming - Layout Managers 523
Chapter 30 - Applets : 545
Chapter 31 - Generic Types 563
Chapter 32 - Java Database Connectivity 571
Index I - Question Index ; ; 621
Index II - Program Index ~ 629
8. no
Table of Contents
Preface ; XXI
_Chapter 1: All ab-out Networks : ~: : 1
What Comprises the Internet? - 2
How does Internet·Function? 3
Software Development for Internet 3
- .
Chapter 2: Introduction to Java : : 7
Features of Java 7
The Java Virtual Machine 10
Differences between C++_and Java: 13
Parts of Java 13
Chapter 3: First Step towards Java Programming•.....•...•....................•...•.......•.....•...........15
API Document : _ 16
Starting a Java program : 16
Importing classes : ~ 16
Formatting the Output 23
Chapter 4: Naming Conventions and Data Types 27
Naming Conventions in Java- : , : ~ ~ 27
Data Types in Java : : 28
integer Data Types : .- : .- 29
Float Data Types 29
- - . . .-- .'.-
Character Data Type 30
String Data Types 31
Boolean Data Types : : : : : ~ : 31
Literals : : 31
Integer Literals...........................................................................................................•: 32
Float Literals : : 32
Character Literals 32
String Literals :: 32
Boolean Literals _ .'.~ 32
Chapter 5: Operators in Java 33
Operators : : 33
Arithmetic Operators 33
Unary Operators : : :.. 34
Increment Operator (++) : 34
Decrement Operator (--) 36
Assignment Operator (=) , - 36
Relational Operator : 37
ml s
9. ~ Core Java - An Integrated Approach
Logical Operators : 38
Boolean Operators - 38
Bitwise Operators 39
Ternary Operator or Conditional Operator ( ? : ) 43
instanceof Operator ~._: 45
new Operator , , 45
Cast Operator ~ .-- 45
Priority of Operators : 45
Chapter 6: Control Statements in Java 47
< • •
if. ..else Statement 48
do::.while Loop : ; 49
while Loop _ 50
for Loop 51
Nested for Loops 54
for-each Loop ~ :.: 55
switch Statement - 56
break Statement..; : ; ,: 58
continue Statement · ; ;..;- .--.: 60
return Statement 62
-
Chapter 7: 'Input and Output: 65
Accepting Input from the Keyboard : , : : 65
Acc.epting a Single Character from the Keyboard : 67
Accepting a String from Keyboard : : 68
Accepting an Integer value from the Keyboard 69
Accepting a Float Value from Keyboard : 70
Accepting a Double Value ; 70
Accepting Other Types of Values .- : 70
Accepting Different Types of Inputs in a Line 73
Reading Input withjava.util.Scanner Class 78
Displaying Output with' System.out.printfO 79
Displaying Formatted Output with String.formatO .- 80
Chapter 8: Arrays 81
Types of Arrays : 81
Single Dimensional Arrays (1 D array) : 82
Multi Dimensional Arrays (2D, 3D, arrays) , 86
Three dimensional arrays (3D array) 89
arrayname.length .- 91
Command Line Arguments 91
Chapter 9: Strings - : 96
Creating Strings : 95
10. Table of Content ~
String Class Methods - 96
String Comparison : , 100
Immutability of Strings 103
Chapter 10: StringBufTer and StringBuUder : 107
Creating StringBuffer Objects , 107
StringBuffer Class Methods : ~ 108
StringBuilder-Class , : - 112
StringBuilder Class Methods 112
Chapter 11: Introduction to OOPs 115
Problems in Procedure Oriented Approach .:.:= : , 116
Features of Object Oriented Programming System (OOPS) 116
Class/object 117
En.capsulation : : i 19
Abstraction 120
Inheritance ~ - ~~ 120
Polymorphism 121
Chapter 12: Classes and Objects , : - 123
Object Creation : : 124
Initializing the Instance Variables 127
Access Specifiers 129
Constructors 130
Chapter 13: Methods in Java : : 139
Method,Header or Method Prototype : 139
Method Body - :~ 140
Understanding Methods .- 141
Static Methods - .- 145
Static Block : : : 149
The keyword 'this' : : 151
"'- . .
Instance Methods : 153.
Passing Primitive Data Types to Methods , 154
Passing Objects to Methods 155
Passing Arrays to Methods , ~ , 158
Recursion - : 162
. Factory Methods , : : : 164
Chapter 14: Relationship Between Objects 169
Relating Objects using References 169
Inner Class .- -.174
Anonymous Inner Class 178
11. XlV ICore Java - An Integrated Approach
Chapter 15: Inheritance ; - 183
Inheritance c •••••••••••••••••.••• : •••• 183
The Keyword 'super' - 188
The Protected Specifier : 192
Types of Inheritance · : 194
Chapter 16: Polymorphism 197
Polymorphism with Variables 197
Polymorphism using Methods : 198
Dynamic Polymorphism :.. 198
Static Polymorphism _
.. 202
Polymorphism with Static Methods : 203
Polymorphism with Private Methods - 204
Polymorphism with Final Methods 204
. final Class 205
Chapter 17: Type Casting , 209
Types of Data Types ; 209
Casting Primitive Data Types 210
Casting Referenced Data Types : :- 211
Generalization and Specialization : 211
The Object Class :.:.· 217
Cloning the Class Objects 220
Chapter 18: Abstract Classes 223
Abstract Method and Abstract Class 224
Chapter 19: Interfaces 233
Interface 233
Multiple Inheritance using Interfaces 246
Abstract Classes vs. Interfaces 242
Chapter 20: Packages.......•........•••.....~........•.....••................................................:: 245
Package - 245
Different Types of Packages : 246
- Built-in Packages 246
User-defined Packages 247
The JAR Files ..; ; : 253
Interfaces in a Package 255
Creating Sub Package in a Package 257
Access Specifiers in Java : ~ 258
Creating API Document 261
12. Table of Content ~
Chapter 21: Exception Handling ;..~ 265
Errors in a Java Program : ~.~ ;: 265
Exceptions ~., : , 267 ~
Exception Handling : 269
Handling Multiple Exceptions : 271
throws Clause 273
throw Clause 275
. Types of Exceptions : : ~ ~ 276
Built-in Exceptions 277
User-defined Exceptions 277
Re-throwing an Exception ; : :· 279
Chapter 22: Wrapper Classes 283
Wrapper Classes ~ ~ 283
Number Class : 284
Number Class Methods 284
Character Class : 285
Important Methods of Character Class 285
Byte Class 287
Constructors : 287
Important Methods of Byte Class 287
Short Class 288
Constructors '.- 289
Important Methods of Short Class , 289
. ' .
Integer Class 289
Constructors .............................................................................................................•......... 289
Important Methods of Integer Class ; 290
Long Class 291
Constructors 291
Important Methods of Long Class : ,' 291
Float Class 292
Constructors 292
Important Methods of Float Class ~ : 292
Double Class 292~
. -
Constructors 292
Important Methods of Double Class 293
Boolean Class 293
Constructors 293
Important Methods of Boolean Class: : 293
Math Class : 294
Important Methods of Math Class : ~ : 294
13. XVI ICore Java - An Integrated Approach
Chapter 23: The Collection Framework 297
Using an Array to Store a Group of Objects , 297
Collection Objects y ••••••• : •••••••••••••••••••••••••••••••• ..........................................................· •••• 299
Sets 300
Lists : 300
Queues : 300
Maps 300
Retrieving Elements from Collections :.:; 301
for-each Loop 301
Iterator Interface 301
Listlterator Interface 301
Enumeration Interface 302
HashSet Class ' : : 302
HashSet Class Methods : 302
LifikedHashSet Class : : 303
Stack Class : 304
Stack Class Methods : 305
LinkedList Class : 307
LinkedList Class Methods : 308
ArrayList Class · : 310
ArrayList Class Methods .-= : : •• : : 311
Vector Class : 312
Vector Class Methods 313
,
HashMap Class : : : 315
HashMap Class Methods : : 316
Hashtable Class : 318
Hashtable Class Methods 319
Arrays Class; : , : , 322
Arrays Class Methods : : 322
Using Comparator to Sort an Array : 324
StringTokenizer Class : 326
StringTokenizer Class Methods : 326
Calendar Class ; 327
Calendar Class Methods 327
Dl;tte Class 328
Chapter 24: Streams and Files , - 333
Stream : .- 333
Creating a me using FileOutputStream 336
Improving Efficiency using BufferedOutputStream : 338
Reading Data from a File using FileInputStream : 340
Creating a File usirtg FileWriter : 342
Reading a File using FileReader 343
14. Table of Content.E
Zipping and Unzipping Files : 344
Zipping a File using DeflaterOutputStream : 345
Unzipping a File using InflaterlnputStream.: : 346
Serialization of Objects ....................................................•.................~ : 347
Counting Number of Characters in a File : 351
File Copy : 352
File Class 353
File Class Methods : 353
Chapter 25: Networking in Java 357
TCPlIP ProtocoL 357
User Datagram Protocol (UDP) 359
Sockets 359
Knowing IP Address 360
URL. : 361
URLConnection Class : 362
Creating a Server That Sends Data : 364
Creating a Client That Receives Data· 365
Two-way Communication Between Server and Client 368
Retrieving a me at server '- 370
Chapter 26: Threads 375
Single·Tasking 376
Multi Tasking : 377
Uses of Threads : 378
Creating a Thread and Running it : : .. 379
Terminating the Thread ' 381"
Single Tasking Using a Thread 382
Multi Tasking Using Threads 383
Multiple Threads Acting on Single Object 385
Thread Class Methods ; : 389
Deadlock of Threads 390
Avoiding Deadlocks in a Program 393
Thread Communication 394
Thread Priorities : 399
Thread Group 400
Daemon Threads 402
Applications of Threads · 402
Thread Life Cycle ~ 406
Chapter 27: Graphics Programming using AWT ;; 409
AWT 409
Components 410
Window and Frame , 410
15. xviii ICore Java - An Integrated Approach
Creating a Frame ................•..................................................................................................... 411
Event Delegation Model : 413
Closing the Frame _ 415
Uses ofa Frame ~ 418
Drawing in the Frame 419
Filling with Colors 421
Displaying Dots - 426
Displaying text in the frame 427
Knowing the Available Fonts , 429
Displaying Images in the Frame : ' 430
Component Class Methods 432
Push Buttons -. 433
Listeners and Listener Methods 438
Check Boxes : 440
Radio Button ~ .......................•................ 442
TextField .....................................................................................•...................- - , 444
TextArea 444
Label , - :.:-,..•............ 445
Choice Class 447
List Class 449
. Scrollbar Class ~ 452
Knowing the Keys on Keyboard : :.454
Working with Several Frames 456
Chapter 28: Graphics Programming using Swing 459
Java Foundation Classes (JFC) 459
Packages of JFC ;.. 460
javax.swing ~d MVC - : 460
Window Panes '. 461
Important Classes ofjavax.swing 463
Creating a Frame in Swing 463
Displaying Text in Frame 466
JComponent Class Methods 469
Creating a Push Button with All Features : , 475
. Displaying Image in Swing 476
Creating Components in Swing 479
SettiI:g the Look and Feel of Components 482
JTable Class 485
JTabbedPane Class 489
JSplitPane Class 491
JTree Class 493
JComboBox Class 497
JList Class : .- 499
16. tiFF
Table of Content ~
.JMenu Class : 502
JToggleButton Class.: :- 509
JProgressBar Class 511
.JToolBar Class · »'••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••• 514
s
JColorChooser Class 516
Handling Keyboard Events : 517
Handling Mouse Events 519
Chapter 29: Graphics Programming - Layout Managers ~.523
FlowLayout .- : ~..:.. 524
BorderLayout - 525
CardLayout - 527
Using a Layout Inside Another Layout.. 529
GridLayout : : 532
GridBagLayout : :.................................•. 533
BoxLayout .- .- 539
Box Class : ; 541
Chapter 30: Applets : 545
Creating an Applet ; 545
Uses of Applets .- 547
<APPLET> tag 547
A Simple Applet : 548
An applet with Swing Components 550
Animation -in Applets , 553
A siri:J.ple Game with an Applet 557
Applet Parameters 5~9
Chapter 31: Generic Types 563
Generic Class :: 563
Generic Method : 566
Generic Interface .- 567
Chapter 32: Java Database Connectivity 571
Database Servers 571
Database Clients 572
JDBC (Java Database Connectivity) 573
-Working with Oracle Database :.- _ .- 574
Working with MySQL Database 576
Stages in a JDBC Program , 578
Registering the Driver 579
Connecting to a Database 580
Preparing SQL Statements 581
Usingjdbc-odbc Bridge Driver to Connect to Oracle Database ; 586
17. xx ICore Java - Ail Integrated Approach
Retrieving Data from MySQL Database 588
Retrieving Data from MS Access Database , 590
Improving the Performance of a JDBC Program : 592
(a) Affect of Driver. 593
(b) Affect of setFetchSlzeO 595
(c) Affect of PreparedStatement 597
Stored Procedures and CallableStatemerit 599
Types of Result Sets 603
Storing Images Into Database : ~ 607
Retrieving Images From Database 609
Storing a file into database 610
Retrieving a File from the Database , 611
ResultSetMetaData '" , 613
DatabaseMetaData : ' 614
Types of JDBC Drivers ; 616
Question Index , ; : 621
Program Index ; , ;.629
18. I
l
,
Preface
The importance of Java language cannot be denied as it has already started ruling over the entire
Software Industry. Companies have started recruiting programmers but there is still a dearth of
Java programmers. I set teaching as my profession in 1993, and have ever since engaged my time
in teaching and training thousands of students in Computer Sciences. Since 2000, I started
teaching Java to students. When my students asked me to prescribe a book for their reference, I
naturally thought of writing an ideal book for them that would fulfill the following goals:
o The book should be written in such a way that learners without any background in
programming should be able to follow it and understand it entirely. This meant that the book
should discuss the concepts of Java in a simple and straightforward language with a clear-cut
explanation, without.beating about the bush.
o Once the students understood the book, they should be able to at least write simple programs
on their own, as this is the first requirement to become a Java programmer. It meant the book
should provide ample solved programs, which could be used by the students not only in their
examinations but also to remove the fear of programming from their minds.
o After reading 'the book, the students should have the' confidence to apply for a· software
development company, face the interview board and come out successful. It meant the book
should also cover sample interview questions, which were asked in various interviews. This
would help the students to prepare well for their future careers.
I searched the market for such a book and to my dismay, I could not found a single one. I found-
some books that provided the concepts, but were lacking in programming examples. A few books
gave programs without any insight into the concepts. None of them was useful to learn Java. To
address this need, I thought of writing a book on Java with a three-stage formula: concepts +
programs + interview questions. The result of my endeavour is the book you have in your hands
now!
"-
Since many students are opting for Computers or IT as the subject of their study, there is a growing
need for them to learn Java from the ground up as well as learn good programming skills, and
finally pursue a career in software development as a Java professional. ,This book will help them
achieve these goals by following a three-stage process focusing on understanding Java, writing
programs, and facing interviews.
Many Indian students may wish to use this book to solve the programs generally asked in their
exams, since this book covers programs such as generating the Fibonacci number series, finding
prime, generating primes, finding the product of matrices, creating subclasses such as rectangle,
circle, triangle from a super class, creating interfaces, and so on. Such programs are commonly
asked in the exams of Indian universities, at B.C.A, B.Sc, M.Sc, M.C.A and Engineering levels.
The coverage of interview questions along with the subject matter will help students do well in
interviews. The questions presented in this book have been collected from various interviews
conducted by top companies while recruiting the candidates.
What this book contains
This book has 32 chapters in all, arranged in increasing order of complexity. Hence, it is advised
that readers start reading this book from the beginning unless they have some previous knowledge
of the subject. The first ten chapters will help bring readers from the novice stage to a stage where
they will have gained a proper understanding the fundamentals. These chapters cover the concepts
of Java and JVM along with the basic elements of writirig a Java program.
I-
.-t Ilii IIIIIIiiI._
19. xxii
Chapter 11 is on OOPS, and covers the concepts on which the Java language was built. The
subsequent chapters explain these concepts (Classes, Objects and Methods) with programs.
Inheritance and Polymorphism, two powerful features of an OOP language, are covered in chapters
15 to 17. Abstract classes and interfaces are discussed in chapters 18 and 19.
Once the software is developed, packaging the classes and providing an API document are
necessary. These issues are discussed in Chapter 20.
Handling errors and exceptions that occur in a Java program are discussed in Chapter 21, while
Chapter 22 discusses how to convert fundamental data into object form.
•
Chapters 23 to 32 are devoted to advanced concepts. The process of arranging various objects in the
memory comes under the collection framework, which has been described in Chapter 23; Chapter
24 tells you how to create fIles using streams; Chapter 25 shows you how to create client and server
programs for a network; and, Chapter 26 covers Threads.
Chapters 27 to 30 discuss the GUI programs, which provide all enhanced user experience.
Chapter 31 is on Generics and Chapter 32, the last chapter of the book, deals with writing Java
programs to communicate with any database.
Version used in this book
While this book is not a complete reference, it covers all core concepts in a methodical way. The
focus is on the important concepts and not on version-specific issues. Hence, you can use this book
to learn Java without worrying too much about the version. .
20. CHAPTER
ALL ABOUT
NETWORKS
d
W
e shall begin this chapter with an understanding .of networking concepts and proceed
further to kriow why languages, like CjC++, are not opted for a network and why Java is a
language suited for a network, especially Internet. _
InterconnectiQn of computers is called network. A network may contain two or more computers
connected with or without a cable. For example, you can connect a computer in Delhi to one placed.
in.Hyderabad with the help of a satellite and data can be sent or received via satellite in the form of
electromagnetic waves. So, a network mayor may not have a cable.
The primary purpose of a network is resource sharing, which means a computer can share its
resources, like data, memory, software, hardware, CPtJ, etc. with other computer.s on the network.
In the network, one computer may ask the other computer for some service. The computer, which
requests for some service is called client and the other computer, which provides that service to the
client· is called' server. A network can have several clients and servers and such a network
architecture is also called a client/server architecture.
Figure 1.1 shows a client jserver architecture. Here, you can see that the request goes from the
client to the server and the server gives back the response.
request -
...
Client i Server
...
response
Client sends request for service.
Server sends response to client.
Figure 1.1 A network with two computers
,
21. ~--_.
2.JChapter 1
Now, let us see how we can connect one computer to another. Following are the requirements for
setting up a network of computed's:
What is the advanta{Je of a netw?rk?
The main advantage of a (,Ie~ork is that it makes resource sharing possible among the connected
systems, thus helping in better utilization'of resources.
Hardware: Computer sy~tems, Network Interface Cards (NIC), cables, modems, hubs, satellites,
etc. ,. {
Software: Any software, which supports networking features, like Unix, Linux, Windows -NT,
etc. so that data.can be sent or received.
Protocol: Protocol could be defined as a standard procedure for regulating data transmission
between computers. It specifies a way to identify the destination and source computers and
establish a connection 'between them to receive or send data. For example, TCP/IP or UDP
protocols help to divide data into small packets of several bytes, insert the packets into frames,
and then send those frames to the destination computer over the network. Protocol is the
underlying feature of the software used on the network.
o
o
o
What Comprises the Internet?
Internet could- be defined as the network of all the computers eXisting on the ea,rth. Not only
individual computers but also a network of computers can be connected into the Internet. For
example, a company may have 100 computers, all connected by the cable. Now, this local network
can be directly connected to the Internet, so that it becomes a part of the Internet. So, Internet is
also sometimes defined as a global network of all networks.
Going back to the history ofInternet in 1969, DoD (Department of Defense), which is a US military
defense department, got 4 computers which they connected with a cable. These 4 computers were
connected by a cable and Unix was installed on them. This is the first network on the earth, which
is also called ARPANET (Advanced Research Project Agency Network). Figure 1.2 shows how
computers were connected in an ARPANET. . ,.
=
Figure 1.2 ARPANET, the first network
Later on, NSFNET (National Science Foundation (NSF)) encouraged individual users to get
connected into this network. Any user can simply connect his computer into this network by using
a cable. But the first problem faced by the users is purchasing and installing the cables. For
example, imagine how much lengthy cable is needed if a person in India wants to connect his
computer to this network. So they thought of an alternative. If already available cables are used,
this problem will be' resolved. By that time, telephone networks are Widely available. Hence,
telephone companies like AT&T,. Hyundai, British Telecom, etc. came forward and offered their
networks for use. Now, the problem of connecting personal computers with a network is solved.
People who want to connect to the network can simply sit in their homes and connect their
computers to the telephone jack. Thus, more and more computers have started becoming a part of
this network and the network has grown rapidly. Today, this network has trillions of computers
22. All about Networks L1..
connected with each other. Thus, it became the biggest network on the eartli. This network is called
Internet.
A network of computers within an organization is called Intranet .'n external network connecting
an organization's network with that of another organization is called Extranei. In other words, we
can take Extranet as a network outside an organization connecting it to other organizations'
network. Similarly, an organization may use the services of a third party private network to
communicate with outside networks. This third party private network is called VAN (Value Added
Network). Now, let us try to understand the concept of Intranet and ExtFanet with the help of a
figure. In Figure 1.3, you can notice that the network within an organization '~ed Intranet and
that connecting the networks of two organizations is known as an Extranet.
Organization 1 Organization 2
'Figure 1.3 Intranet and Extranet
How does Internet Function?
'pke any network, Internet also requires certain hardware, software, and- protocols to perf0rJ!l its
ft.'nctions. For example, hardware like computer systems, cables, hubs, routers, satellites, etc. are
needed to connect different computers with each other. The computer, which is connected to
Internet Service Provider's (ISP) computer is called client and the ISP's computer is called server.
Other than ISP servers, many other servers are maintained and used privately by some
organizations. Currently, millions of servers are available on Internet. Some servers focus on a
single.area like maintaining employees' attendance in a company or scheduling the jobs for the
employees of different branches. Such servers are called Application servers. Some servers provide
services purely related to Internet, for example, maintaining the Websites and communicating with
clients on Internet. Such servers are called Web servers. "
A client machine and a server machine on Internet also need software. The software that is installed
on an Internet client is called Web browser. Popular Web browsers are Internet Explorer,Netscape
Navigator, Mozilla Firefox, Mosaic, etc. The software that is installed on an Internet server machine
is called Web server. There are several Web servers, like IIS (Internet Information Server), Web logic,
Web dynamics, Apache, JBoss, etc.
Apart'from software, protocols are also used on Internet. The most widely used protocol on Internet
is http, which stands for hypertext transfer protocol. http is responsible for displaying the html
pages (or Web pages) on your client machine when you browse Internet. When you download a file
from Internet to your client machine, you are using ftp (file trapsfer protocol). When you send
mails, SMTP (Simple Mail Transfer Protocol) is used, and while receiving mails POP (Post Office
Protocol) is used. .
Which is the most widely used protocol on Internet?
Hypertext transfer protocol (http) is the most widely used protocol on Internet. The text on Internet is
sent or received from one machine to another using this protocol only.
Software Development for Internet
Suppose we are writing a C program with the name x :c. This means x. c fIle contains source code.
When we compile this program, we get x. obj fIle that contains machine language code, which is
23. .±.JChapter 1
just equal to the source code in x. c me. For example, this x. obj me contains the first statement to
-include a header me, like <stdio. h>. When we run the program, C compiler goes to the C standard
library (it is found generally,Juo-tclib)' and searches for the header file <stdio. h> there:,When the
header file is found, C compiler copies the ~ntire code (this code will be in machine language format)
from the header file int,9'-the C program. So,:ifyou writeaC program of 10 lines and the <stdio.h>
file contains 200 line~ then the total size of the file will be 210 lines. This file is also called x. exe
file. This file is a full-fledged. file that contains the entire prof7'l.m in machine language instru,ctions.
These instructions-,are understandable to the microprocessor. So it executes them and gives the
results. Figur~shows how the source code in a C program is converted to machine language
instruction~beforebeing executed by the compiler.
. ,
There are several microprocessors developed by many companies, for example, Intel Corporation.
Every microprocessor can recognize a group of instructions called the Instrnction set of that
-microprocessor. So the instructions recognized by Pentium processor may not be understandable to
the Celeron and similarly the instructions of Celeron may not be understandable by Spark
processor.
If we generate x .'exe file on a computer with Pentium processor, then that x. exe file contains
machine laIlguage instructiohs understandable to Pentium only. If we tryeto execute this x . exe file
on another computer with Spark processor, it may not be able to 'execute the instructions of x. exe
file. The reason is Spark processor cannot understand th~ Pentium processor instructions, which
are in x. exe.
Figure 1.4 Execution of a C program
D
=
Program output
Executable code
Object code
C program
source code
Similarly, develop x . exe file using an operating system like DOS. Then 'copy this x. exe into other'
. operating system like UNIX. Now, try to execute the x. ex€! file on UNIX. You will see that you
cannot! The reason for this is that every operating system stores the ·data and instructions iI:l
different formats. For example, the instruction for addition of two values may be stored by DOS as:
add a, b; whefeas the same instruction may be stored by UNIX as: a add b. So, if we try to
execute add a, b instruction in UNIX, it cannot un1erstand it since its format is different from
what it is expecting. This is 'the reason, why we cannot execute the same x. exe me' in different
operating systems.
There is a lot about instruction formats. The example that we have taken is only for illustration purpose.
What does it mean? If we created an . exe file in C or C++ on X processor and Y operating system,
then we can execute it on X processor and Y operating system only. If the processor is changed or '
the operating system is changed, then it is not possible to execute the same code. This means C or
C++ programs are executable only on the computer system that has X processor .and Y operating
system, where they have been developed. They cannot be executed on a different configUration. So
they are called system dependent programs. Hence, C or' C++ languages are also called system
dependent or platform dependent languages.
Now, let us come back to Internet. As we know that Internet is a global network of all the computers
existing on the earth and anyone can connect hisfI:er computer to this network. So there will be
different types of compu'~ers with different processors and different operating systems existing on
Internet. It is completely heterogeneous. So, if a software is developed using C/C++ like languages,
that software can be distributed on the Internet and people can download the . exe files, but they
cannot run those files because of their system dependency. So C/C++ is not suitable for developing
24. I
All about Networks l.l.
.software for Internet. We need a language, which is completely system independent so that it can
run on any system on Internet. And that is Java!
How Java is suitable for Internet? In Java, if we write a program, it is stored with an extension
. java. Let us create a program, say x. java. It contains java source code stat~ments. Now, the: first
step is to compile this x. java program. To do· that, Java compiler first translates the x. java
program into x. class file. What will be there in x. class file? Java pe:ople coined a group of
instructions to express any operation. These instru~tions are called byte code instructions because
the size of each instruction is 1 byte (=8 bits) exactly. There are a -fixed fiu~er of byte code
instructions, around 200. Any java program can be rewritten using these'Iew byte code
instructions. That file is called x. class. So, we can say that a x. class file containssource code
equivalent to byte code. ".
But the microprocessor cannot understand byte code instructions, neither can it execdte them.
Then, these byte code instructions are meant for whom? They are for JVM (Java Virtual Ma2h---n'i~
These byte code instructions are understandable by JVM, which is a program written to understand
the byte code instructions and convert them into machine code. JVM's role is very crucial in a way
that it has to first identify the operating system and processor used in the computer system and
then convert the byte code instructions in an understandable format for that particular processor
and operating system.
Remember, JVM is not a machine-it is a program! JVM program is freely available on Internet and
can be downloaded for use in a few minutes. Figure 1.5 shows how a java- source code passes
through various stages before being executed by the compiler.
- ---:::::::.
o
=
Java program
source code.
Byte code JliM converts byte - Program output
code into machine code
i
Figure I.S Execution of a Java program
. So, if -ive write x. java program on a computer using Pentium processor and compile it, the compiler
will produce x. class containing byte code instructions. -
These byte code instructions are given to JVM. Now JVM understands that we are using Pentium
processor in our system, so -it converts byte code into-machine code, which is understandable by
the Pentium processor. So the processor executes it and displays the results. Similarly, JVM
understands the operating-system used in the computer and accordingly it forms the instructions,
so there will not be any problem for the operating system to understand these instructions. Now, if
we send the same x. class file to another computer system with a different processor, say Spark
processor, then the JVM in that system will convert these byte code instructions to machine code
understandable by the Spark processor. So Spark processor can execute those instructions and
display the results. In this way, we can execute the . cl-ass file on any computer system with- any
processor and any operating system-provided JVM is available.
Remember byte code is system independent. It can be created on any computer using those
predefined 200 instructions only. But JVM is system dependent, since it has 10 interact with the
processor and operating system of the computer. This is the reason behind several flavors of JVM
available on Internet. If we are using Windows, then we should download only Windows version of
JVM and if we are using Linux, then we should use only Linux version of JVM.
So, if we write a· . java program on X processor and Y -operating system, then that program is
executable on any other computer system with any processor and operating system. This means
java programs are system independent or platform independent. That's why Java is called a system
independent programming language.
On Internet, different computer systems with different processors and different operating systems
are available, but still Java programs will run on any system and produce the same results on all
the systems. If we develop a software using Java, the. class files can be downloaded from Interne
25. ~ Chapter 1
and can be executed on any other computer system without any problem. Hence, Java is a suitable
programming language for-software development on Internet.
What is the difference· between an executable file and a .class file?
.exe file- contains machine language instructions for the microprocessor and is system dependent.
.class file contains byte code instructions for the JVM and is system independent.
.-/- - .
Since Inteniet is a public network, everyone can connect their computers into Internet and this
leads to several security problems for data. Suppose, we are sending an email to a friend. Now, this
mail will' go through millions of servers on Internet before reaching the destination computer. In
between, anybody can open the mail and see the data of the mail. Thus, we can say that data sent
over' Internet is' susceptible -to many kinds of security threats. Let us discuss some of the major
-~curityproblems for data.on Internet along with their solutions:
o Eavesdropping: This means reading others' data illegally on Internet. For example, opening
others' emails and reading them comes into this category. The solution for thIS problem is:
encryption and decryption. Converting the data into an unre~dable format is called encryption
and getting back the original data from the encrypted format is called decryption. When
sending the email, we can encrypt the data and send it. If any third person opens it, he cannot
read it because it is in an unreadable format. While encrypting the data, we use a password
called key. Only the person who knows that key can decrypt it and read it. This key is known to
our friend to whom the email is sent, so that only he can open it and read it. Encryption and
decryption can be done using Java technology.
o Tampering: This is another problem on Internet. Not only reading others' data but also
modifying it is called tampering. Encryption and decryption is the solution for this problem arso.
If we encrypt the data, a third person cannot read it so he cannot modify it also.
o Impersonation: A per-son disguising himself as another person on Internet is called
impersonation. _
Many people hide their original identity and act as somebody else to make
transactions. The solution for this problem is digital signature. Digital signature is a file that
contains personal identification information in an encrypted format. Storing the personal
information in digital signature and sending this information along with the email assures the
receiver of the identity of the sender. Digital signature can be created using Java technology,.
o Virus: Virus represents a program that can cause harm to the data, software, and hardware of
a computer system. Most of the viruses spread with . exe,. doc, image (. gif, . jpg), audio,
and video mes(.mpg, .avi, .mp3). Virus cannot spread with a .txt me (example, the.me
created in Notepad). In Java, we create. class mes, which are similar to . txt mes and hence
there is no chance of virus affecting these meso Even if somebody intentionally tries to
incorporate the virus code into a , class file, JVM can verify its presence before running the
program and, if found, can abort the .class file's execution.
From ,the above discussion, we can say that Java is the language, which can eliminate the above
security problems that often occur on Internet. This is another reason why Java is sought after for
developing software meant for Internet.
'~.-"Q:~
Why Java is suitable for Internet?
(Java is suitable for Internet because of two main reasons. 1) It is system independent and hence its
-programs can run on any type of computer system available on Internet. 2) It eliminates a lot of
security problems for data on Internet. .
Conclusion
By now, you must have gathered information about networks, the Internet, and how Java is
suitable for the Internet.
26. CHAPTER
INTRODUCTION
TO JAVA
t
B
efore starting to learn Java, let us plunge into its history and see how the language
originated. In 1990, Sun Microsystems Inc. (US) has conceived a project to develop software
for consumer electronic devices that could be controlled by a remote. This project was called
Stealth Project but later its name was changed to Green Project
In January of 1991, Bill Joy, James Gosling, Mike Sheradin, Patrick Naughton, and several others
met in Aspen, Colorado to discuss this' project. Mike Sheradin was to focus on business
development; Patrick Naughton was to begin work on the graphics system; and James Gosling was
to ide.ntify the proper programming language for the project. Gosling thought C and C++ could be
used to develop the project. But the problem he faced with them is that they were system dependent
'languages and hence could not be used on various processors, which the electronic devices might
use. So he started developing a ne"", language, which was completely system independenf. Th'is
language was initially called Oak. Since this name was registered by some other company, later it
was changed to Java. '
Why the name Java? James Gosling and his team members were consuming a lot of tea while
developing this language. They felt that they were able to develop a better language because of the
good quality tea they had consumed. So the tea also had its own role in developing this language
and hence, they fIxed the name for the language as Java. Thus, the symbol for Java is tea cup and
saucer.
B)llSeptem1:>er of 1994, Naughton and Jonathan Payne started writing WebRunner-a Java"based
Web browser, which was later renamed as HotJava. By October 1994, HotJava was stable and was
demonstrated to Sun executives. HotJava was the fIrst browser, having the capabilities of executing
applets, which are programs designed to run dynamically on Internet: This time, Java's potential in
the context of the World Wide Web was recognized.
Sun formally announced Java and HotJava at SunWorld conference in 1995. Soon after, Netscape
Inc. 'announced that it would incorporate Java support in its browser Netscape Navigator.- Later,
Microsoft also announced that they would support Java in their Internet Explorer Web browser,
further solidifying Java's role in the World Wide Web. On January 23rd 1996, JDK 1.0 version was
released. Today more than 4 million developers use Java and more than 1.75 billion devices run·
Java. Thus, Java pervaded the world.
Features of Java
Apart from being a system independent language, there are other reasons too for the immense
popularity of thi-s language. Let us have a look at some of its features.
27. .!..JChapter 2
o Simple: Java is a simple programming language. Rather than saying that this is the feature of
Java, we can say that this is the design ,aim of Java. When 'Java is developed, they wanted it to
be simple because it has to work on electronic devices, where less memory is available.' Now,_
the question is how Java is made simple? First of all, the difficultconcepts of C and C++ have
been omitted in Java. For example, the concept of pointers-which is very difficult for both
learners and programmers-has been completely eliminated from Java. Next, 'JavaSoft (the
team who develoPed Java is called with this name) people maintained the same syntax of C and
C++ in Java, so that a programmer who knows C or C++ will find Java already familiar.
Figure 2.1 Class and object
Why pointers are eliminated from Java?
1. Pointers lead to confusion for a programmer.
2. Pointers may crash a program easily, for example, when we add two pointers, the program,
crashes immediately. The same thing could also happen when we forgot to free the memory
allotted to a variable and reallot it to some other variable.
3. Pointers break security. Using pointers, harmful programs like Virus and other hacking
programs can be developed.
Because ofthe above reasons, pointers have been'eliminated from Java.
o Object-oriented: Java is an object,oriented programming language. This means Java programs
use objects and classes. What is an object? An object is anything that really exists in the world
and can be distinguished from others. Everything that we see physically will corne into this
definition, for example, .everyohuman being, a book, a tree, and so on. .
Now, every object has properties and exhibits certain behavior. Let us try to illustrate this point by
taking an example of'a dog. It got properties like name, height; color, 'age, etc. These properties are
represented by variables. Now, the- object dog will have some actions like running, barking, eating,
etc. These_~actions are represented by variou~ methods (functions) in our programming. In
programming, VaflOUS tasks are done by methods only. So, we can conclude that objects contain
variables and methods. .
A group of objects exhibiting same behavior (properties + actions) will come under the saI1!.e group'
called a class. A class represents a group name given to several objects. For example, take the clogs:
Pinky, Nancy, Tom, and Subbu. All these four dogs exhibit same behavior and hertce belong to the
same group, called dog. So dog is the class name, which contains four objects.Jn other words, we
could define a class as a model or a blueprint for creating the objects. We write the charaCteristics
of the objects in the class: 'dog'. This means, a class can be used as a model in creation of objects.
So, Just like objects, a class also contains properties and actions, i.e. variables and methods
(Figure 2.1).
properties· vars
actions· methods
ruoO
bark{)
eatO
Tom
_1 foot
brown
5_years
object Tom
actions· methods
properties: vars -
running
barking
eating
height-",
color
_ age
class: Dog
28. Introduction to Java L.2.
We can use a class as a model for creating objects. To write a class, we· can write all the
characteristics of objects which_should follow the class. These characteristics will guide us to create
the objects. A class and its objects are_almost the same with the difference that a class does not
exist physically, while an object does. For example, if we say dog; it forms a picture into our mind
with 4 legs, 2 ears, some length and height. This picture in our mind i1'Lc1ass. If we.. tally this picture
with the physical things around us, we can find Tom living in our house is satisfying these qualities.
So Tom, which physically exists, is an object and not a class.
Let us take another example. Flower is a class but if we take Rose, Lily, Jasmine - th~y are all
objects of flower class. The class flower does not exist physically but its objects, like Rose, Lily,
Jasmine exist physically.
What is the difference between a function and.a m€}thod?
A method is a function that is written in a class. We do not haile functions in Java; instead we-'have
methods. This means whenever a function is written in Java, it should be written inside the class only.
But if we take C++, we can write the functions inside as well as outside the class. So in C++, they are
called member functions and not methods.
- ' -
Since Java is a purely object-oriented'prograrriming language, in order to write a program in Java,
we need atleast a Class or an object. This is the reason why in every Java program we write atleast
one class. C++ is not a purely object-oriented language, since it is possible to write programs in C++
without using a class or an object. ' -
o Distributed: Information is distributed on various computers on a network. Ysing Java, we can
write prQgrams, which capture information and distribute it to the clients. This is possible
because Java can handle the protocols like TCP/IP and UDP.
[J Robust: Robust means -strong. Java programs are strong and they don't crash easily like a C or
C++ program. There arc two reasons -for this. Firstly, Java has got excellent inbuilt exception
handling features. An exception is an error that occurs at run time. If an exception occurs, the
program terminates abruptly giving rise to problems like loss of data. Overcoming such
problems is called.'exception handling. This means that even though an exception occurs in a
Java program, no harm will happen. - -
..
Another reason, why Java is robust lies in its memory management features. Most of the C and C++
prOgrams crash in the' middle because of:not allocating sufficient memory or forgetting the memory
to be freed in a program. Such problems will not occur in Java because the user need not-allocate.
or deallocate the memory in Java. Everything will be taken care of byJVM only. For exa.rnple, JVM
will allocate the necessary memory needed by a Java program.
Which part of JVM will allocate the memory for a Java program?
Class loader subsystem of JVM will allocate the necessary memory needed by the Java prpgram.
Similarly, JVM is also capable of deallocating the memory when it is nut used. Suppose a variable or
an object is created in memory and is not used. Then after some time, it is automatically removed
by garbage collector of JVM. Garbage collector is a form of memory management that checks the
memory from time to time and marks the variables or objects not used by the program,
automatically. After repeatedly identifying the same variable or object, garbage collector confirms
that -the variable or object is not used and hence can be deleted.
29. .2EJChapter 2
Which algorithm is used by garbage collector to remove the unused variables or objects from memory?
Garbage collector uses many algorithms but the most commonly used algorithm is mark and sweep.
How can you call the garbage collector?
Garbage collector is automatically invoked when the program is being run. It can be also called by
calling gc() method of Runtime class or System class in Java.
o Secure.: Security problems like eavesdropping, tampering, impersonation, and virus threats can
be eliminated or minimized by using Java on Internet.
o System independence: Java's byte code is not machine dependent. It can be run on any
machine with anycprocessor and any operating system.
o Portability: If a program yields the same result on every machine, then that program is called
. portable. Java programs are portable. This is the result of Java's System independence nature.
o Interpreted: Java programs are compiled to generate the byte code. This byte code can be
downloaded and interpreted by the interpreter in JVM. If we take any other language, only an
interpreter or a compiler is used fo execute the programs. But in Java., we use .both compiler
and interpreter for the execution.
o High Performance: The-problem with interpreter inside the JVM is that it is slow. Because of
this, Java programs used to run slow. To overcome this problem, along with the interpreter,
JavaSoft people have introduced JIT (Just In Time) compiler, which enhances the speed of'
execution. So now in JVM, both interpreter and JIT compiler work together to run the program.
o Multithreaded: A thread represents an individual process to execute a group of statements.
JVM uses several threads to execute different blocks of code. Creating multiple threads is called
'multithreaded'.
o Scalability: Java platform can be implemented on a wide range of computers with varying
levels of resources-from embedded devices to mainframe computers. This is possible because
Java is compact and platform independent. - ~.
o Dynamic: Before the development of Java, only static text used to be displayed-in the browser.
But when James Gosling dernonstrated an animated atomic molecule where the rays are
moving and stretching, the view~rs were dumbstruck. This animation was done using an applet
program, which are the dynamically intetacting programs on Internet.
The Java Virtual Machine
Java Virtual Machine (JVM) is the heart of entire Java program execution process. It is responsible
for taking the . class file and converting each byte code instruction into the machine language
instruction that can be executed by the microprocessor. Figure 2.2 shows the architecture of Java
Virtual Machine.
30. Method
area
Classfile_
Class loader
subsystem
I
Java
stacks
pc
registers
Introduction to Java l!!..
Native
method
stacks
t
Interpreter
Execution I
'engine
Runtime data areas
JIT
compiler ~
.I Operating System
Figure 2.2 Components in JVM architecture
First of all, the . java program'is converted into a . clas s me consisting of byte code instructions by
the java compiler. Remember, this java compiler is outside the JVM: Now this. class file is given to
the JVM. In JVM, there is a module (or program) called class loader sub system, which performs the
following functions: .
o First of all, it loads the. class fIle into memory.
o Then it verifIes whether all byte code instructions are proper or not. If it fmds any instruction
suspicious, the execution is rejected immediately.
o If the byte instructions are proper, then it allocates necessary memory.to execute the program.
This memory is divided into 5 parts, called run time data areas, which contain the data and results
while running the program. These areas are as follows:
o Method area: Method area is the memory block,. which stores the class code,. code of the
variables, and code of the methods in the Java program. (Method means functions written in a
class)
o Heap: This is the area where objects are created. Whenever JVM loads a class, a method and a
heap area are immediately created in it.
o Java Stacks: Method code is stored on Method area.. But while running a method, it needs
some more memory to store the data and results. This memory is allotted on Java stacks.. So,
Java stacks are memory areas where Java methods are executed. While executing methods, a
separate frame will be created in the Java stack, where the method is executed. JVM uses a
separate thread (or process) to execute each method. .
o PC (Program Counter) registers: These are the registers (memory areas), which contain
memory address of the instructions of the methods. If t1:J.ere are 3 methods, 3 PC registers will
be used to track the instructions of the methods. .
o Native method stacks: Java methods are executed on Java stacks. Similarly, native methods
(for example CjC++ functions) are executed on Native method stacks. To execute the native
methods, generally native method libraries (for example CjC++ header mes) are required. These
header mes are located and connected to JVM by aprogram, called Native method interface.
31. ~ Chapter 2
Execution engine contains interpreter and JIT (Just In Time) compiler, which are responsible for
converting the byte code instructions into machine code so that the processor will execute them.
Most of the JVM implementations use both the interpreter and JIT compiler simultaneously to
convert the byte code. This technique is also called adaptive optimizer.
Generally, any language (like C/C++, Fortran, COBOL, etc.) will use either an interpreter or a
compiler to translate the source code into a machine code. But in JVM, we got interpreter and JIT
compiler both working at the same time on byte code to translate it into machine code. Now, the
main question is why both are needed and how both work simultaneously? To understand this, let
us take some sample code. Assume these are byte code instructions:
When, the-interpreter starts execution from IS,I instruction, it converts print a; into machine code
and gives it to the microprocessor. For this, say the interpreter has taken 2 nanoseconds time. The
processor takes it, executes it, and the value of a is displayed.
Now, the interpreter comes back into memory and reads the 2nd instruction print b; To convert
this into machine code, it takes another 2 nanoseconds. Then the instruction is given to the
processor and it executes it. ~
Next, the interpreter comes to the 3rd instruction, which is a looping statement print a; This
should be done 10 times and this is known to the interpreter. Hence, the first time it converts
print a into machine code. It takes 2·nanoseconds for this. Mter giving this instruction to the
processor, it comes back tomemoxy and reads the print a instruction the 2nd time and converts it
to machine code. This will tS-ke another 2 nanoseconds. This will be given to the processor and the
interpreter. comes back and reads print a again and converts it 3rd time taking another 2
nanoseconds. Like this, the interpreter will convert the print a instruction for 10 times,
consuming a total of 10 x 2 = 20 nanoseconds. This procedure is not efficient in terms of time. That
is the reason why JVM does not allocate this code to the interpreter. It allots this code to the JIT
compiler.' .
Let us see how the JIT compiler will execute the looping instruction. First of all, the JIT compiler
reads the print a instruction and converts that into machine code. For this, say, it is taking 2
nanoseconds. Then the JIT compiler allots a block of memory and pushes this machine code
instruction into that memory. For this,say, it is taking another 2 nanoseconds. This means JIT
compiler has taken a total of 4 nanoseconds. Now, the processor will fetch this instruction from
memory and executes it 10 times. Just observe that the JIT compiler has taken only 4 nanoseconds
for execution, whereas to execute the same loop the interpreter needs 20 nanoseconds. Thus, JIT
compiler increases the speed of execution. Recognize that the first two instructions will not be
allotted to JIT compiler by the JVM. The reason is clear. Here it takes 4 nanoseconds to convert
each instruction, whereas the interpreter actually took only 2 nanoseconds.
Mter loading the . class code into memory, JVM first of all identifies which code is to be left to
interpreter and which one to JIT compiler so that the performance is better. The blocks of code
allocated for JIT compiler are also called'hotspots. Thus, both the interpreter and JIT compiler will
work simultaneously to translate the byte code into machine code.
What is JIT compiler?
JIT compiler is the part of JVM which increases tbe speed of execution of a Javaprogram.
32. Introduction to Java ~
Differences between c++ andJava:
By the way, C++ is also an object-oriented programming language, just like Java. But there are
some important feature-wise differences, between C++ and Java. Let us have a glance at them' in
Table 2.1.
Table 2.1
C++ Java
C++ is not a purely object,-oriented
·~~~~n~~~~;oJ· '~o~i
using a class er an object.
Pointers are available in C++.
Multiple Inheritance feature is available
in C++.
. Ope.rator overloading is available in C++. It>4s not available in Java.
and header files are
There are constructors and destructors
in C++.
Parts of Java
Only constructors are there in Java. NCLdestructors
are available in this language.
Sun Microsystems Inc. has divid~d Java into 3 parts-Java SE, Java EE, and Java ME. Let us
. discuss them in brief here:
o Java SE: It is the Java Standard .Edition that contains basic core Java classes. This edition is
used to develop standard appletsand applications.
o Java EE: It is the Java Enterprise Edition and it contains classes that are beyond Java SE. In
fact, we need Java SE in order to use many of the classes in Java EE. Java EE mainly
concentrates on providing business solutions on a network.
o Java ME: It stands for~Java Micro Edition. Java ME is for developers who develop code. for
portable devices, such as a PDA or a cellular phone. Code on these devices needs to be small in
siz€ and should ~ake less memory.
33. .2!JChapter 2
Java software can be downloaded from the Sun Microsystems site:
http://java.sun.comljavase/downloads/index.jsp
Conclusion
. In this chapter, you have learned the features of the Java. and got familiar with the JVM
architecture along with part of ~ava. By now, you must have got a glimpse of Java. Along with all
thi~,we have also compared the C++ with Java. .
34. FIRST STEP
TOWARDS JAVA
PROGRAMMING
CHAPTER
W
henever we. want to write a ·program, .w~ ShO.Uld first think about. writing comme~ts. What
are comments? Comments are descnptlOn about the features of a program. ThIS means
that whatever we write in aprogram should be described using comments. Why should we
write comments? When we write comments, we can understand what the program is doing as well
as it helps others to easily follow our code. This means readability and understandability of a
program will be more. If a program is understandable, then only can it be usable in a software. If
other members of the software development team cannot understand our program, then they may
not be able to use it in the project and will reject it. So writing comments is compulsory in any
program. Remember, it is a good programming habit.
There are three types of comments in Java-single line, multi line, and Java documentation. Let us
discuss all of them here:
o Single line comments: These comments are for marking a SL'1gle line as a comment. These
comments start with double slash symbol / / and after this, whatever is written till the end of
the line is taken as a comment. For example,
Tn
o Multi-line comments: These comments are used for representing several lines as comments.
These comments start with / * and end with */. In between / * and */, whatever is written is
treated as a comment. For example,
o Java documentation comments: These comments start vvith / ** and ehd with */. These
comments are used to provide description for every feature in a Java program. This description
proves helpful in the creation of a .html file called API (Application Programming Interface)
document: Java documentation comments should be used before every feature in the program
as shown here:
7 ' cfescri ptl on
class coce
/"*.,d.escrd pti'on about a
Method c de
35. ~ Chapter 3
API Document
The API document generated from the. java program is similar to a helpflle where all the features
are available with their descriptions. The user can refer to any feature in this file and get some
knowledge regarding how he can use it in his program. To create anAPI document, we should use a
special compiler called j avadoc compiler. Figure 3.1 shows the process of creation of an API
document.
API document
class Classname
description about class
package Packagename
description about package
void rnethodname()
description about method
---+ void methodnameO
description about method
method code;
method code;
class code;
,- description about method""
void methodnameO
{
}
,.. d_escription about method-'
void mathodname()
{
Java program
r*description about package""
, package Packagename;
.e-description about dass*'
class Classname
{
In u e<s 10. >
What is an API document?
An API document is a . h tml file that contains description of all the features of a software, a product,
or a technology. API document is helpful for the user to understand. how to use the software or
. technology.
This means, a request is made to the C/C++ compiler to include the header file <s,tdio. h>. What is
a header file? A header file is a file, which contains the code of functions that will be needed in a
program. In other words, to be able to use any function in a program, we must first include the
header file containing that function's code in our program. For example, <stdio. h> is the header
Figure 3.1 API document creation
Importing classes
Suppose we are writing a C/C++ program, the frrstline of the program would generally be:
Starting a Java program
So let us shirt our first Java program with multi line comments:
36. First Steps towards Java Programming 17
me that contains functions, like printf (), scanf (), puts (), gets (), etc. So if we want to use any
of these functions, we should include this header file in our CjC++ program. '
What happens when we include the header fIle? After we include the header fIle, the CjC++
compiler goes to the standard library (generally it is available in tcl lib) and searches for the
,header fIle there. When it finds the header fIle, it copies the entire header me content into the
program where the #include statement is written. Thus, if we write a program of 10 lines; then
after copying code from the header file, the program size may become, say, 510 lines. From where
do these additional 500 lines are coming? They have been copied physically i,nto our program from
the header fIle. Thus, our program size increases unnecessarily, wasting memory and processor
ti~. .
A similar but a more efficient mechanism, available in case of Java, is that of importing classes.
First, we should decide which classes are 'needed in our program. Generally, programmers are
interested in two things:
o Using the classes by creating objects in them.
o Using the methods (functi~ns) of the classes.
In Java, methods are available in classes or interfaces. What is an interface? An interface is similar
to a class that contains some methods. Of course, there is a lot of difference between an interface
and a class, which we will discuss later. The main point to be kept in mind, at this stage, is that a
class or an interface contains methods. A group of classes and interfaces are contained in a'
package. A package is a kind of directory that contains a group of related Classes and interfaces and
Java has several such packages.,in its library,
Java library
I
Packages
I
Classes and interfaces
I
Methods
If a programmer wants to use a class, then that class should be imported into his program. If he wants
to use a method, then that corresponding class or interface should be imported into his program.
In our first Java program, we are using two classes namely, System and String. These classes
belong to a package called java .lang (here lang represents language). So tJ;i.ese two classes must
be imported into our program, as shown below:
Whenever We want to import several classes of the same package, we need not write several import
statements, as shown above; instead, we can write a single statement as:
mort "ava. an . .
Here, * means all the classes and interfaces of that package, i.e. java. lang, are imported (made
available) into our program. In import statement, the package name that we hav.e written acts like a
reference to the JVM to search for the classes there. JVM will not copy any code from the classes or
packages. On the other hand, when a class name or a method name is used, JVM goes to the Java
library, executes the code there, comes back, and substitutes the result in that place of the
program. Thus, the Java program size will not be increased.
37. ~ChaPter3
- What is the difference between#include and import statement?
,I
#include directive makes the f:ompiler go to the C/C++ standard library and copy the code from
'the header files into the program. As a result, the program size increases, -thus wasting memory and
processor's time. -
import statement makes the JVM go to the Java standard library, execute the code there, and
substitute the result into the program. Here, no code is copied and hence no waste of memory or
pt:ocessor's time, So, import is an efficient mechanism than #include.
Mter importing the classes into the program, the next step is to write a class, Since Java is purely
an object-oriented programming language, we cannot write a Java program without having at least
one class or object. So, it is mandatory that every Java program should have at least one class in it,
How to write a class? We should use class keyword for this purpose and then write the class name.
u51ic statlc Vela maln Strln ar 5
Next to main () method's name, we have written String args []. Before discussing the
main () method, let us fIrst see how a method works, A method, gen~rally, performs two functions.
D It can accept some data from outside
D It can also return some result
A class code starts with a { and ends with a }. We know that a class or an object contains variables
and methods (functions), 'So we can create any number of variables and methods inside the class.
This is our fIrst program, so we will create_ onlY.one method, i.e. compulsory, in it-main () method.
Why should we write main {} method? Because, if main () method is not Wlitten in a Java program,
JVM will not execute-it. main (} is the starting point for JVM to start execution of a Java program,
r 5
i CSt 'n
Let us take sqrt () method. This method is used to cal9ulate square root value -of a given number.
So, at the time of calling sqrt n method, we should pass a number (e.g~ 16) for which we want to
calculate square root, Then, it calcula_tes square root value and returns the result (e,g. 4) to us.
Similarly, main () method also accepts some data from us, For example, it accepts a group of
strings, which is also called a string type array, This array is String args [] , which is written along
with the main n method as:
I
Here args [] is the array name and it is of String type. This means that it can store a group of
strings, Remember, this array can also store a group of numbers but in the form of strings only. The-
values passed to main () method are called arguments. These arguments are stored into args []
-array, so the name args [] is generally used for it.
Amethod can return some result. If we want the method to return the result in form of an integer,
then we should write int before the method name. Similarly, to get the result ill string form or as a
single character, we can write string or char before it, respectively. If a method is not meant to
return any value, then we should write void before that method's name. void means no value.
main () method does not return any value, so void should be written before that method's name.
A method is executed only when it is called, But, how to call a method? Methods are called using 2
steps in Java.
38. First Steps towards Java Programming l.2!.
1. Create an object to the class to which the method belongs. The syntax of creating the object is:
I
2. Then the ~ethod should be called using the obj ectname .methodname () .
Since main () method exists in the class First; to call main () method, we should first of all create
an object to First class, something like this:
Then call the main () method as:
j.m i
So, if we write the statement:
- ,
",side the main () method, then JVM will execute this statement and create the object.
r class Fi rst
{
y looking at the code, we can understand that an object could be created ocly af!er callin~ the·
main () method. But for calling the main·() method, fIrst of all we require an object. Now, how'is it
possibl~ to cr~ate an object before callmg the main () method? So, ~e should- call the main·()
method without creating an" object. Such met.hods are called static methods and should be declared
as static.
Static methods are the methods, which can be called and executed without creating the objects.
Since we want to call main () method without using an object, we should declare main () method as
static. Then, how is the main () method called and executed? The answer is by using the
classname .methodname (). JVM calls main () method using its dass name as First .main () at the
time of running the program.
JVM is a program written by JavaSoft people (Java development team) and main () is the method
written by us. Since, main () method should be available to the JVM, it should be declared as
public. If we don't declare main () method as public, then. it doesn't make itself available to JVM
and JVM cannot execute it:
So, the main () method should always be written as shown here:
If at all we want to make any changes, we can interchange public and static and write it as
follows:
(jl)] lC
39. Till now, according to our discussion, our Java program looks like this:
'-
22.J Chapter 3
Or, we can use a different name for the string type array and write it as:
[
args'[] is not written in main () method?
When rnai n () method is written without S t r ing a rgs [J as:
public static void main ()
the code will compile but JVM cannot run the c,Ode because it cannot recognize the main () method as
the method from where it should start execution of the Java program. Remember JVM always looks for
main () method with sti-ing type arr!!y as parameter.
Our aim of writing this program is just to display a string "Welcome to Java". In Java, print ()
method is used to display something on the monitor. So, we can write it as:
But this is not the correct way of calling a method in Java. A method should be called by using
objectname .methodname (). So, to call print () method, we should create an object to the class to
which print () method belongs. print () method belongs to PrintStream class. So, we should call
print () method by creating an object to printStrea~class as:
But as it is not possible to create the object to PrintStream class directly, an alternative is given to
us, i.e. System. out. Here, System is the class nam~and 01l;t is a static variable in System class. out
is called afield in System class. When we call this field, a PrintStream class object will be created
internally. So, we can call the print () method as shown below:
System. out gives the PrintStream class object. This object, by default, represents the standard
output device, i.e. the monitor. So, the string "Welcome to Java" will be sent to the monitor.
Now, let us see the final version of our Java program:
40. First Steps towards Java Programming ~
Program 1: To display a message.
Output:
Save the above program in a text editor like Notepad with the name First. java. Now, go to System
prompt and compile it usingjavac compiler as:
The compiler generates a fIle called First. class that contains byte code instructions. This fIle is
executed by calling the JVM as:
Then, We can see the result.
We already discussed that JVM is a program. Which program is it? By observing the command java
First, We can say that JVM is nothing but java.exe program. In fact, JVM is written in C
language.
Let us write another Java program to fmd the sum of two numbers. We start this program with a
single line comment like this:
Then we should import whatever classes and interfaces we want to use in our program. In this
program, we will use two classes: Systemand String. These classes are available in the package
java. lang. So, we should import these classes as:
o a
Here, * represents all the classes of java. lang package. This import statement acts like a reference
for the JVM to search for classes when a particular class is used .in the program. After writing the
import statement, we should write a class,. since it is compulsory to create at least one class in
every Java program. Let us write the class as shown below:
41. ~ Chapter 3
We know that a class contains variables and methods. Even if we do not creste variables or
methods, we should write at least one method, Le. main (). The purpose of writing the main()
method is to make JVM execute the statements within it. Let us take ariexample:
Here, main () method is declared as public, static, and void. public because it should be made
available to JVM, which is another program; static because it should be called without using any
object; -and void because it does not return any value. Also, after the method name, we write
String args [] which is an array to store the values passed to main () method. These values
passed to main () are called arguments. These values are stored in args [] array in the form of
strings.
Inside the main () method, let us write the code to fi..'1d the sum of two numbers. Observe the full
program now:
- Program 2: To find the sum of hvo numbers.
numoers
jjdisplay resul<t
system.out.print(z);
Output:
In the above program, inside main () method, we write the first statement as:
int x
42. r
)
/
First Steps towards Java Programming ~
Here x, y are called variables. A variable represeritsmemory location' to store data or values. We
want to st()re 'integer immbers into x, y. So before t..~ese variables, we ,write into This int
represents the type of data to be stored into the variables. It is also calle<i a data type. By writing
int x, y, we are announcing the java compiler that we 'are going to store integer'type data into x, y
variables. Remember, declaring the datatype is always required before using any variable. All data
types available in Java are discussed in Chapter 4.
After declaring the x, y variables as int data type, we have stored integer numbers into x, y as:
I
= represents storing the right hand side value into the left hand side variable. Thus, 10 is stored
into x and 25 is stored into 'y'. So =is a symbol that represents assignment (or stor;;tge) operation.
Such symbols are also called operators. All the operators available in Java will be discussed in
Chapter.5. The next step is to find the sum of these values. For this purpose, we write:
At the right hand side we got x+y, which performs the sum. Here + is call~d additio'n' operator. The
result of this sum is stored into z, which we cteclared as another int type variable. Now, we should
display the result usirig print () method as:
Here, syste~ is a clas~ in java .lang package and out is a field in this class. When we'refer to
System. out, it createsPrintStream object, which, by default, represents the standard output
device, Le.fI!.onitor.' So, by writing System.out.pri'nt(z), we are passing z value to print()
method, which displays that value on the monitor. So in the output, we can see the result as 35. ,
Formatting the Output
In Program 2, we have used the foilowing statement to dispiay the result:
This will display the result ,35 'on the monitor. But, this is not the proper way to display the results
to the user'. When the user sees 35, he would be baffled as what is this I).umber 35? So, it is the
duty of the programmer to prompt the user with a proper message, something like this:
This is more clear and avoids any confusion for the user. How can we display the output in the
above format? for this purpose, we should add a string "Sum of two numbers=" before the z value
in the print () method:
Here, we are using +to join the string "Sum of two numbers=" 'and the numeric variable Z. The
'reason is that the print () method cannot ·display more than one value. So if two values, like a
string and a numeric value need to be displayed using a single print () method, we should
combine them using a + operator.
Now, the output will look like this:
43. r
n
2
r
wo nurn e
wo numOePs roz
o
um
S t m. t. r n "u 0
Sum 0
Please observe that we have used two print (.) methods and still we got the result in only one line.
What does it mean? First print () method is displaying the string: !'Sum of twolnumbers" and
keeping the cursor in the same line. Next print () me1:lJod is also showing its output in the same
u 0 two number'S
This will also give the correct result as:
Here, the execution will start from the inner braces.. At left, we got x, which represents a number
and at right we got y I which is also,a number. Since both are number-s, 'a<fcI1tion will be done by the
+ operator, thus giving a result 35. Then the result will be displayed like this:
urn· 0 two nurn ers-
To eliminate the above inner braces, we can use two print () methods like this:
n ~f t "nu blIFS'"'''+ X-r~
So, how to get the correct result? By using another pair of simple braces inside the print ()
method, we can get the correct result.
u 0 two nurn e 5
See the output is wrong. What is the reason? In the print () method's braces, from left to right, we
got a string "Sum of two humbers=" and two numerit: variables x and y as shown below:
Since left one is a string, the next value, i.e. of x is also converted into a string; thus the value of x,
i.e. ~O will be treated as separate characters as 1 aIld 0 and are joined to the string. Thus, we get
the output in the string form:
The next variable value is 25. Since till now, at left we got a string, so this y value is also converted
into a s~ring. Thus 2 and 5 are taken as separate characters and joined to the string, thus we get
the result as: .
which displays:
We know that value of x is 10 and y is 25. Suppose, we use print () method to display directly x+y
value in the place of z, we can write:
2!.JChapter 3
44. I
II
I
I
First Steps towards Java Programming 25
line adjacent to the previous string. To conclude, print () method displays the result and then
keeps the cursor in the same line.
Suppose, we want the result in two separate lines, then we can use println () methqd in the place
of print () method as:
This will display the result in two lines as:
Sum 0 two num6ers
p:cintln () is also a method belonging to PrintStream class. It throws the cursor to the next line
a....'ter displaying the result.
What is the difference between print () and println () method?
Both methods are used to display the results on the monitor. print () method displays the resLilt
and then retains the cursor In the same line, next to the end of the result. println () displays the
result and then throws the cursor to the next line. .
...et us take the following statement:
:his will display the output as shown below:
Sum 0 two numBers 35
_ ow, suppose we want to display the result in two lines using only one println () method, what is
-" e way? For this purpose, we can use a code n inside the string, as shown here:
:his will display the result like this:
m f wo u r
:iris means n is throwing the cursor into the next line at that place. This is called backslash code
escape sequence. Table 3.1 lists the noteworthy backslash codes with their meanings.
"able 3.1
Backslash code Meaning
Next line
Backspace
45. Backslash code
~ Chapter 3
For example, observe the following statements:
The above statements display the output as:
Program 3: To understand the effect of print () and println () methods and the backslash codes.
Output:
By now, you must be finding Java to be very friendly.
Conclusion
In this chapter, we have learned about providing comments in the java program. We have also come
across with API documents. While moving towards the end of the chapter we have come across with
the creating a program in Java.
46. AMING
NO DATA
CHAPTER
PES
ONVENTIONS
I
n the previous chapter, we understood Java by writing a couple of programs. In those programs,
you might have observed that sometimes we have used small letters and sometimes capital
letters. For example, we have written the class System starting with a capital letter. You cannot
·te this class name as system or SYSTEM. Since Java is a case sensitive programmingJanguage, it
=gnizes capital and small letters as different. So the programmer should take care of upper and
er case whilt;. writing a program in Java. But how to know where to use which case-upper or
er? For this purpose, certain conventions (rules) are followed by JavaSoft people while naming
e variables, classes, methods, etc. These naming conventions should be followed by every
;rrograrrimer in his programs for maintaining uniformity and also for clarity of distinction betWeen
.. erent elements of a program. These rules also reduce the possibility of any spelling mistakes
~e writing the nanies of variables, classes, etc. in the programs. For example, a Java program will
::ot compile, if main () method is written as:
I
e problem in the preceding statement is using capital P for public and capital Mfor main (). Such
=:mrs can be eliminated if we follow the naming conventions.
ing Conventions in Java
_mning conventions specify the rules'to be followed by a Java programmer while writing the names
packages, classes, methods, etc. Now, let us see some of the major naming conventions to be
- owed in Java.
A package represents a sub directory that contains a group of classes and interfaces. Names of
packages in Java are written in small letters as:
.e
h
A class is a model for creating objects. A class specifies the properties and actions of objects. An
interface is also similar to a class. Each word of class names and interface names start with a
capital letter as:
47. ~ChaPter4
o A class and an interface contain methods and variables. The first word of a method name is in
small letters; then from second word onwards, each new word starts with a capital letter as
shown here:
o The naming convention for variables names is same as that for methods as given here:
1!",,---,,-'II'o;_. _
Now, the question that is commonly asked is that if same rule is applied for both variables and
methods, how can we distinguish between them? The answer is that since a method's name ends with·
a pair of simple braces 0, it can be distingUished easily from a variable whose name will not have any
braces.
o Constants represent fixed values that cannot be altered. For example, PI is a constant whose
value is 22/7 or 3 . 14159, which is fixed. Such constants should be written by using all capital
letters as shown here:
Here, BOLD is a constant in Font class. This is the way most of the inbuilt constants in Java are
referenced. <.
o All keywords should be written by using all small letters as follows:.
Data Types in Java
We know we need variables to store the data. Internally, a vanable represents a memory locatiOl
which holds data. When we want to use a variable-in a program, we should first declare it as:
Here, we are declaring that x is a variable, which can store int (integer) type data. This means in
is representing the nature of data to be stored into x. int is also called a data type. For exampl(
x can store an integer number like 125 as:
48. I
lin
as
I
ose
ital
are
ion
Naming Conventions and Data Types I 2
, x is a variable and = represents that the value 125 is stored into x. This value 125 stored into
also called literal. There are various data types and literals defined in Java, which we will be
ssing in this chapter.
er Data Types
data types represent integer numbers, Le. numbers without any fractional parts or decimal
IS. For example, 125, -225678, 0, 1022, etc. come under this category. Integer data types are
sub divided into byte, short, int, and long types. Table 4.1 lists the data types.
4.1
,
type Memory size Minimum and Maximum values
'" .. :>t.
:!-::e 1 by.t.e -128 to +127 ><ll m
-- yt 2 bytes -32768 to +32767
- 'iii
4 byte~ if. ~i;jls .. ."l:. ,~ @ii ':';
-- -2'14748364~tq;.Ji~14~48;3M7",~ ".I!ilo'!'
- '. 'R...• 01'
:.::, 9 8 bytes -9223372036854775808 to
+9223372036854775807
us try to understand this through an example given here:
teo~
~ preceding statement, we are declaring byte data type for the variable rno and the value 10,
is stored into rno. byte represents any value between -128 to +127.
_:-; x=150L;
-~, _50 is stored into x, which is declared as long type. Notice the L at the end of the statement.
," L is not there, then JVM allots only 2 bytes of memory to x as against the usual 8 bytes
ory that should be allotted to a long type. The reason for this is that 2 bytes are sufficient to
the value 150. But if we attach I or L at the end of the value as shown in the preceding
Ie, then JVM will consider it as a long value and will allot-8 bytes to it.
Data Types
data types are useful to represent numbers with decimal point. For example, 3.14, 0.0012,
-_::L 11, etc. are called floating point numbers. These are again classified as fl.oat (single
. 'on floating point number) and double (double precision floating point number). The
nce exists essentially in the number of digits, they can represent accurately after the decimal
~ This accuracy is also called precision. Table 4.2 depicts the size of' float and double.
int
:lIe,
=:mble 8 bytes -1.8e308 to -4.ge-324 for negative values
and 4.ge-324 to 1.8e308 for positive
values
49. .22.JChapter 4
What is the difference between float and double?
Floa t can represent up to 7 digits accurately after decimal point, whereas daubl e can represent up
to 15 digits accurately after decimal point.
Let us now look at an example given here:
float i 3.'D12}i';
Here, the variable pi is containing the value 3 .142. I~ F is not written at the end, then JVM ~ould
have allotted 8 bytes assuming the value to be double. The reason for this is that in float and
double data types, the default is taken as double. By attaching F or f, we can ask the JVM to
consider it as a float value and allot only 4 bytes.
double distance=1.98e8;
Here,e or E represents X 10 to the power. Hence, 1. 98e8 means 1. 98X108. This is also called
scientific notation of re~resentingnumbers.
Character Data Type
This data type represents a single character like a, P, &, *, etc. Table 4.3 shows char data type
details.
Table 4.3
Data type Memory size Minimum and Maximum values
Char 'II .." 2 bytes ;i't oto 65535 ."F ~ .,"1
Here is an example of character data type:
cfla:f en ~X"
Here, we are storing the single character 'x' into the variable ch. Here, 'X' is also called characte7
literal. WHenever character literals are written, they should be enclosed inside the single quotes.
By observing the minimum and maximum values in the table earlier, we shall get a doubt regarding
why the range is expressed in integer numbers (0 to 65535). We know that all the characters on the
keyboard are translated into integer values called ASCII (American Standard Code for Information
Interchange), which is a standard maintained by every keyboard manufacturer. The processOI
recognizes the character uniquely from its ASCII value. Hence, let us understand the' range
mentioned in the table is nothing but the ASCII value range only.
The ASCII value range, from 0 to 65535, given in the table can uniquely represent a total of 6553E
characters. This means a total of 65536 distinct characters can be recognized by Java. But we nevel
use these many characters since our keyboard contains English alphabets and some othe]
characters whose total does not exceed 256. This means 1 byte is s'Ufficient to represent all th<
available characters of the keyboard. Then why 2" bytes are used to represent the char data type ir
Java?
JavaSoft people wanted to provide a facility to include characters not only from English but alS(
from all other human languages to be used in Java programs. This will enable the programmers t(
write and execute a Java program in any language, which becomes an advantage on Internet. Thi1
system is also called Unicode system. Unicode uses 2 bytes so that any character from any languagl
can be encoded successfully.
50. llid
nd
to
led
pe
er
~e
6
~r
~r
:e
n
o
o
s
e
Naming Conventions and Data Types l1!..
What is a Unicode system?
Unicode system is an encoding standard that provides a unique number for every character, no matter
what the platform, program, or language is. Unicode uses 2 bytes to represent a single character.
String Data Types
A String represents a group of characters, like New Delhi, AP123, etc. The simplest way to create a
String is by storing a group of characters into a String type variable as:
ri tr
Now, the String type variable str contains "New Delhi". Note that any string written directly in a
program should be enclosed by using double quotes.
There is a class with the name String in Java, where several methods are provided to perform
different operations on strings. Any string is considered as an object of String class. But in
CjC++, a string is considered as a character array containing some characters where the last
character would be 0. This is not valid in Java, since in Java, we got strings and character arrays
both separately. .
Now the question arises that if String is a cla~s, why are we taking it as a data type? The answer
is that every class is a data type and is also called user-defined data type.
Boolean Data Types
Boolean data types represent any of the two values-true or false. JVM uses I bit to represent a
boolean value internally, for example:
00 ean S onse r
"
As shown earlier, we should not enclose the boolean value true (or false) in any quotation mal'ks."
in CjC++, 0 represents false and any other number represents true. This is not valid in Java.
"terals
A literal represents a value that is stored into a variable directly in the program. See the following
examples:
In the preceding statements, the right hand side values are called literals because these values are
being stored into the variables shown at the left hand side. As the data type of the variable changes,
the type of the literal also changes. So we have different types of literals. These are as follows:
o Integer literals
o Float literals
o Character literals
o String literals
o Boolean literals
Read on to get familiar with them.
51. ~ Chapter 4
Integer Literals
Integer literaIs represent the fIxed integer values like 100, -55, 123450, etc. All these numbers
belong to decimal system, which uses 10 digits (from 0 to 9) to represent any number. Suppose, we
want to write an integer in octal number system (octal number system uses 8 digits, from 0 to 7),
then· we should prefIx 0 before the number.· To represent hexadecimal number (hexadecimal
number system uses 16 digits from 0 to 9 and from A to F), we should prefIx Ox before the value.
Float Literals
Float literals represent fractional numbers. These are the numbers with decimal points like 2.0, -
0.005, 3.14, 6.1e-22, etc. which should be used with float or double type variables. While
writing these literals, we can use E or e for scientifIc notation, F or f for float literal, and D or d for
double literal (this is the default and generally omitted).
If. same value as dl, but in scientific notation
-~
Character Literals
Character literals indicate the following:
. 0 General characters, like A, b, 9, etc.
o Special characters, like ?, @, etc.
o Unicode characters, like u0042 (this represents a in ISO Latin 1 character set).
o Escape sequence (backslash codes) like n, b, etc.
Character literals should be enclosed in single quotation marks. The preceding unicode characten
and escape sequence can also be represented as strings.
String Literals
String literals repres'ent objects of String class. For example, Hello, Anil Kumar, AP1201, etc. wil
come under string literals, which can be directly stored into a String object.
Boolean Literals
Boolean literals represent only two values-true and false, It means we can store either true or falSI
into a boolean type vanable.
Conclusion
By following naming conventions, a programmer can avoid a lot of mistakes in writing the names 0
packages, classes, methods, variables, etc. This will improve readability as well as understandabili~
of a program. So maintaining naming conventions is a good programming habit.
A program generally acts on data, processes it, and provides the results. So data is very importaI1
element of a program. In this chapter, we also discussed different data types, in terms of type (
data received, stored, or used in a program.
52. ~rs
Ne
7),
lal
ile
or
rs
CHAPTER
OPERATORS IN.
JAVA
A
programmer generally wants to do some operations in a program. For example, in a program,
you want to perform addition of two numbers. How can you do it? Just by using + symbol, we
can add the numbers. This means + is a symbol that performs an operation, i.e. addition.
Such symbols are called operators and programming becomes easy because of them. Let us discuss
about operators in this chapter and how to use them with examples.
Operators
An operator is a symbol that performs an operation. An operator acts on some variables, caped
operands toget the desired result, as shown in Figure 5.1.
rOperator
ill
I
a + b
;e
)f
y
It
)f
Operand Operand
Figure 5.' Operator and operands
If an operator acts on a single variable, it is called unary operator; if it acts on two variables, it is
called binary operator; and if it acts on three variables, then it is called ternary operator. This is one
type of classification. ·Let us now examine various types of operators in detail.
Arithmetic Operators
These operators are used to perform fundamental arithmetic operations like addition, subtraction,
etc. There are 5 arithmetic operators in Java. Since these operators act on two operands at a time,
these are called binary operators. Table 5.1 displays the functioning of these operators. Here, we are
assuming the value of a as 13 and b as 5.
53. 18
8
Result
a-b
Subtraction
operator
Meaning Example
.addition, operator a + h
*
Operator
+
Table 5.1
In this code snippet, the unary minus (-) operator is used on variable x to negate its value. The
value of x is 5 in the beginning. It became -5 when unary minus is applied on it.
Addition operator (+) is also 1,lsed to join two strings, as shown in the following code snippet:
o String 51= "wel";
o String 52= "come";
o String 53= 51+52; Ilhere, '+' ~5 joining 51 and 52.
Now, we get welcome in s3. In this case, + is called String concatenation operator.
Increment Operator (++)
This operator increases the value of a variable by 1, for example:
Unary Operators
As the name indicates, unary operators act on only one operand. There are 3 kinds of unary
operators:
o -Unary minus operator ( - )
o Increment operator ( ++ )
o Decrement operator ( -- )
Unary Minus Operator (-)
This operator is used to negate a given value. Negation means converting a negative value into
positive and vice versa, for example:
2!..JChapter 5
54. Operators in Java ~
Here, the value of the variable x is incremented by 1 when ++ operator is used before or after it..
Both are valid expressions in Java. Let us take an dmmple to understand it better:
x= :i{+ •
In this statement, if x is 3, then x+l value will be 4. This value is stored again in the left hand side
variable x. So, the value of x now becomes 4. The same thing is done by ++ operator also.
Writing ++ before a variable is called pre incrementation and writing ++ after a variable is called post
incrementation. In p~e incrementation; incrementation" is done first and any other operation is done
next. In post incrementation, all the other operations are done first and incrementation is done only
at the end. To understand the difference between pre and post incremenations, let us take a couple
of examples.
Example 1: Finding the difference between pre- and post- increment ofx
Output:
Output:
In this example, see the left-hand side and right-hand side statements. The second statement on
the left uses pre-incrementation, while the second statement on the right uses post-incrementai:ion.
At the left hand side:
o System. out. println (x); I I displays the value of x as 1
o System. out .println (++x); I I first increments the value of x and then displays it as 2
o System.out.println (x); I I displays the value of x, which is already incremented, Le. 2
At the right hand side:
o System.out.println(x); II displays the value of x, i.e. 1
o Sys"tem. out. println (x++) ; / / first displays the value of x as 1 and then increments it.
o System. out.println (x); I I displays the incremented value of x, i. e. 2
Example 2: Finding the difference between pre- and post- increment of a and b
56. “I think that will suffice.”
“And this?” asked the General.
They read each other’s letters, expressed satisfaction, and
then Waldron heard a slight click, the opening and shutting
of a wallet.
Some notes were counted out—to the sum of one thousand
pounds. They rustled, and the listener knew that they were
English notes so that they could not be traced so easily as
those which the unscrupulous German contractor might
withdraw from his own bank in Berlin.
His Excellency counted them, declared the sum to be
correct, and then, after a further brief conversation the
German left, His Excellency remaining so as not to be seen
in his company.
The deal was concluded. Though interesting to Hubert, it
however carried him no farther in his inquiry. It proved of
course that General Cataldi, Minister of War, was corrupt
and unscrupulous, yet were not the majority of the men
who formed the Cabinet equally ready to accept bribes?
He stood in that artistically furnished bedroom full of
chagrin. He had practically had his journey there for
nothing, and had lost valuable time by his absence from
Rome.
Therefore he slipped out along the corridor, and two hours
later was on his way to Culoz, to catch the train-de-luxe
from Paris to Rome.
During that night as the express roared through the
mountains he lay in his narrow sleeping-berth watching the
green-shaded lamp above, and full of conflicting thoughts.
57. The attempt upon his life showed plainly that the thief was
aware of the strenuous efforts he was making to fathom the
mystery. But who was the thief! Was it this unscrupulous,
much-decorated General who took secret commission of
contractors, the man who allowed the army to be fed on
discarded tin food, and go shod in cheap German boots
which wore in holes on the first march, in order to enrich
himself?
Long and deeply he thought, and still the conviction clung
to him that the person mainly responsible for the sale of the
plans to Austria was His Excellency himself.
Thoughts of Her Highness rose within him. He sighed. Yes,
he loved her with all his body and soul. Yet that barrier of
birth could never be bridged. After all, they could be only
good friends, therefore he had never dared to declare his
love. She was a Princess of the blood-royal and might marry
a reigning Sovereign, but he was a mere diplomat, a
secretary of Embassy, a man whom the Court regarded as
the necessary adjunct of a practically defunct institution,
for, however much one may cling in these days to the old
usages and customs, yet the glaring fact must be faced that
kings themselves are the ambassadors, and royal visits
from one Court to another tend to cement more
international friendships than ten years of that narrow little
squabbling and intriguing world which exists in every capital
under the name of the corps diplomatique.
The public have been long enough gulled by the false tinsel
and glamour of the diplomatic world, and in these ultra-
modern days they see the inutility of it all. Often an obscure
Vice-Consul in an obscure port is of greater use to the
nation than the whole of the red-taped, ceremonious
Embassy, with its splendid house, its dinners and dances, its
58. flunkeys and furbelows, and its flabby, do-nothing policy
directed from Downing Street.
Hubert Waldron, born and bred in the diplomatic
atmosphere and nurtured upon the squabbles and petty
jealousies of international politics, could not close his eyes
to the fact that the public of Europe were being gulled daily
by the Press, and that at an hour when all would seem
quietest and most peaceful, the great and terrible European
war would suddenly break out.
Though at the Embassies you will be told that the peace of
Europe is quite assured nowadays, and though your penny
papers with their “advertised actual sales” will print
reassuring leaders for the sake of the particular party who
supports them, yet there is not a diplomat in all Europe who
does not, in his own heart, fear a violent and bloody
explosion and that brought about by the Dual Monarchy.
Though this view may appear pessimistic, it is nevertheless
a hard fact that the Powers of the Triple Alliance have not
signed any agreements relating to the Mediterranean, and
more than one European throne is to-day tottering to its
fall, nay, more than one nation may, at any moment, be
erased from the map.
But the whole object of diplomacy is to reassure, not to
alarm. The days when the greatest international tension
exists are those when the outlook seems the most serene
and unruffled.
In our present century war breaks out; it is not declared.
And war in Europe may break out at any moment, even
though much is said of the solidity of the Triple Alliance.
On arrival at the great echoing station at Rome, Hubert
descended, tired and fagged, and took a taxi home.
59. It was then nine o’clock in the morning, and Peters,
surprised to see him, handed him a letter which had been
left on the previous night. On opening it he found it was
from Ghelardi, dated from the Bureau of Secret Police, and
asking when he could see him.
At this request he was somewhat surprised in view of what
had already passed between them, nevertheless he spoke
to the functionary on the telephone at his private house and
at eleven o’clock entered his private room at the Ministry.
Their greeting was the reverse of cordial. Indeed Hubert
had at first hesitated to meet him at all, yet he thought that
the object of the interview might concern the unfortunate
incident in the Palace; hence he went, determined to still
show a bold front.
“I regret, Signor Waldron, to have disturbed you,” the crafty
old man said when his visitor was seated. “But it has been
reported to me that the other night you were attacked by
two individuals, and that you narrowly escaped with your
life—that you shot and wounded both your assailants.”
The policeman had, notwithstanding the bribe, evidently
made a report in order to show his watchfulness to his
superior. Hubert frowned in annoyance.
“Oh, it was nothing at all,” he declared, laughing. “I had
quite forgotten all about it. They were merely footpads, I
suppose. No further notice need be taken of them.”
“Ah! but they are very dangerous characters, and well-
known in Rome,” he said. Then, looking straight at him the
old man with the bristly hair said in a curious, half-
suspicious voice: “You appear, Signor Waldron, to have
some rather bitter enemies in Rome—eh?”
60. “I was not aware of it,” answered the diplomat. “If I have it
does not trouble me in the least. I am perfectly able to
defend myself.”
“They are secret enemies, it seems,” Ghelardi said slowly,
looking at his visitor meaningly.
Hubert did not reply for a few moments. At last he said:
“And they include yourself, Signor Commendatore.”
The cunning old fellow smiled.
“Ah, you are referring, I suppose, to that incident of the
other night. Well, I think we may surely let that pass. We all
of us have our hours of irresponsibility,” and he slowly
twisted the diamond ring around his little finger, laughing
lightly.
“Thank you. I have no desire for your covert sneers, Signor
Commendatore,” he said angrily, rising. “As I have told you
—you are my secret enemy, and I shall treat you as such.”
“It is rather a pity that you do so.”
“A pity—why?”
“For the sake of Her Royal Highness.”
“Her name need not enter into our discussion,” Hubert said
hotly, his hand upon the door ready to leave. “I do not see
your object in troubling me to come here, merely to tell me
of the attack made upon me by two criminals which the
police should already have under lock and key. It is not
much to the credit of the department that the streets of
Rome are unsafe at night.”
61. “Ah! my dear signore, you are a little too impatient, I fear,”
replied the chief of spies, quite undisturbed. “I was about to
prove to you my friendliness.”
“I desire none of your friendship,” declared the Englishman
hotly. “And I tell you that I will not have you mention the
name of the Princess Luisa in connection with my own.”
“Friendships formed by Her Royal Highness are frequently
unfortunate.”
“Are they!” exclaimed Waldron, his eyes aflame. “If you
were younger, Signor Commendatore, I would knock you
down for your gratuitous insult. As it is, I shall not forget it.
Buon giorno!”
And he left the room, slamming the door after him.
62. Chapter Twenty Six.
Gathering Clouds.
Dust had once more been thrown into the eyes of Europe.
Weeks had gone by, spring came, and the Roman season
was on the wane. The month of May—the Primavera—with
all its blossoms and ceremonies had opened.
As far as the world knew not a cloud obscured the political
horizon. In the chancelleries of Europe there were no
sinister whispers, in the Embassies they danced and dined,
the Archduke Francis Ferdinand had made a placid speech
from the Throne, and Count Berchtold had declared the
foreign policy of Austria-Hungary unchanged, and further,
that the changes in the Near East had created new interests
common to the Dual Monarchy and to Italy, and that their
policy was leading them together along the path of co-
operation, and also that their attitude towards each other
tended to preserve the peace of Europe and to assure
freedom and equilibrium in the Adriatic.
It is always so. The calm is followed by the storm. At Vienna
they were secretly completing their plans for a sudden coup
against their neighbours, yet the true facts were known only
in our own Intelligence Department in Whitehall, and the
information had in turn been sent in a cipher dispatch to the
Embassy in Rome.
It was this dispatch which the Ambassador, receiving it one
evening from the hand of the King’s messenger, who had
brought it in hot haste direct from Downing Street, passed
over to Hubert to decipher.
63. The information was highly alarming, to say the least.
The British secret agent—a responsible Austrian official in
the Ministry of War—reported that the great army massed
in the Tyrol for manoeuvres was being kept there. A secret
order had been issued to the Eighth, Tenth, and Thirteenth
Army Corps to concentrate from the Adriatic across to the
Danube, and at the same time the Ministry of Marine had
issued orders to the navy recalling the Adriatic fleet which
had been manoeuvring between Cattaro and Ragusa up to
Trieste.
The wireless stations at Sebenico and Pola had been taken
over by the navy, and operators placed there sent expressly
from the Ministry of Marine in Vienna.
All tended to a secret attack—to war—a war in Europe with
dreadnoughts, high explosives, aeroplanes, seaplanes,
submarines, and wireless conditions never before imagined
either in the wildest dreams of novelists or the ever-active
brains of place-seeking party politicians.
Preparations were slowly but surely being made in Vienna,
and the blow would surely soon be struck.
For an hour Waldron remained in consultation with his Chief.
Then, regardless of Downing Street regulations, and only
hoping to prevent the conflagration, he went back to his
rooms on the ground floor of the Embassy, scribbled a hasty
copy of the secret information, and with it walked direct to
the Quirinale.
Events would, he saw, very soon be moving fast.
About six o’clock he entered the private room of the
Minister of the Royal Household, that cosy, well-
remembered apartment in which Ghelardi had discovered
64. him on his knees beside Her Royal Highness. The Minister
himself was not in, but his secretary went immediately
along to the private apartments and asked His Majesty for
audience on Waldron’s behalf.
The request was immediately granted, and he was at once
shown up the long corridor, past the sentries guarding the
door leading to the royal apartments, and on into the King’s
private cabinet, where His Majesty, plainly dressed in dark
blue serge—for he discarded uniform whenever he could—
stood eagerly awaiting him.
“Well, Waldron?” he exclaimed, stretching out his hand
warmly, “I’ve been expecting you for days. Anything to
report—eh?”
For answer his visitor drew out the rough memorandum
from his pocket, and after brief explanation regarding its
source, proceeded to read it.
His Majesty’s handsome, clear-cut face fell. He grew pale,
but remained silent till the end.
Then with his hands behind his back, he strode slowly
across the soft carpet to the heavily curtained window and
back again.
Twice he paced the room in silence.
“Strange, Waldron!” he said, pausing and standing before
the diplomat. “Very strange that you get this information,
yet Ghelardi is in ignorance of what is happening?”
“He may not deem it wise to report to Your Majesty,” Hubert
suggested.
65. “Wise!” he echoed. “In the interests of the country’s safety
it is his first duty! He reports to me sufficient regarding
trivial matters—the irresponsible vagaries of my niece, Lola,
and things of that sort. Yet he knows nothing of what is in
progress across the frontier,” the King cried in anger. “Again,
he has discovered nothing regarding the theft of those
plans. If we could but find out the truth we might easily
face our friends in Vienna, and prevent this attack.
Diplomacy could avert the explosion even now, if we only
knew the identity of the spy.”
“I have made every inquiry, Your Majesty, but I have, alas!
failed.”
“I can only suppose that the conspiracy must have been
formed in our own camp,” was the King’s hard remark, and
his visitor knew what was passing in His Majesty’s mind.
Though Sovereign, he was not blind to the corruptness of
his Ministry. Yet, as monarch, his hands were, alas! tied, or
he would have long ago cleaned out the Augean stable.
For an hour he remained with the King, discussing the
seriousness of the international situation.
“Ah, Waldron,” sighed His Majesty, as he stood before the
fire, erect, almost statuesque, his face pale and hard-set,
“my people little know how much responsibility rests upon
me, or how heavy is the burden of my duties towards my
nation. During these past weeks I have slept but little, and
many a night have I passed in here alone, trying to devise
some scheme whereby to defeat this secret plot against us.
I have learnt how untiring have been your efforts to unravel
the mystery of the theft, and I also know that a dastardly
attempt has been made upon your life. I know how well and
faithfully you have served me, even though I am not your
66. own King. I can only thank you most deeply. Your father
was my father’s friend, and you are my friend.”
“And I trust, even though I have failed to accomplish
successfully the mission entrusted to me, that Your Majesty
will still allow me to be your most faithful and devoted
servant,” he replied.
“I know you have done your very best, Waldron, and I
highly appreciate it,” was the Sovereign’s earnest reply.
“Ah!” he sighed, “if we could only discover the truth
concerning those plans. Then, by prompt action, we might
save the situation. But alas! it is still a mystery.”
“Has Your Majesty formed any theory?” Hubert asked, after
a few moments’ hesitation.
“Only one—that Cataldi may have sought profit to himself.”
Hubert Waldron nodded, but no word escaped him.
“But how can we prove it—how can we prove it?” the King
said.
The Englishman shrugged his shoulders. He recollected that
sum which had come to the Minister from a mysterious
source a few days after the theft. But of that he made no
mention to the King. It was, after all, no proof. Only a
suspicion.
Therefore, after yet another half an hour, he made his
adieu, bowed as he backed out of the room, and then
walked home full of gravest reflections.
That same evening he had promised to see off at the station
by the Milan express two English ladies who had been
guests of Lady Cathcart at the Embassy, and this he did,
67. driving in the car with them, for the Ambassador himself
had to be present at an official dinner given by the Minister
of Foreign Affairs.
He had bidden the two ladies farewell and the train had
moved out of the station upon its long, northward journey
when, just as he was about to enter the Ambassador’s car,
standing in the piazza, he caught sight of a familiar face—
that of Henri Pujalet.
“Hallo?” he cried. “Why—you in Rome?”
“Yes. I arrived only this afternoon,” responded Her
Highness’s lover, halting and putting out his hand. He was
well-dressed, though there seemed to have been some
slight attempt to disguise his features. “Mademoiselle does
not know I am here,” he added, “so if you see her, please
do not mention this meeting. I shall not see her until the
day after to-morrow—when we have an appointment to
meet.”
“Very well,” laughed Waldron, though, truth to tell, he was
consumed by jealousy. Then in reply to a question he told
Waldron that he was staying at the Hôtel de Russie, out by
the Porta del Popolo, to which place Hubert gave him a lift,
afterwards bidding him good evening and driving back to
the Embassy.
What further indiscretion, he wondered, was Lola about to
commit.
His heart was bursting with unspoken love. Night after night
he lay and thought of her in wonder. Though she was in
ignorance of it, she was his all-in-all. Since he had been in
Rome he had danced attendance upon many women, as it
was his duty as diplomat to do; he had laughed and flirted,
and danced and gossiped, and kissed many a woman’s
68. hand, but in his heart he held them all in supreme
indifference. His eyes and heart were only gladdened when
Her Royal Highness, the scandalously skittish and
unconventional, chanced to be present. This was fortunately
often the case, and frequently he found himself in cosy
corners or in conservatories with her as she whispered
merrily behind her fan.
This Frenchman, Pujalet, still knew her by the name she
had used in her incognita in Egypt—Lola Duprez. Where, he
wondered, would they hold their secret meeting?
He bit his lip in mad jealousy as there arose before his eyes
a vision of that far-off oasis of dark palms, the steely sky
with the bright stars shining, and of two figures clasped
breast to breast.
Peters, as he entered his room, placed the evening paper
before him.
Taking it up mechanically he saw a heading: “Boots for the
Army,” and read as follows:
“It has just transpired, telegraphs our Berlin correspondent,
that the tender for the supply of all boots to the Italian
Army for the next three years has been secured by the well-
known firm of Steinberg and Klein, of Friedenau, near
Berlin. It will be remembered that last year they also
secured the contract for supplying tinned meats and leather
accoutrements for the expedition to Tripoli. The contract
was signed by His Excellency General Cataldi some weeks
ago, but has not been made public until to-day. The prices
quoted by the English and French firms were lower, but His
Excellency, after various tests, decided that the quality of
the goods offered by the German firm was distinctly better.”
69. Waldron, with bitter words upon his lips, cast the journal
from him viciously.
A letter he opened was from Beatriz, dated from Moscow.
She was having a brilliant success at the Opera there, she
said. When could they meet?
He tore it into small fragments and cast it into the
wastepaper-basket. All thought of the handsome dancer
who had used him merely as a stepping-stone to fame had
now passed from him. He only remembered her with a
feeling of poignant bitterness.
Upon the mantelshelf a large, imposing card of invitation
caught his eye. Peters sorted them out, and day by day
placed them in that conspicuous spot so that he might be
reminded of his engagements.
The presence of the Honourable Hubert Waldron, M.V.O.,
was requested that night by His Excellency General Cataldi
at an official reception at the Ministry of War.
He smiled. Cataldi, the unscrupulous, corrupt member of
the Cabinet, who was feathering his nest so comfortably,
had, perhaps, hired those two assassins to take his life. And
he was invited to his reception. The situation was not
without its grim humour.
Yes, he would go. He would watch further this man who was
providing the brave, patriotic sons of Italy with uneatable
beef and unwearable boots, in order that the Countess Cioni
should be provided with funds.
He rung up Pucci on the telephone, telling him where he
was going.
“You have entrée to the Ministry, Pucci, have you not?”
70. He heard the detective reply in the affirmative.
“I may want you. So go there.”
“I cannot go as guest, signore,” came the reply. “I will
arrange, if you wish, to be on duty as a servant.”
“Good. And be as near His Excellency’s private room as
possible. I will meet you there at midnight and give you
instructions. The reception is at eleven—after the banquet
at the Ministry of Foreign Affairs. His Majesty will, no doubt,
be there, and other members of the Royal Family.”
“Benissimo, signore, I shall be in the corridor at midnight,
acting as waiter.”
Then Hubert rang off, and passing into his bedroom, got
into uniform with the aid of the queer, under-sized, hunch-
backed little man who, for so many years, had been his
faithful servant, and whose father before him had been
valet to Hubert’s father.
At eleven o’clock Waldron stood before the long cheval glass
arranging his tight uniform collar. Then he placed his
decorations exactly at the right angle, settled the hang of
his pearl-handled diplomatic sword, and took his white
gloves from Peters’ hand.
His face was dark and clouded. On the one hand he had no
desire to meet the corrupt Minister who was bringing
disaster and defeat upon his country, while on the other he
knew that his Chief expected him to turn up there and be
on show, as is the duty of those attached to the Embassies.
His Majesty, too, would be there. What, in face of those
words of his concerning His Excellency, could he think?
Truly, the head upon which lies a crown must, indeed, be
71. very weary. How little does the general public know of that
narrow, glittering, fevered world which, in every capital,
surrounds a throne—that world where place-seekers
intrigue, where money brings power, where morality is so
often scoffed at as antiquated and out-of-date, and where
the true, honest love of man and woman is forbidden
because of rank and blood.
How little do the readers of our daily Press ever dream of
the many bitter romances of love that are to-day being
enacted beneath the shadows of the thrones of Europe, for
the social columns tell nothing save what those mentioned
desire that the world shall know, while the scandals which
find their way into print are only the sordid ones. How little,
indeed, do the public dream of the hearts which lie broken
near the thrones of Europe, of the mad passion, of the steel
fetters of royalty, or of the true, honest affection of those
beyond the pale. It is only when there is a morganatic
marriage, or when a Prince or Princess of the blood-royal
renounces their royal rights that that public pause for a
second to reflect. And then, alas! they too often put it down
to mental derangement.
But the public are in ignorance of the world behind the walls
of the royal palace, the pomp, the splendour, the
officialdom, and, alas! the constant intrigue.
Only those in the immediate entourage of the Sovereign
and the diplomat know the truth. And, after all, it is that
little fevered world of its own which rules the greater world
outside. And so the Powers of Europe struggle on, one
against the other, for wealth and supremacy.
At eleven o’clock Hubert Waldron’s taxi drove into the great
courtyard of the Ministry of War, that huge, handsome
72. building at the other end of the Via Venti Settembre to
where the British Embassy was situated.
As he descended, the sentries, noticing his uniform,
saluted, and returning their salute, he entered the great
vestibule, threw his cloak to one of the gorgeously dressed
flunkeys, and with his cocked hat tucked beneath his arm
made his way up the great red-carpeted staircase to the
first floor where the reception was being held.
As he went up he could hear the tuneful strains of dance
music being played above by one of the military bands,
bright military uniforms were everywhere, the place, usually
so dark and sombre, had been adorned by flowers and
palms, and was now brilliantly lit by festoons of coloured
electric lamps.
Italy, par excellence the country of the British tourist, has
its charm even in its officialdom.
At the top of the staircase stood the Minister himself, His
Excellency General Cataldi, resplendent in his brilliant, gold-
laced uniform, glittering with decorations, saluting as he
received his guests.
Hubert smiled bitterly within himself. He recollected that
last occasion when, after travelling many miles, he had seen
him driving to the Univers at Tours, and remembered the
subsequent conversation when he had accepted the bribe to
place brown-paper boots upon the feet of the Italian Army.
He saw that His Excellency wished to behave with great
cordiality as he passed. But he merely drew himself up,
saluted, and passed on along the corridor.
A second later he found himself face to face with the
detective, Pucci, who, in plain evening-clothes as a waiter,
73. came up and bowed, and then, with darkly knit brows,
motioned that he desired most anxiously to speak with him.
74. Chapter Twenty Seven.
Reveals an Intrigue.
Hubert Waldron, a smart figure in his diplomatic uniform,
strolled along the corridor, followed at a respectable
distance by the neatly-dressed waiter until, at a convenient
point, the diplomat halted at the junction of two corridors,
as though in doubt. Pucci was at his side in an instant.
“I learnt only half an hour ago, signore, that there is a plot
against you!” he said. “Signor Ghelardi is your enemy. You
were attacked by the two assassins whom he bribed, but
the conspiracy failed. Be careful. Exercise the greatest
caution, signore—I beg of you.”
“This is not news to me, Pucci,” replied the diplomat,
pretending to button his white glove. “I am keeping
observation upon His Excellency the Minister, so be near me
to-night, and keep a sharp look-out. It is in the personal
interests of His Majesty. Is he here?”
“Si, signore. He arrived a quarter of an hour ago. I saluted
him and he recognised me—even in this garb. His Majesty
never forgets the faces of those whose duty it is to be his
personal guardians.”
“All right, Pucci. Be near in case I require you—I trust you.”
“Bene, signore. I shall be there if you want me, never fear,”
was the reply; of the faithful police agent.
And then the British diplomat strolled up the corridor,
leaving the waiter to bustle along in the opposite direction.
75. Pucci was full of resource. He had been attracted to Hubert
Waldron because he had seen that he was a fine, strong
character, a man of high ideals, of dogged courage, and of
British bull-dog perseverance. Waldron, of the stock that
had made the Empire what it is, commanded respect. He
was a man of action and of honour. Though clever, far-
seeing, and with a keen scent for mystery, yet he was
honest, upright, and once he made a friend that friend was
his for always. His only fault was that he was too generous
towards his friends, or to those who were in want. He would
give his last half-sovereign to anyone who told him a tale of
poverty.
In this connection he had often been imposed upon. He
knew it, but always declared that, after all, he might have
done one really charitable action, though others who had
told their stories were impostors.
Like most men possessed of keen wits, he had been very
badly imposed upon at times. Yet often and often, by his
sympathetic feelings, he had spent the greater part of his
pay in the relief of real cases of distress.
The Waldrons had ever been charitable, for they were
always English gentlemen in the truest sense of the word.
In the great Council Chamber with the huge crystal
chandeliers, where the walls were hung with the ancient
tapestries brought from the Palazzo Communale at Siena—
the chamber in which the sittings of the Council of Defence
were held, and where the lost plans had been discussed—
the King stood, the brilliant, imposing centre of His
Excellency’s guests.
The assembly was a somewhat mixed one, though mainly
military, and uniforms of every description were there, while
76. every second man wore decorations of one kind or another.
The ladies were mostly wives of high officers of State, of
prefects and of military men. Yet there was also the usual
sprinkling of wives and daughters of deputies and senators.
Monte Citorio is always much in evidence in every public
function in Italy.
Twice each year was the great imposing Ministry of War—or
at least the public portion of it—thronged with officials from
every corner of the kingdom, for His Excellency, General
Cataldi, sent invitations broadcast, as he found it a cheap
way of returning the hospitality daily offered to him—
especially as the entertainment was paid for out of the
public purse.
Waldron, on entering the Council Chamber, made his bow
before His Majesty, and then, after nodding acquaintance
with many persons he knew, crossed to where the Princess
Luisa was standing in conversation with a stout old General,
the commandant on the Alpine frontier. He bowed over her
hand, and then all three began to chatter, while a few
moments later the secretary, Lambarini, approached and
found the little group.
Presently Lola, who was wearing a beautiful gown of pale
carnation pink, and who looked inexpressibly sweet as she
smiled, bent and whispered to Hubert:
“We had better not be seen together to-night, I think. Let
us meet to-morrow at noon, out at Frascati, as before. I
must see you. It is most important.”
“Good,” he replied. “That is an appointment,” and bending
over her hand he passed across the great apartment, and
was soon laughing merrily with Suderman, secretary of the
Swedish Embassy.
77. He was rather annoyed that Lola—whom he had come there
expressly to meet—should have ordered him to remain
apart from her. What, he wondered, did she fear?
When in her presence, the world was, to him, full of bright
gladness, but when they were apart, he only moped in
silence and despair.
Did she know the truth, he wondered. Had she, by her
woman’s keen, natural intuition, discovered that he loved
her—that he was hers, body and soul?
Though he laughed lightly with the tall, fair-haired Swede at
his side, his thoughtful eyes were still upon her, full of
supreme admiration. And once she glanced furtively at him,
as though in fear, it seemed, and then he saw her
accompany the fat old General out into the ante-chamber
adjoining.
For half an hour, or more, he remained talking with men
and women he knew—the same old weary chatter of which
the diplomat serving his country abroad grows so
unutterably tired.
Who, of all that gay throng save His Majesty himself,
dreamed of the sharp-edged sword of war suspended above
them? Who knew of the black peril which threatened the
fair land of Italy, or of the carefully prepared plot which her
enemies in Vienna had prepared against her.
As Waldron stood chatting with a stout woman in black—the
wife of one of the great Hebrew financiers of Genoa, he saw
His Excellency enter and take his stand near the King,
smiling serenely and bowing graciously to those about him
—he, the man who was feeding the army upon tinned meat
that had been rejected by the German authorities, and who
78. signed contracts in return for bundles of bank-notes. Ah!
what a world is ours!
But alas! is there not corruption in every Ministry of every
European Power. What contractor to-day can hope to do a
legitimate business without placing apart a sum for palm-
oil? Disguise it as you will, business morality is in these
days of grab and get-rich-quick, at a very low ebb, for too
often, alas! honesty spells bankruptcy.
A pretty young Countess was talking with Hubert as he
stood watching His Excellency. Was the General, he
wondered, the man who had hired the two ruffians, Merlo
and Fiola, to make that murderous attack upon him? Or was
it Ghelardi, as the detective, Pucci, had that night declared.
Was it possible that the Chief of Secret Police had now
found out the strenuous efforts he was making towards the
elucidation of the problem of the stolen plans, and in
consequence his jealousy had been aroused.
Of which theory to accept he was utterly undecided.
He was listening to the pretty woman’s inane chatter, hardly
aware of what she said. His mind was far too full of the
grave peril of the international situation.
Suddenly his eyes wandered around to find Lambarini. He
was there a few moments before, but he seemed to have
left and passed into one or other of the ante-rooms. A point
had arisen in his mind regarding the plans earlier that
evening, and upon it he wished to ask him a question.
The Council Chamber was now hot and stifling, and the
mingled odours of the chiffons of the women nauseated
him. He would have preferred to be in the quiet comfort of
79. his own rooms, now that Lola had sent him away. Yet was
not his duty to be seen at that official reception?
Dawson, the British military attaché, conspicuous in his
Guards’ uniform, came up to him, saying in a low voice:
“Hallo, Hubert, you look a bit bored, my dear boy. So am I.
Couldn’t we clear out, do you think? I’m going to play
bridge down at the club. Come?”
“Not to-night, old chap,” Hubert answered. “I shall stay
another quarter of an hour, and then toddle home.”
“Sure you won’t—eh?”
“No, not to-night. I’m tired.”
“Right-ho! Good night,” answered the attaché cheerily, and
was next moment lost in the crowd. Waldron pushed his
way through the throng into the ante-chamber, vainly
searching for Lambarini. Pironti, the unscrupulous secretary
of the Minister was there, surrounded by women—wives of
officers and others who hoped to secure the man’s good
graces to procure better appointments for their husbands.
In the army it was openly declared that Pironti was
necessary in order to secure His Excellency’s ear, and many
a man had been passed over his superior’s heads and given
lucrative jobs because Pironti’s palm had been crossed by a
few bank-notes.
Presently, tired to death of the incessant laughter and
chatter, Hubert left by a door which he knew led to a long
corridor, which ended with a flight of stairs to the first floor.
On the nights of Ministerial receptions the sentries had
orders to allow guests to pass without hindrance and
80. unchallenged throughout the building, therefore, as Hubert
ascended the stairs the soldier stood at attention.
Above, was another wide corridor leading right round the
first floor to where was situated General Cataldi’s private
cabinet in the centre of the huge, handsome pile
overlooking the broad Via Venti Settembre.
To that part of the building few of the guests penetrated,
save perhaps some officials who took their wives to see the
fine suite of rooms occupied by His Excellency the Minister.
Hubert was still in search of Lambarini, and was wondering
if he had gone in that direction.
At some distance down the corridor from the door of His
Excellency’s private cabinet two sentries, their duties
relaxed that night, stood at ease chatting, but as Hubert
passed they drew themselves to attention, while around a
corner from another corridor which ran at right angles a
waiter with a silver salver in his hand hurried by.
The man’s face struck Waldron as peculiarly familiar, yet he
saw it only for a second, as the man seemed in a great
hurry.
It was not Pucci, for he had not seen him since he had first
entered the building.
Hubert halted and looked after the receding figure, much
puzzled. His clothes did not fit him, for the tails of his dress-
coat were too long, and the trousers also were too big.
Apparently, he seemed of middle-age, with a short
moustache turning slightly grey, yet in his eyes, in that brief
second when their glance had met, there was an expression
that was familiar.
81. “Who can he be?” murmured Hubert to himself. “I know
him. But for the life of me I can’t recollect where we’ve met
before.”
The man who travels comes frequently across familiar
waiters in all sorts of out-of-the-way places. Therefore, after
reflection, he came to the conclusion that it must be a man
who had served him somewhere or other in the past.
And he went forward to His Excellency’s rooms—that room
wherein, on the last occasion, he had discussed the stolen
plans with Cataldi and the two secretaries.
No one was nigh. The sentry still stood gossiping at the
other end of the corridor. He would enter and have yet
another look at that big safe which had been so
mysteriously opened, though no one appeared to have
entered there.
He turned the handle of the big door of polished mahogany.
It yielded noiselessly, and pushing it open, he stood upon
the thick, Oriental carpet in the too familiar room.
He halted upon the threshold, scarce believing his own
eyes.
Before the Minister’s safe—the same one from which the
plans had been stolen—stood a woman—Lola!
The safe door stood open, and as he looked he watched her
abstract an envelope, which she folded hurriedly with
nervous hands and thrust into the breast of her gown, at
the same time producing a similar envelope which she put
in the place of the one she had stolen.
So noiselessly had he entered that she was all unconscious
of his presence.
82. His heart gave a great bound and he held his breath. His
senses were frozen by the amazing and horrifying discovery.
With staring eyes he watched her breathlessly, as with
hurried hands she closed the heavy safe door, turned the
small key twice and then slipped it into her long white
glove, at the same time crushing the stolen envelope
deeper down into the breast of her low-cut dress.
For a second she remained motionless. Then she tried the
safe door in order to reassure herself that it was securely
locked, and turned to leave.
But as she did so a low cry escaped her hard, white lips.
She found herself face to face with Hubert Waldron.
83. Chapter Twenty Eight.
The Eyewitness.
“Princess!”
“You!” she gasped, staring at him, her face white as death,
and clutching at the back of a chair for support.
“Yes. I see now why you were so anxious that I should not
remain in your company this evening,” he said in bitter
reproach.
“Then—then you know!” she cried. “You—you saw me!”
“Yes. I have been watching you, and I can only say that I
am surprised to find you tampering with His Excellency’s
safe!” he said in a low, hard tone, while, as ill-luck would
have it, old Ghelardi, in uniform, with a glittering star upon
his coat, entered the room just at that moment and
overheard part of the diplomat’s words.
“Ah!” said the crafty Chief of Secret Police, affecting not to
have overheard anything. “Ah! these assignations—eh?”
She raised her hand towards him in a quick gesture, but
from her glove, there fell the small key.
Ghelardi stooped and picked it up.
“Hallo!” he exclaimed, “what does this mean, Your
Highness? A safe key!”
The unhappy girl, white as death, nodded in the affirmative.
84. The white-haired official stepped across, drew the brass
cover aside from the keyhole, and tried the key. It yielded.
“And may I ask Your Royal Highness why I find you here, in
His Excellency’s room, with a key to his private safe
wherein, I believe, many secrets of our defences are kept?”
he asked of her.
“I refuse to answer you, Signor Commendatore,” was her
bold reply, as she drew herself up and faced him. “You have
no right to question me. I shall answer only to His Majesty
for what I have done.”
This bold declaration took Hubert aback.
“Very well,” replied the old man, pocketing the key and
smiling that strange, cunning smile of his. “Your Highness
shall be compelled to answer to him—and without very
much delay.”
And he turned on his heel and without a word left the room.
“Ah! Mr Waldron,” she cried, wringing her hands, “what
must you think of me? I know I have acted very foolishly—
that I am mad—that I—”
“Hush, Princess!” he said, his heart full of sympathy for her
in her wild distress. “You have acted wrongly, it is true—
very, very wrongly. Yet I am still your friend. I will see you
safely out of this impasse—if you will only allow me. What is
that document you have abstracted from the safe?”
She made no response, but placing her hand within her
breast she very slowly drew it out and handed it to him.
Without opening the envelope he placed it in his pocket.
Then taking her hand, he looked long and earnestly into her
85. face and said:
“You had better return to the Palace at once, Lola. You are
not well. Leave me to settle matters with Ghelardi.”
“But he will tell the King!” she gasped, wringing her hands
in despair. “What can I say—how shall I explain?”
“Leave all to me,” he urged. “But before you go, tell me one
thing. Why is Henri Pujalet in Rome?”
“No, no!” she shrieked, “do not mention his name. I—ah! no
—do not torture me, I beg of you!” she went on wildly.
“Hate me—denounce me as a spy, if you will—revile my
memory if you wish—but do not taunt me with the name of
that man.”
“I will see you to your carriage. Come,” he urged simply.
She struggled to calm herself, placing her gloved hand upon
her beating heart, while the Englishman laid his hand
tenderly upon her shoulder in deepest sympathy.
At first he had been horrified at discovering the bitter,
amazing truth. But horror had now been succeeded by
poignant regret and a determination to suppress, if
possible, what must be, if divulged by Ghelardi, as no doubt
it would—a most terrible national scandal.
While they were standing together, a Colonel of Artillery and
two ladies entered, the former showing them the private
cabinet of the head of the War Department. The women
recognised the Princess by the decoration she wore at the
edge of her bodice, and bowed low and awkwardly before
her as she passed out, followed by Hubert.
86. With hurried steps he conducted her to the main entrance,
and at once sent a servant for one of the royal automobiles,
saying that Her Royal Highness was not well.
Together they waited in an ante-room almost without
speaking. She seemed too nervous and overwrought.
“I trust you, Mr Waldron,” she said suddenly, looking up into
his face. “Yet—ah! what can you think of me! How you must
scorn and despise me! But—but I hope you will not
misjudge me—that—you will make allowances for me—a girl
—a very foolish girl?”
“Do not let us discuss that now,” he hastened to reply in a
low, hard voice, for he never knew until that moment how
mad was his affection for her.
And just then one of the royal flunkeys entered, bowing, to
announce that the car was awaiting Her Royal Highness.
Their hands clasped in silence, and she walked out through
a line of obsequious servants and down the flight of steps to
the royal car.
As she went out a waiter stood behind the line of soldiers
drawn up in the great vestibule, watching intently.
Unobserved he had followed the pair when they had
emerged from His Excellency’s private cabinet, and his
shrewd eyes had noticed something amiss.
He was the same man who had passed Hubert earlier in the
evening and whose face had so puzzled him.
The Englishman, after the royal car had driven away, turned
and made his way back in search of Ghelardi.
87. The discovery held him utterly confounded. What secret was
contained in that envelope she had stolen? Why had she a
key to the Minister’s safe?
As he walked back, his mind tortured by a thousand strange
thoughts and curious theories, the mysterious waiter
followed him at a respectable distance, watching.
Hubert was wondering what had become of Pucci whom he
ordered to be near him, and whom he had not seen the
whole evening.
He gained the door of His Excellency’s room just as the
Chief of Secret Police returned along the corridor.
“I have been endeavouring to discover His Excellency, but,
unfortunately, I cannot find him anywhere,” the old man
said. “We will open the safe and see what has been taken.
It is utterly astounding to me that the Princess Luisa should
be revealed as a spy.”
“I do not think we should condemn her yet,” urged Waldron.
“There may be some explanation.”
“Explanation! What explanation can there be of a woman
who takes advantage of a reception, when the sentries are
relaxed, to creep up here, open the safe with a false key,
and abstract documents.”
“I cannot see the motive,” declared Waldron.
“Ah! but I do. I and my agents have been watching for
weeks,” he replied, and crossing to the safe he placed the
key in the lock and again opened it.
Many formidable bundles of documents were disclosed,
lying within, together with the thin envelope with which Lola
88. had replaced the one she had taken.
Waldon took it up and turned it over with curiosity. Then,
deliberately tearing it open, he pulled out its contents.
It was, he found to his dismay, only a blank piece of tracing
paper!
“Ah! that is what she has placed here, after taking out a
similar envelope, I suppose,” snapped the keen-eyed old
man, grasping the situation in a moment. “I have suspected
this all along—ever since those fortress plans so
mysteriously disappeared. And now she has taken another
document. I was foolish to allow her to leave with you.”
“The document—or whatever it is—is in my safe keeping.”
“You have it!” he cried quickly. “Please hand it to me.”
“I shall do no such thing, Commendatore,” was Hubert’s
defiant reply.
“It is a secret of State, and you, as a foreigner, have no
right to its possession!”
“It has been given to me for safety, and I shall hand it over
to His Majesty, and to him alone.”
“Signor Waldron, I demand it,” the old man said angrily,
raising his voice as he flung the safe door to with a clang
and re-locked it. “I demand it—in the name of His Majesty!”
“And I refuse.”
“You defy me then?”
“Yes, I defy you, signore,” he replied firmly, his dark eyes
fixed upon those of the crafty official.
89. “You are Her Highness’s lover. When the King is made aware
of that fact he will show you little graciousness, I assure
you,” said Ghelardi with a dry laugh.
“But you will remain silent upon that point, just as you will
remain silent regarding what we have discovered to-night,”
the Englishman said slowly. “No scandal must attach to the
Princess’s name, remember.”
“Of course you wish to shield her—for your own ends. She
is the spy for whom we have been searching all these
weeks. It is she who placed in the hands of the our enemies
the truth concerning the new fortifications along the
northern frontier.”
“I refuse to discuss that point,” replied Hubert very coldly,
but firmly. “One thing alone I demand of you, and that is
silence—silence most absolute and profound.”
“It is my duty to inform the King of the whole
circumstances.”
“True, it may be your duty, but it is one that you will not
perform, Signor Ghelardi. Think of the terrible scandal
throughout Europe if the Press got wind of it! And they
must do—if you report officially, and it comes to the ears of
His Excellency the Minister. The latter hates the Princess,
because she accidentally snubbed the Countess Cioni at the
ball at the Palazzo Ginori last week.”
“That is no affair of mine. Women’s jealousies do not
concern me in the least. I am charged with the safety of the
State against foreign espionage.”
“Well—in this case you’ve discovered the truth accidentally,”
responded the diplomat, “and having done so, if you respect
your Sovereign and his family, you will say nothing. Further,
90. we may, if we remain silent, be able to obtain more
information from Her Highness as to the identity of the
person into whose hands the plans fell.”
“She abstracted them, without a doubt, for she had this
duplicate key of the safe,” the old man declared.
“You will say nothing, I command you.”
“You! How can you impose silence upon me, pray?” he
demanded fiercely. “You are a foreigner, and you are holding
a State secret.”
“I shall hold it at present for safe keeping.”
“Then I shall go straight to the King and lay the whole
matter before him.”
“You threatened to do a similar action before,” said the
other very quietly. “I repeat my warning—that silence is
best.”
“Then I tell you frankly that I refuse to heed your warning.
It is my duty to my Sovereign to tell him the truth.”
“Very well—go to him and tell him—at your own peril.”
“Peril!” he echoed. “What peril?”
“The peril at which I have already hinted, Signor Ghelardi,”
he answered in a low, hard voice. “Do you wish me to be
more explicit? Well—there is in a village called Wroxham, in
Norfolk, a mystery—the murder of a man named Arthur
Benyon, a British naval officer—which has never yet been
cleared up. One man can clear it up—an eyewitness who is,
fortunately, still alive and who knows you. And if it is
cleared up, then you, Luigi Ghelardi—who at the time
91. Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
More than just a book-buying platform, we strive to be a bridge
connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.
Join us on a journey of knowledge exploration, passion nurturing, and
personal growth every day!
ebookbell.com