Example: bankruptcy

A Programmer’s Guide to Java - pearsoncmg.com

A programmer s Guide toJava SE 8 Oracle Certified Associate (OCA)This page intentionally left blank A programmer s Guide toJava SE 8 Oracle Certified Associate (OCA)A Comprehensive PrimerKhalid A. MughalRolf W. RasmussenBoston Columbus Indianapolis New York San Francisco Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City S o Paulo Sydney Hong Kong Seoul Singapore Taipei TokyoMany of the designations used by manufacturers and sellers to distinguish their productsare claimed as trademarks.

A Programmer’s Guide to Java ® SE 8 Oracle Certified Associate (OCA) A Comprehensive Primer Khalid A. Mughal Rolf W. Rasmussen Boston • Columbus • Indianapolis • New York • San Francisco • Amsterdam • Cape Town

Tags:

  Guide, Programmer, Java, A programmer s guide to java

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of A Programmer’s Guide to Java - pearsoncmg.com

1 A programmer s Guide toJava SE 8 Oracle Certified Associate (OCA)This page intentionally left blank A programmer s Guide toJava SE 8 Oracle Certified Associate (OCA)A Comprehensive PrimerKhalid A. MughalRolf W. RasmussenBoston Columbus Indianapolis New York San Francisco Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City S o Paulo Sydney Hong Kong Seoul Singapore Taipei TokyoMany of the designations used by manufacturers and sellers to distinguish their productsare claimed as trademarks.

2 Where those designations appear in this book, and the publisherwas aware of a trademark claim, the designations have been printed with initial capitalletters or in all authors and publisher have taken care in the preparation of this book, but make noexpressed or implied warranty of any kind and assume no responsibility for errors or omis-sions. No liability is assumed for incidental or consequential damages in connection with orarising out of the use of the information or programs contained information about buying this title in bulk quantities, or for special sales opportunities(which may include electronic versions; custom cover designs.)

3 And content particular toyour business, training goals, marketing focus, or branding interests), please contact ourcorporate sales department at or (800) government sales inquiries, please contact questions about sales outside the , please contact us on the Web: of Congress Control Number: 2016937073 Copyright 2017 Pearson Education, rights reserved. Printed in the United States of America. This publication is protected bycopyright, and permission must be obtained from the publisher prior to any prohibitedreproduction, storage in a retrieval system, or transmission in any form or by any means,electronic, mechanical, photocopying, recording, or likewise.

4 For information regardingpermissions, request forms and the appropriate contacts within the Pearson EducationGlobal Rights & Permissions Department, please visit : 978-0-13-293021-5 ISBN-10: 0-13-293021-8 Text printed in the United States on recycled paper at RR Donnelley in Crawfordsville, printing, July 2016To the loving memory of my mother, Zubaida Begum,and my father, Mohammed Azim K. Olivia E. Rasmussen andLouise J. Dahlmo page intentionally left blank viiContents OverviewFigures xixTables xxiExamples xxiiiForeword xxviiPreface xxix1 Basics of java Programming 12

5 Language Fundamentals 273 Declarations 474 Access Control 955 Operators and Expressions 1436 Control Flow 1997 Object-Oriented Programming 2638 Fundamental Classes 3419 Object Lifetime 38310 The ArrayList<E> Class and Lambda Expressions 41311 Date and Time 461viiiCONTENTS OVERVIEWA Taking the java SE 8 programmer I Exam 507B Exam Topics: java SE 8 programmer I 515C Annotated Answers to Review Questions 519D Solutions to Programming Exercises 553E Mock Exam: java SE 8 programmer I 571F Annotated Answers to Mock Exam I 605 Index 619ixContentsFigures xixTables xxiExamples xxiiiForeword xxviiPreface xxix1 Basics of java Members: Fields and Instantiation, Reference Values, and References4 Object Members6 Invoking.

6 Aggregation and of Java13 Review java Application16 Essential Elements of a java Application16 Compiling and Running an Output18 Formatted java Ecosystem21 Object-Oriented Paradigm22 Interpreted: The JVM23 Architecture-Neutral and Portable Bytecode23 Simplicity23 Dynamic and Distributed23 Robust and Secure24 High Performance and Multithreaded24 Review Questions25 Chapter Summary25 Programming Exercise262 Language Language Elements28 Lexical Tokens28 Identifiers28 Keywords29 Separators29 Literals30 Integer Literals30 Floating-Point Literals31 Underscores in Numerical Literals32 Boolean Literals32 Character Literals32 String Literals34 Whitespace35 Comments35 Review Data Types37 The Integer Types38 The char Type38 The Floating-Point Types38 The boolean

7 Type39 Review Declarations40 Declaring and Initializing Variables41 Reference Values for Variables42 Default Values for Fields42 Initializing Local Variables of Primitive Data Types43 Initializing Local Reference Variables43 Lifetime of Variables44 Review Questions45 Chapter Summary46 Programming Declarations49 Statements50 Instance Methods and the Object Reference this50 Method Default Constructor54 Overloaded Constructors56 Review Array Variables59 Constructing an Array59 Initializing an Array60 Using an Array61 Anonymous Arrays63 Multidimensional Arrays64 Sorting Arrays68 Searching Arrays69 Review Passing72 Passing Primitive Data Values73 Passing Reference Values75 Passing Arrays77 Array Elements as Actual Parameters78final Arity Methods81 Calling a Variable Arity Method82 Variable Arity and Fixed Arity Method main()

8 Method85 Program Types87 Declaring Type-safe Enums87 Using Type-safe Enums88 Selected Methods for Enum Types89 Review Questions90 Chapter Summary92 Programming Exercise934 Access Source File Packages98 Using Packages99 Compiling Code into Packages105xiiCONTENTSR unning Code from for Classes107 Review Rules114 Class Scope for Members114 Block Scope for Local Modifiers for Top-Level Type Modifiers for Classes120abstract Classes120final Classes122 Review Accessibility Modifiers123public Members124protected Members126 Default Accessibility for Members127private Members128 Review Modifiers for Members131static Members132final Members133abstract Methods136synchronized Methods136native Methods137transient Fields138volatile Fields139 Review Questions140 Chapter Summary142 Programming Exercise1425 Operators and and Narrowing Primitive Conversions144 Widening and Narrowing Reference Conversions145 Boxing and Unboxing Conversions145 Other Conversion Contexts147 Assignment Context147 Method Invocation Context148 Casting Context of the Unary Type Cast Operator.

9 (type)148 Numeric Promotion and Associativity Rules for Order of Operands152 Left-Hand Operand Evaluation First152 Operand Evaluation before Operation Execution153 Left-to-Right Evaluation of Argument Integers154 Calculating Two s Complement155 Converting Binary Numbers to Decimals157 Converting Decimals to Binary Numbers157 Relationships among Binary, Octal, and Hexadecimal Simple Assignment Operator =158 Assigning Primitive Values159 Assigning References159 Multiple Assignments159 Type Conversions in an Assignment Context160 Review Operators: *, /, %, +, -163 Arithmetic Operator Precedence and Associativity164 Evaluation Order in Arithmetic Expressions164 Range of Numeric Values164 Unary Arithmetic Operators: -, +167 Multiplicative Binary Operators: *, /, %167 Additive Binary Operators: +, -169 Numeric Promotions in Arithmetic Expressions170 Arithmetic Compound Assignment Operators: *=, /=, %=, +=, -=172 Review Binary String Concatenation Operator + Increment and Decrement Operators: ++, --176 The Increment Operator ++176 The Decrement Operator --176 Review Operators: <, <=, >, >= Data Value Equality.

10 ==, !=181 Object Reference Equality: ==, !=182 Object Value Logical Operators: !, ^, &, |184 Operand Evaluation for Boolean Logical Operators185 Boolean Logical Compound Assignment Operators: &=, ^=, |= Operators: &&, ||186 Short-Circuit Bitwise Operators: ~, &, |, ^189 Bitwise Compound Assignment Operators: &=, ^=, |=192 Review Conditional Operator: ? Operators: new, [], instanceof, ->195 Review Questions196 Chapter Summary197 Programming Exercise197xivCONTENTS6 Control of Control Flow Statements200 The Simple if Statement200 The if-else Statement201 The switch Statement203 Review Statements213 The while Statement213 The do-while Statement214 The for(;;) Statement215 The for(:) Statements219 Labeled Statements220 The break Statement221 The continue Statement223 The return Statement


Related search queries