Immediate download Java 17 Quick Syntax Reference: A Pocket Guide to the Java SE Language, APIs, and Library Mikael Olsson ebooks 2024
Immediate download Java 17 Quick Syntax Reference: A Pocket Guide to the Java SE Language, APIs, and Library Mikael Olsson ebooks 2024
com
https://ebookmeta.com/product/java-17-quick-syntax-
reference-a-pocket-guide-to-the-java-se-language-apis-and-
library-mikael-olsson/
OR CLICK HERE
DOWLOAD NOW
https://ebookmeta.com/product/java-17-quick-syntax-reference-a-pocket-
guide-to-the-java-se-language-apis-and-library-3rd-edition-mikael-
olsson/
ebookmeta.com
https://ebookmeta.com/product/c-10-quick-syntax-reference-a-pocket-
guide-to-the-language-apis-and-library-mikael-olsson/
ebookmeta.com
https://ebookmeta.com/product/java-17-quick-syntax-reference-3rd-
edition-mikael-olsson/
ebookmeta.com
https://ebookmeta.com/product/war-in-the-modern-world-course-
guidebook-the-great-courses-wondrium-1st-edition-david-r-stone/
ebookmeta.com
https://ebookmeta.com/product/hair-story-nonieqa-ramos/
ebookmeta.com
https://ebookmeta.com/product/activist-affordances-how-disabled-
people-improvise-more-habitable-worlds-1st-edition-arseli-dokumaci/
ebookmeta.com
https://ebookmeta.com/product/designing-machine-learning-systems-an-
iterative-process-for-production-ready-applications-chip-huyen/
ebookmeta.com
https://ebookmeta.com/product/hi-c-data-analysis-1st-edition-silvio-
bicciato/
ebookmeta.com
Bioinformatics in Rice Research Theories and Techniques
1st Edition Manoj Kumar Gupta (Editor)
https://ebookmeta.com/product/bioinformatics-in-rice-research-
theories-and-techniques-1st-edition-manoj-kumar-gupta-editor/
ebookmeta.com
Java 17 Quick
Syntax Reference
A Pocket Guide to the Java
SE Language, APIs, and Library
—
Third Edition
—
Mikael Olsson
Java 17 Quick Syntax
Reference
A Pocket Guide to the Java SE
Language, APIs, and Library
Third Edition
Mikael Olsson
Java 17 Quick Syntax Reference: A Pocket Guide to the Java SE Language,
APIs, and Library
Mikael Olsson
Hammarland, Länsi-Suomi, Finland
Chapter 3: Variables�����������������������������������������������������������������������������9
Data Types�������������������������������������������������������������������������������������������������������������9
Declaring Variables���������������������������������������������������������������������������������������������10
Assigning Variables���������������������������������������������������������������������������������������������10
Using Variables���������������������������������������������������������������������������������������������������10
Integer Types�������������������������������������������������������������������������������������������������������11
Floating-Point Types��������������������������������������������������������������������������������������������11
iii
Table of Contents
Char Type������������������������������������������������������������������������������������������������������������12
Boolean Type�������������������������������������������������������������������������������������������������������12
Variable Scope����������������������������������������������������������������������������������������������������13
Anonymous Block�����������������������������������������������������������������������������������������������13
Type Inference�����������������������������������������������������������������������������������������������������14
Chapter 4: Operators��������������������������������������������������������������������������15
Arithmetic Operators�������������������������������������������������������������������������������������������15
Assignment Operators����������������������������������������������������������������������������������������16
Increment and Decrement Operators������������������������������������������������������������������16
Comparison Operators����������������������������������������������������������������������������������������17
Logical Operators������������������������������������������������������������������������������������������������17
Bitwise Operators�����������������������������������������������������������������������������������������������18
Operator Precedence������������������������������������������������������������������������������������������18
Chapter 5: String��������������������������������������������������������������������������������21
Combining Strings�����������������������������������������������������������������������������������������������21
Escape Characters����������������������������������������������������������������������������������������������22
String Compare���������������������������������������������������������������������������������������������������23
StringBuffer Class�����������������������������������������������������������������������������������������������23
Text Blocks����������������������������������������������������������������������������������������������������������24
Chapter 6: Arrays��������������������������������������������������������������������������������27
Array Declaration������������������������������������������������������������������������������������������������27
Array Allocation���������������������������������������������������������������������������������������������������27
Array Assignment������������������������������������������������������������������������������������������������28
Multidimensional Arrays�������������������������������������������������������������������������������������28
ArrayList Class����������������������������������������������������������������������������������������������������29
iv
Table of Contents
Chapter 7: Conditionals����������������������������������������������������������������������31
If Statement��������������������������������������������������������������������������������������������������������31
Switch Statement�����������������������������������������������������������������������������������������������32
Switch Expression�����������������������������������������������������������������������������������������������33
Ternary Operator�������������������������������������������������������������������������������������������������35
Chapter 8: Loops���������������������������������������������������������������������������������37
While Loop����������������������������������������������������������������������������������������������������������37
Do While Loop�����������������������������������������������������������������������������������������������������38
For Loop��������������������������������������������������������������������������������������������������������������38
For Each Loop�����������������������������������������������������������������������������������������������������39
Break and Continue���������������������������������������������������������������������������������������������39
Labeled Block�����������������������������������������������������������������������������������������������������40
Chapter 9: Methods����������������������������������������������������������������������������41
Defining Methods������������������������������������������������������������������������������������������������41
Calling Methods��������������������������������������������������������������������������������������������������42
Method Parameters��������������������������������������������������������������������������������������������42
Return Statement������������������������������������������������������������������������������������������������43
Method Overloading��������������������������������������������������������������������������������������������44
Passing Arguments���������������������������������������������������������������������������������������������45
v
Table of Contents
Constructor Chaining������������������������������������������������������������������������������������������51
Initial Field Values�����������������������������������������������������������������������������������������������51
Default Constructor���������������������������������������������������������������������������������������������52
Null����������������������������������������������������������������������������������������������������������������������52
Default Values�����������������������������������������������������������������������������������������������������53
Garbage Collector�����������������������������������������������������������������������������������������������53
vi
Table of Contents
vii
Table of Contents
viii
Table of Contents
Index�������������������������������������������������������������������������������������������������127
ix
About the Author
Mikael Olsson is a professional web
entrepreneur, programmer, and author. He
works for an R&D company in Finland where
he specializes in software development. In
his spare time, he writes books and creates
websites that summarize various fields of
interest. The books he writes are focused on
teaching their subject in the most efficient way
possible, by explaining only what is relevant
and practical without any unnecessary
repetition or theory.
xi
About the Technical Reviewer
Manuel Jordan Elera is an autodidactic
developer and researcher who enjoys learning
new technologies for his own experiments
and creating new integrations. Manuel won
the Springy Award – Community Champion
and Spring Champion 2013. In his little free
time, he reads the Bible and composes music
on his guitar. Manuel is known as dr_pompeii.
He has tech-reviewed numerous books
for Apress, including Pro Spring MVC with
WebFlux (2020), Pro Spring Boot 2 (2019), Rapid Java Persistence and
Microservices (2019), Java Language Features (2018), Spring Boot 2 Recipes
(2018), and Java APIs, Extensions and Libraries (2018). Read his 13 detailed
tutorials about many Spring technologies, contact him through his blog
at www.manueljordanelera.blogspot.com, and follow him on his Twitter
account, @dr_pompeii.
xiii
Introduction
Java is a high-level object-oriented programming language developed by
Sun Microsystems, which became part of Oracle Corporation in 2010. The
language is very similar to C++ but has been simplified to make it easier
to write bug-free code. Most notably, unlike C++, there are no pointers
in Java—instead, all memory allocation and deallocation is handled
automatically.
Despite simplifications like this, Java has considerably more
functionality than C++, due to its large class library. Java programs
also have high performance and can be made very secure, which
has contributed to making Java the most popular general-purpose
programming language in use today.
Another key feature of Java is that it is platform independent. This is
achieved by only compiling programs halfway, into platform-independent
instructions called bytecode. The bytecode is then interpreted, or run,
by the Java Virtual Machine (JVM). That means any system that has
this program and its accompanying libraries installed can run Java
applications.
To allow Java to be used in a variety of environments, there are four
different editions: Java ME, Java SE, Java EE, and Java FX. Each edition
contains a JVM and a set of class libraries. Java SE (Standard Edition)
provides the standard JVM along with the commonly used libraries for
building applications, in particular desktop applications. Java ME (Micro
Edition) is a small-footprint version of Java SE designed for running on
small devices such as mobile phones. Java EE (Enterprise Edition) is an
extended version of Java SE that includes libraries for building large-scale
xv
Introduction
xvi
CHAPTER 1
Hello World
I nstalling
Before you can program in Java, you need to download and install a Java
Development Kit (JDK), such as the Standard Edition (JDK SE) from
Oracle’s website.1 Among other things, the JDK includes the Java compiler,
the class libraries, and the virtual machine needed to run Java applications.
You should also download an Integrated Development Environment (IDE)
as it will make development in Java much easier. One such Java IDE is
Apache NetBeans,2 which is available for free on Windows, macOS, and
Linux. If you don’t want to use any IDE at all, using a regular text editor is
also an option. To work without an IDE, you can create an empty file with
the .java extension—for example, MyApp.java—and open it in your text
editor of choice.
C
reating a Project
If you decide to use an IDE (recommended), you need to create a
project, which will manage the Java source files and other resources.
To create a project in NetBeans, click File ➤ New Project. In the dialog
1
www.oracle.com/java/technologies/javase-downloads.html
2
https://netbeans.org
Author: Anonymous
Language: English
STORIES
OF THE
WAR OF 1812,
AND THE
MEXICAN WAR.
WITH NUMEROUS ENGRAVINGS.
PHILADELPHIA:
W. A. LEARY & Co.
No. 138 NORTH SECOND ST.
1854.
SURRENDER OF DETROIT.
In June, 1812, the United States declared war against Great Britain.
The chief cause of the war was the impressment of American
seamen by the British. General Hull, with twenty-five hundred men,
took post at Detroit, in Michigan. Soon afterward, the British general,
Brock, with thirteen hundred men, appeared before Detroit, erected
batteries, and summoned Hull to surrender. He refused, and the
British opened their fire upon the works. On the 26th, they crossed
the river and moved forward to the attack. The American troops
were prepared to receive them, and eager for the conflict. But as the
British approached, Hull ordered his men to retire into the fort, and
hoisted a white flag. In a short time, terms of surrender were agreed
upon, and the whole American army, with all its ammunition and
stores were given up to the British. This surrender excited the
indignation of the people. Hull was accused of cowardice, tried by a
court martial, and sentenced to be shot. The President, however, in
consideration of his age and services, remitted the punishment, but
ordered his name to be stricken from the rolls of the army.
BATTLE OF QUEENSTOWN.
BATTLE OF QUEENSTOWN.
Early in October, 1812, about three thousand five hundred men,
under command of General Van Rensselaer, were assembled on the
Niagara frontier. General Van Rensselaer resolved to make an attack
on the British position at Queenstown, eight miles below Niagara
Falls. At daybreak on the 13th of October, the troops began to
embark to cross the river. The British opened a fire upon them,
which was returned by the American batteries. Colonel Van
Rensselaer, with about one hundred men, reached the shore, and
stormed the fort of the British, though not without severe loss. The
Americans drove the enemy from the field, and the victory was
supposed to be gained, when another reinforcement arrived, and the
conflict was renewed. At this critical moment, General Van
Rensselaer crossed the river to bring a reinforcement for his gallant
little band, and found that the militia would not obey his orders.
Colonel Christie maintained the fight on the opposite shore, against
overwhelming numbers, until seeing no hope of relief, he
surrendered the remnant of his force. The Americans lost one
thousand men in all, in this battle. The loss of the enemy was
somewhat less, but their noble commander, the gallant Brock, was
slain.
DEFENCE OF FORT HARRISON.
COMMODORE HULL.
CAPTURE OF THE GUERRIERE.
At the commencement of the war, the navy of Great Britain was
looked upon as invincible. But an important victory changed the
opinion of the people of the United States. The frigate Constitution,
commanded by Captain Isaac Hull, sailed from Annapolis on the 25th
of July, 1812, for New York. Falling in with a British fleet, she only
escaped by great skill and seamanship. Soon after she sailed from
Boston, and on the 19th of August encountered the British frigate,
Guerriere, commanded by Captain Dacres. A fierce conflict of about
half an hour’s length ensued. The Guerriere was reduced to a wreck,
and after her surrender, burned. In this action the Americans had
seven men killed, and seven wounded. The British loss was fifteen
killed, sixty-two wounded, and twenty-four missing. The effect of
this victory was to give the Americans confidence in the skill and
bravery of their seamen.
CAPTURE OF THE FROLIC.
ATTACK ON YORK.
General Dearborn, the commander of the United States forces on the
Ontario frontier, having resolved to attack York, the capital of Upper
Canada, embarked seventeen hundred troops, and left Sackett’s
Harbor on the 25th of April. On the 27th, the troops, under the
command of General Pike, effected a landing and drove a much
superior force of the enemy from the shore. But they returned to the
attack, and the contest was renewed. The enemy were again
defeated and driven to their works. The whole force of the
Americans having reached the shore, and being arranged in the
order for attack, General Pike pressed forward, carried one of the
enemy’s batteries, and was moving towards the main works, when a
sudden and tremendous explosion of the magazine occurred, hurling
upon the advancing troops immense masses of stone and timber,
and for a time checking them by the havoc it made. General Pike
was mortally wounded. But the troops under command of Colonel
Pearce, pressed on, and captured the town, with all the land and
naval forces in and about it. The total loss of the Americans was
three hundred and twenty men. General Pike was greatly lamented.
The British loss was four hundred killed or wounded, and three
hundred prisoners.
CAPTURE OF FORT GEORGE.
FORT GEORGE.
DEFENCE OF SACKETT’S HARBOR.
COMMODORE PERRY.
BUILDING OF THE FLEET ON LAKE ERIE.
Early in the spring of 1813, the attention of the government of the
United States, was directed to the important object of obtaining the
command of Lake Erie. The earnest representations of General
Harrison had awakened the administration to a proper sense of the
necessity of this measure. The British already had an efficient naval
force upon the lake, and it gave them great advantages. Two brigs
and several schooners were ordered to be built, under the direction
of Captain Oliver H. Perry. That able and active officer saw that the
work was carried on with the greatest rapidity, and on the 2d of
August, he was able to sail in quest of the enemy’s squadron. The
British, though much superior in force, did not venture out to meet
the new squadron.
BATTLE OF LAKE ERIE.