Java Programming for Engineers 1st Edition Julio Sanchez download
Java Programming for Engineers 1st Edition Julio Sanchez download
https://ebookname.com/product/java-programming-for-engineers-1st-
edition-julio-sanchez/
https://ebookname.com/product/the-pc-graphics-handbook-1st-
edition-julio-sanchez/
https://ebookname.com/product/matlab-programming-for-
engineers-3rd-edition-stephen-j-chapman/
https://ebookname.com/product/groovy-programming-an-introduction-
for-java-developers-1st-edition-kenneth-barclay/
https://ebookname.com/product/programming-and-problem-solving-
with-java-1st-edition-edition-nell-b-dale/
Building Wealth Buying Foreclosures 1st Edition John
Schaub
https://ebookname.com/product/building-wealth-buying-
foreclosures-1st-edition-john-schaub/
https://ebookname.com/product/closed-loop-neuroscience-1st-
edition-ahmed-el-hady/
https://ebookname.com/product/pathfinder-adventure-path-punks-in-
a-powder-keg-outlaws-of-alkenstar-1-of-3-p2-2nd-edition-vanessa-
hoskins/
https://ebookname.com/product/the-handbook-of-contemporary-
animism-1st-edition-graham-harvey/
https://ebookname.com/product/the-coretta-scott-king-
awards-1970-2009-40th-anniversary-coretta-scott-king-awards-
book-4th-edition-henrietta-m-smith/
An apocryphal dictionary of psychoanalysis 1st Edition
Giuseppe Civitarese
https://ebookname.com/product/an-apocryphal-dictionary-of-
psychoanalysis-1st-edition-giuseppe-civitarese/
JAVA
Programming
for Engineers
MARIA P. CANTON
Minnesota State University, Mankato
CRC PR E S S
Boca Raton London New York Washington, D.C.
This book contains information obtained from authentic and highly regarded sources. Reprinted material
is quoted with permission, and sources are indicated. A wide variety of references are listed. Reasonable
efforts have been made to publish reliable data and information, but the author and the publisher cannot
assume responsibility for the validity of all materials or for the consequences of their use.
Neither this book nor any part may be reproduced or transmitted in any form or by any means, electronic
or mechanical, including photocopying, microfilming, and recording, or by any information storage or
retrieval system, without prior permission in writing from the publisher.
The consent of CRC Press LLC does not extend to copying for general distribution, for promotion, for
creating new works, or for resale. Specific permission must be obtained in writing from CRC Press LLC
for such copying.
Direct all inquiries to CRC Press LLC, 2000 N.W. Corporate Blvd., Boca Raton, Florida 33431.
Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are
used only for identification and explanation, without intent to infringe.
Table of Contents
Preface
Numeric data
Building Objects
The default constructor
Overloading the constructor
Error Types
Hardware and software errors
Algorithmic errors
Exceptions
Bullt-in exception handling
Java's approach
Java exception classes
Advertising exceptions
Exceptions Programming
Java exception processing
Raising exceptions
Handling exceptions
Throwing exceptions
Interval arithmetic
Treatment of infinity
Not a number (NaN)
Signaling and quiet NaNs
Exceptions
Invalid operation exception
Division by zero exception
Overflow exception
Underflow exception
Inexact result exception
IEEE 754 in Java
java.lang Class Double
MAX_VALUE
MIN_VALUE
NaN
NEGATIVE_INFINITY
POSITIVE_INFINITY
public static boolean isInfinite(double v)
public boolean isInfinite()
public static boolean isNaN(double v)
public boolean isNaN()
java.lang Class Float
MAX_VALUE
MIN_VALUE
NaN
NEGATIVE_INFINITY
POSITIVE_INFINITY
public static boolean isInfinite(float v)
public boolean isInfinite()
public static boolean isNaN(float v)
public boolean isNaN()
Java Numeric Truncation
public static double ceil(double a)
public static double floor(double a)
public static double rint(double a)
public static long round(double a)
public static int round(float a)
Preface
This book about Java programming is designed to address the needs of en-
gineers, scientists, and technology professionals in general. In identifying
our target audience we have made several assumptions:
1. Our readers are not likely to use Java to develop applications of major com-
plexity. Instead, we envision that the programs would be relatively small
and specialized towards the solution of a particular problem set of a tech-
nological field.
2. Our audience is more concerned with the solution of numerical problems
than with text processing or the crunching of alphabetic data.
3. The typical development environment consists of a single programmer or a
small programming team.
4. Most of the programs will be used by an individual or by a small technical
group.
5. The programs and applications will not be marketed to the public at large.
Based on these assumptions we have focused our attention on those
topics in Java programming that are of greater interest to our audience.
At the same time, we have minimized the coverage of topics that are of
less concern to the typical engineer-programmer.
Contents
The book aims at a comprehensive coverage of Java 1.3 as a full-featured
programming language, using the PC platform. The text assumes no prior
programming experience. The only skills expected in the reader are basic
keyboarding and user-level familiarity with the PC. The material is sprin-
kled with short Java programs and code fragments that illustrate the point
at hand. The sample programs are stripped of all unnecessary complica-
tions and distracting details, however, most of them stand alone as small
applications. The purpose of the sample programs is to provide a valid, run-
ning sample that can be reused in your own code.
Part I
Chapter 1
Java Programming
Introducing Java
Java is a programming language similar to C and C++. Its most characteris-
tic feature is that Java is a platform-independent language. This means that
Java programs will run on any machine that supports the language. The slo-
gan “write once, run anywhere” has often been used to describe and pro-
mote the Java language.
Incidentally...
Java is not without drawbacks, and platform-independency is more a
goal than a reality. Often Java programs must be modified before they
operate correctly in another system. This has led some critics to re-
write the Java slogan to say “write once, debug everywhere.”
Perhaps the most important element in Java’s success was its timeli-
ness. The language was introduced at the same time that the World Wide
Web was rapidly gaining popularity. The Web is an international network
of incompatible computers, made by dozens of manufacturers and having
unique hardware characteristics. There is no standard operating system
or software environment on the Web.
Programmers note:
The language used to create Web pages and other Internet documents
is called Hypertext Markup Language (HTML). Java code can be em-
bedded in HTML documents in a capsule called a Java applet.
Java is object-oriented
An object is a program element that contains both data and code. The ratio-
nale for objects is that data is useful if there are operations that can be used
to transform it. For example, we find it useful to store numbers in a com-
puter system because there are operations that can be performed on these
numbers. A computer program stores the hourly wage of a company’s em-
ployees because it can later calculate the gross pay of each individual by
multiplying the hourly wage by the number of hours worked. What use
would it be to store numbers in a computer system that cannot perform
arithmetic?
Programmers note:
As an object-oriented language, Java resembles Smalltalk. Smalltalk
was developed at the Xerox Palo Alto Research Center (PARC) and
first released in 1980. Although Smalltalk has never been very popu-
lar, it is considered a model for object-oriented programming lan-
guages. Java supports inheritance, encapsulation, and polymorphis,
the cornerstones of object-oriented systems.
Java is strongly-typed
Java is described as a strongly-typed language. This means that all data
must belong to a specific type and that the data type cannot be changed
while the program is executing. For example, whole numbers belong to one
data type and fractional numbers to another one.
input to the compiler, has the extension .java. The Java byte code file gener-
ated by the Javac compiler has the extension .class. It is the file with the
.class extension that is executed by the Java interpreter. In Chapter 3, you
will learn to create and run a program using the Java software development
tools.
Java Code
A program, in general terms, is a sequential set of instructions designed to
perform a specific task. In this sense, the set of instructions that must be
followed to start up a particular model of automobile could be described as
the start-up program for that vehicle. By the same token, a computer pro-
gram is a set of logical instructions that makes the computer perform a spe-
cific function.
For example, you may write a computer program to calculate the inter-
est that accrues when you invest a given amount of money, at a certain in-
terest rate for a specific period of time. Another program could be used to
tell a robot when it is time to recharge its batteries. A third one to help a
physician diagnose a childhood disease by examining the patient’s symp-
toms. In all of these cases the program consists of a set of instructions
that perform conditional tests, follow a predictable path, and reach a pre-
dictable result. A set of haphazard instructions that lead to no predictable
end is not considered a program.
Communicating with an alien intelligence
When we write a computer program we are communicating with an alien in-
telligence. A computer is a machine built of metal, silicon, and other com-
posite materials. It has no knowledge and no common sense. In a way, a
computer is no more than a tin can. If one-hundred years ago someone had
found you attempting to communicate and give orders to a tin can, you
would have probably been committed to a mental institution.
Our main difficulty is that the tin can never knows what you mean. A
human intelligence has accumulated considerable knowledge of the
world and of society at large. The set of instructions for a human to get
me a can of pop out of a vending machine can be rather simple:
“Joe, here is fifty cents, would you please get me a Pepsi?”
Joe, who has knowledge of the world, understands that he must walk
out of the room, open the necessary doors and walk up and down stairs,
reach the vending machine, wait in line if someone is using it, then place
the coins in the adequate slot, punch the Pepsi button, retrieve the can of
pop, and bring it back to me, again opening doors and walking up and
down stairs as necessary. Joe has knowledge of doors, of stairs, of money,
The machine, on the other hand, has no previous knowledge, does not
understand social conventions, and has no experience with doors, stairs,
people standing in line, or vending machine operation. If we forget to tell
the robot to open the door it will crash through and leave a hole shaped
like its outline. If we forget to tell it to wait in line if someone else is using
the vending machine, then the robot may just walk over the current cus-
tomer in its effort to put the coins in the slot. The tin can has no experi-
ence, no social manners, and no common sense. Giving instructions to a
machine is different and much more complicated than giving instructions
to an intelligent being.
Flowcharting
Computer scientists have come up with tools and techniques to help us de-
velop programs. One of the simplest and most useful of these tools is the
flowchart. A flowchart, like the word implies, is a graphical representation
of the flow of a program. In other words, a flowchart is a graph of the tests,
options, and actions that a program must perform in order to achieve a spe-
cific logical task.
Incidentally...
Present-day computers do not have human-like intelligence. Assump-
tions that are obvious when dealing with human beings are usually in-
valid when dealing with a machine. Computer programs must leave no
loose ends and presume no reasonable behavior. You cannot tell a
computer “well... you know what I mean!” or assume that a certain op-
eration is so obvious that it need not be explicitly stated. The program-
mer uses a flowchart to ensure that each processing step is clearly
defined and that the operations are performed in the required se-
quence.
Ney, Marshal, Napoleon's statement regarding the last acts of, 187.
Tiberius, 411.
Transcriber's note:
Archaic spelling and variations in
spelling and hyphenation have been
retained except in obvious cases of
typographical error.
Anchors to footnotes 1 and 2 have
been supplied by the transcriber.
Table of contents has been created
for the HTML version.
*** END OF THE PROJECT GUTENBERG EBOOK BLACKWOOD'S
EDINBURGH MAGAZINE—VOLUME 62, NO. 386, DECEMBER, 1847
***
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com