Beginning Java 7 [Friesen 2011-11-22].pdf
(
8581 KB
)
Pobierz
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
Contents at a Glance
About the Author..................................................................................................
xiv
About the Technical Reviewer..............................................................................
xv
Acknowledgments...............................................................................................
xvi
Introduction........................................................................................................
xvii
Chapter 1: Getting Started with Java......................................................................
1
Chapter 2: Discovering Classes and Objects........................................................
51
Chapter 3: Exploring Advanced Language Features...........................................
131
Chapter 4: Touring Language APIs.....................................................................
227
Chapter 5: Collecting Objects..............................................................................
319
Chapter 6: Touring Additional Utility APIs..........................................................
401
Chapter 7: Creating and Enriching Graphical User Interfaces............................
435
Chapter 8: Interacting with Filesystems.............................................................
511
Chapter 9: Interacting with Networks and Databases........................................
585
Chapter 10: Parsing, Creating, and Transforming XML Documents...................
663
Chapter 11: Working with Web Services............................................................
751
Chapter 12: Java 7 Meets Android.....................................................................
831
Index...................................................................................................................
873
iii
C H A P T E R 1
Getting Started with Java
Welcome to Java. This chapter launches you on a tour of this technology by focusing on fundamentals.
First, you receive an answer to the “What is Java?” question. If you have not previously encountered Java,
the answer might surprise you. Next, you are introduced to some basic tools that will help you start
developing Java programs, and to the NetBeans integrated development environment, which simplifies
the development of these programs. Finally, you explore fundamental language features.
What Is Java?
Java is a language for describing programs, and Java is a platform on which to run programs written in
Java and other languages (e.g., Groovy, Jython, and JRuby). This section introduces you to Java the
language and Java the platform.
Note
To discover Java’s history, check out Wikipedia’s “Java (programming language)”
(
http://en.wikipedia.org/wiki/Java_(pro
gramming_language)#History
) and “Java (software platform)”
(
http://en.wikipedia.org/wiki/Java_(sof
tware_platform)#History
) entries.
Java Is a Language
Java
is a general-purpose, class-based, and object-oriented language patterned after C and C++ to make
it easier for existing C/C++ developers to migrate to this language. Not surprisingly, Java borrows
elements from these languages. The following list identifies some of these elements:
•
Java supports the same single-line and multiline comment styles as found in
C/C++ for documenting source code.
•
Java provides the
if
,
switch
,
while
,
for
, and other reserved words as found in the
C and C++ languages. Java also provides the
try
,
catch
,
class
,
private
, and other
reserved words that are found in C++ but not in C.
•
As with C and C++, Java supports character, integer, and other primitive types.
Furthermore, Java shares the same reserved words for naming these types; for
example,
char
(for character) and
int
(for integer).
1
CHAPTER 1
GETTING STARTED WITH JAVA
•
Java supports many of the same operators as C/C++: the arithmetic operators (
+
,
-
,
*
,
/
, and
%
) and conditional operator (
?:
) are examples.
•
Java also supports the use of brace characters
{
and
}
to delimit blocks of
statements.
Although Java is similar to C and C++, it also differs in many respects. The following list itemizes
some of these differences:
•
Java supports an additional comment style known as Javadoc.
•
Java provides
transient
,
synchronized
,
strictfp
, and other reserved words not
found in C or C++.
•
Java’s character type has a larger size than the version of this type found in C and
C++, Java’s integer types do not include unsigned variants of these types (Java has
no equivalent of the C/C++ unsigned long integer type, for example), and Java’s
primitive types have guaranteed sizes, whereas no guarantees are made for the
equivalent C/C++ types.
•
Java doesn’t support all of the C/C++ operators. For example, there is no
sizeof
operator. Also, Java provides some operators not found in C/C++. For example,
>>>
(unsigned right shift) and
instanceof
are exclusive to Java.
•
Java provides labeled break and continue statements. These variants of the C/C++
break and continue statements provide a safer alternative to C/C++’s goto
statement, which Java doesn’t support.
Note
Comments, reserved words, types, operators, and statements are examples of fundamental language
features, which are discussed later in this chapter.
A Java program starts out as source code that conforms to Java
syntax
, rules for combining symbols
into meaningful entities. The Java compiler translates the source code stored in files that have the
“
.java
” file extension into equivalent executable code, known as
bytecode
, which it stores in files that
have the “
.class
” file extension.
Note
The files that store compiled Java code are known as
classfiles
because they often store the runtime
representation of Java classes, a language feature discussed in Chapter 2.
The Java language was designed with portability in mind. Ideally, Java developers write a Java
program’s source code once, compile this source code into bytecode once, and run the bytecode on any
platform (e.g., Windows, Linux, and Mac OS X) where Java is supported, without ever having to change
the source code and recompile. Portability is achieved in part by ensuring that primitive types have the
same sizes across platforms. For example, the size of Java’s integer type is always 32 bits.
2
Plik z chomika:
musli_com
Inne pliki z tego folderu:
Big Java Late Objects [Horstmann 2012-02-01].pdf
(167477 KB)
Data Structures_ Abstraction and Design using Java (2nd ed.) [Koffman & Wolfgang 2010-01-26].pdf
(190252 KB)
Big Java Early Objects (5th ed.) [Horstmann 2013-01-04].pdf
(145099 KB)
Data Abstraction and Problem Solving with Java_ Walls and Mirrors (3rd ed.) [Prichard & Carrano 2010-10-30] (photocopier quality).pdf
(110506 KB)
A Little Java, a Few Patterns [Felleisen & Friedman 1997-12-19].pdf
(14847 KB)
Inne foldery tego chomika:
3D Design - Programming
ActionScript
Actionscript - Flash - Flex - Air
Ada
ADO
Zgłoś jeśli
naruszono regulamin