Index
A access modifiers, 60 class, 56 Abstract Window Toolkit (AWT), fields, 56 9, 14, 420–422 JAR, 58 Access modifiers library, 59 compilation error, 62 methods, 56 member-level accessors, 60, 63 modules, 60 package-private modifier, 61 package-info.java, 57 public class, 60 top-level, 60 anonymous class, 285 C anyMatch(..) method, 309 Checked exceptions, 143–144 Apache Tomcat, 577 Classes Arrays, 92 abstraction Assignment operator (=), 209–210 Actor class, 123 AudioType, 299 Human class, 121–122 Java compiler error, 122 Musician class, 123 B parent class/superclass, 122 Binary operators, 217 subclass, 122 Binary representation, 168–169 UML diagram, IntelliJ Binary serialization, 503–507 IDEA, 123–124 Bitwise operators, 227 constructors, 117–120 AND, 228, 230 data encapsulation, 111–114 NOT, 227–228 fields, 108–110 OR, 230–231 instantiation, 107–108 XOR, 231–232 methods, 115–117 Boxing, 190 variables, 110–111 Bubble sort algorithm, 256, 267 Comments, 107 Building blocks Compact String, 187
599 © Iuliana Cosmina 2018 I. Cosmina, Java for Absolute Beginners, https://doi.org/10.1007/978-1-4842-3778-6 Index
Concurrent mark sweep (CMS), 565 sorting class hierarchy, 319 Constructors System.out.print class family, 318 Actor class, 120 System.out.print method, 322–324 Human instance, 117–119 logging with JUL Musician class, 120 FileHandler class, 330 polymorphism, 119 IntelliJ IDEA, 334 return statement, 118 java.util.logging.ConsoleHandler, 329 Control flow statements java.util.logging.Level class, 336 flowchart elements, 244 java.util.logging. if-else SimpleFormatter, 329 code, 248 logging libraries, 325 flowchart, Complex if-else, 247 logging output, 331 flowchart, missing else branch, 246 log messages, 335 IntelliJ IDEA launcher, 249 MergeSort class, 326, 328 parameters, 249 SimpleFormatter, 330 using exception, 277–279 SorterJulDemo class, 326 using try catch, 277–278 SortingJulDemo class, 329, 332–333 StreamFormatter class, 329 StringBuilder, 326 D WARNING, 335, 336 Data encapsulation, 111–114 XMLFormatter, 330 Debugging SLF4J and Logback, 337 assertions ch.qos.logback.core. java.lang.AssertionError, 346–347 ConsoleAppender class, 340 rules, 348 ch.qos.logback.core.FileAppender VM options, 346 class, 341 breakpoints, 317 ch.qos.logback.core.rolling. definition, 317 RollingFileAppender, 342–343 IntelliJ IDEA breakpoints, 348–349 ch.qos.logback.core.rolling. Java tools RollingPolicy, 342 jcmd, 353–355 configuration file, XML/Groovy, 339 jconsole, 355–358 info.debug(..) logs, 339 JMC, 359–362 info.error(..) logs, 338 jps, 351–352 info.warn(..) logs, 339 logging logging implementation, 337, 339 main(..) method, 324 log.info(..) logs, 339 merge sort, 319–322 LogManager, 337 sort(..) method, 325 log.trace(..) logs, 339
600 Index
MergeSort class, 340 Gender enum, 125
601 Index
File handlers (cont.) finalize() methods, 571, 574–575, 577 getName(), 474 genSinger() methods, 572, 573 getParent(), 474 grep command, 576 IOException, 478 IntelliJ IDEA launcher, 575–576 isFile(), 473 deleting object, 587 isHidden(), 475 eden space, 562 lambda expressions, 476 Epsilon no-op collector, 565, 569 length(), 474 exceptions and causes, 595–596 list() method, 475 G1, 565, 569 listFiles(), 475 garbage first (G1), 564 pathnames, 473, 475 generations, 562 printStats(..) method, 471–472 genSinger() method, 581–582 rename(f), 478 go() method, 578 SecurityException, 477 grep method, 580, 582 String value, 471 head memory, 578, 583 URI, 474 heap structure, 561–562 FileInputStream, 489–492 Java heap and stack memory, 572–573 FileOutputStream, 499–502 java.lang.ref.Cleaner object, 584 FilterCharProcessor, 539 old generation space, 563 Finite streams, 289 Oracle Hotspot JVM flatMap(..) method, 304–305 architecture, 560–561 Flattening, 305 parallel collector, 565, 567 Floating-point types, 170 permanent generation space, 564 Flow.Processor, 549 runtime.freeMemory() method, 578 Flow.Publisher, 549 runtime.maxMemory() FlowPublisherVerification method, 578, 583
602 Index
Garbage first (G1), 565 IntelliJ IDEA, HelloWorld project generate(..) method, 290 build menu, 76 Generics, 145–147 build project option, 76 Git, 24, 38 change directory, 79 Gradle, 24, 37–38, 85 commands execution, 80 Gradle multimodule-level structure, 87–88 compile, 77, 80 Gradle project, 86, 88–89 configuration, 72 create new project option, 70–71 H directory structure, 82 HelloWorld.java file, 74, 79 Heavyweight components, 14 Java class, 75, 78–79 Hello World! class Java module, 71 class declaration, 90 Java 11 project, 71 configuration, 93–94 JRE, 78 IntelliJ IDEA editor, 89 language level, 73 java.util.List, 94 menu option, 76 main() method, 90–92, 94 modules, 73–74 package declaration, 90 move class, 82 println() method, 95, 96 object types, 76 package option, 81 I project SDK, 73 Identifiers, 106 project settings, 73 Imperative programming, 537 project view, 72 Installation refactor button, 82 Download JDK button, 26 sandbox, 72 Git, 38 src directory, 75 Gradle, 37–38 terminal button, 79 JDK 8 vs. contents comparison, 28 Interactions, Java components, 531 JDK 10 vs. JRE contents, 28 Interface Publisher
603 Index
Interfaces (cont.) portable, 8–9 default methods, 135 real applications in, 2 definition, 129 Sun Microsystems diamond class hierarchy, 130 automatic memory management, 7 marker, 129 Duke, 5 Musician and Actor classes, 129–130 Green Team, 5 normal, 129 Java logo, 7 Performer class, 129–133 logo, 6 Interface Subscriber
604 Index
start(..) methods, 435 output files, 519 Swing and AWT, 433 width and height of images, 526 TextArea, 438–439 Java Message Service (JMS), 531 Window Demo, 435–437 Java Mission Control (JMC) JAVA_HOME environment variable description, 359 on Linux, 36–37 flight recording menu and dialog on macOS, 35–36 window, 361–362 on Windows system Java Flight Recorder, 359 dialog window, 31 Memory tab, 360–361 menu item, 30 Oracle article, 362 Path variable, 33 SortingSlf4jDemo main class, 359 system variable, 32, 34 start JMX console, 359–360 Java IDE Java Native Interface (JNI), 29 GitHub user, 42–43 Java 2 Platform, Enterprise Edition IntelliJ IDEA (J2EE), 11 configure Git plugin, 41 Java 2 Platform, Micro Edition (J2ME), 11 configure Gradle plugin, 41 Java 2 Platform, Standard Edition (J2SE), 11 configure plugins dialog section, 40 Java Process API Gradle project view, 46 BufferedReader, 363 IDE Feature Trainer plugin, 42 children() method, 368 java-for-absolute-beginners creating, 362–363 project, 43–45 InputStream, 363 JetBrains, 39 JAVA_HOME environment variable, 366 Java keywords, 147–150 Linux shell commands, 367 Java Media API onExit(), 367 BaseMultiResolutionImage class, parent() method, 368 519–523 ProcessBuilder, 367–368 BufferedImage, 517 ProcessDemo class, 366 checkSize(..), 524 ProcessHandle, 364 EXIF data, 514–517 ProcessHandle.Info, 365 getResolutionVariant(), 521, 522, Java Runtime Environment (JRE), 10, 28 524–525 JavaScript Object Notation (JSON), 511–513 image classes hierarchy, 513–514 Java Server Pages (JSP), 455–456, 461, 463 image file, 514 Java Shell tool (JShell) ImageIO class, 519 code completion, 53 image storage formats, 513 defined, 49 java.awt.Graphics2D, 517–519 help, 50 java.awt.Image class, 513–514 java.lang.String, 52
605 Index
Java Shell tool (JShell) (cont.) FilterCharProcessor, 539, 542 Java statements, 55 filterCharProcessor.subscribe(..), 544 JDK, 50 Flow.Publisher
606 Index
mocks implementation, 268, 270–271 classes, 393 vs. while flowcharts, 269 createAccount(..) method, 393, 394 for findOne(..) method, 395 Arrays utility class, 263 Gradle test reports, 395–396 code, 257, 260–261 @InjectMocks and @Mock, condition, 259–260 394–395 enhanced syntax, 262 libraries, 395 flowchart, 258 objects and variables, 395 square brackets, 258 PowerMock, 393 Loops, breaking pseudo test class, 375–376 break statement, 271–273 execution, 377 continue statement, 271, 273–274 junit-platform.properties, 376 return statement, 271, 275–276 menu option, IntelliJ IDEA, 377 testOne() method, 378 stubs M AccountServiceImpl, 384 Maven repository, 85 assertThrows, 389–392 Member-level accessors, 63 createAccount(...) Methods, 115–117 method, 385–386 Module descriptor, 64 option field, 388 Module hell, 60 repo stub, 387–388 Modules returned values and compile, manually, 84 exceptions, 386 defined, 64 test coverage, 387 directives, 67 testNonNumericAmountVersion IDE generate, 83 One() method, 389, 390 Java 9 project, 65, 66 write test, 388–389 Java 10, 67 @Test, 375 java--list-modules, 66 JDK, 64 keywords, 67–68 L limit access, 69 Lambda expression, 95 module-info.class descriptor, 84 Last In, First Out (LIFO), 154 module-info.java, 64, 68 Lazy loading, 178 public types, 68 Looping statements, 257 requires keyword, 68 do-while SimpleReader class, 65 code block execution, 268 Modulus operator, 222
607 Index N parallelStream() method, 286 Path handlers NetBeans, 23 compareTo(..) method, 479 NG reactive publisher, 551 createFile(...), 482 Non-blocking back-pressure, 534 delete(..), 482 NullPointerException, 283 getFileName(), 480 Numerical operators, 214 getFileSystem(), 480 getRoot(), 480 O IOException, 482 Object types java.nio.file.Path, 478 classes (see Classes) Paths.get(fileURI), 478–479 enums, 125–128 properties, 481 interfaces (see Interfaces) resolve(..), 480 Operators sample code, 481 assignment, 209–210 toAbsolutePath(), 480 category, 207–208 peek(..) method, 308, 310 explicit conversion, 211–213 Performer hierarchy, 211 numerical Point-to-point (p2p) messaging binary, 217, 219–223 model, 531 Elvis operator, 241 Polymorphism, 119 logical, 233–237 Primitive data types negation, 216 binary representation, 168–169 relational, 223, 225–226 boolean type, 165–166 shift, 238, 240–241 byte, 169 sign, 215–216 char type, 166–167 unary, 214–215 = (equals) operator, 159 Oracle, 55 float and double, 170–171 JavaFX 2.0, 16 int, 169 Java SE 7, 15–16 integer primitives, 167 Java SE 8, 16–17 long, 170 Java SE 9, 17–18 numeric types, 167–168 Java SE 10, 19 numeric values, 171, 173 Java SE 11, 20 real primitives, 170–171, 173 short, 169 stack, 160–161 P, Q swap() method, 160 Package, 56, 81 Project Jigsaw, 64 Parallel collector, 565 Project reactor
608 Index
advantage, 552 hierarchy, 488 empty() method, 556 java.io.Closeable interface, 486 Flux and Mono, 556 lambda expressions, 487 flux publisher implementation, 553 nullReader(), 489 interval(..) method, 557 StringBuilder, 488 JDK-based implementation, 557 Scanner class, 482 operators, 552 utility methods, 484 org.reactivestreams. Reading user data Subscriber
609 Index
Reference data types (cont.) from arrays, 287, 289 escaping characters, 187 collection interfaces and heap, 161–163 classes, 284 java.lang.Thread class, 201–202 empty streams, 289 lambda expressions, 205 finite streams, 289 run() method, 202 IntStream instance, 292–293 CounterRunnable code, 205 LongStream instances, 293 runnable code, 204–205 stream of primitives, 292 stack and heap memory, 174–176 stream of strings, 294 start() method, 203 debugging, code, 310 string, 183 anyMatch(..), 309–310 swap() method, 163–165 findAny(), 309–310 Thread.currentThread() method, 205 peek(..), 310 thread management, 206 dropWhile, 292 wrapper classes, 189 functions, 282 Regression tests, 371 interfaces, 293 Run-time polymorphism, 119 intermediate operation add(..), 289 allMatch(..), 309–310 S anyMatch(..) method, 309 Serial collector, 564 collect(..) method, 303 Serialization, 502 count(), 306 binary, 503–507 distinct() method, 306 JSON, 511–513 filter(..) method, 302 XML, 507–511 findAny(), 309–310 sorted() operation, 313 findFirst(), 306 Stack and heap memory flatMap(..) method, 304–305 add() method, 157 limit(..) method, 307 definition, 153–154 map(..) method, 303 java.lang.String class, 154 noneMatch, 310 JVM parameters, 154 Optimal
610 Index
limit, 289–290, 307 getValueIsAdjusting(), 429 NullPointerException, 283 java.awt.BorderLayout, 425–426 Optimal, 309 java.awt.event.ActionListener, 427 Optional, 283, 295–298, 303–306, 309 javax.swing.JFrame, 423 parallel data processing, 282 JComponent, 425 range, 293 JFrame, 424–425 rangeClosed, 293 JFrame.EXIT_ON_CLOSE, 424 Stream, 281–294, 298–300 JList
611 Index
Testing (cont.) SampleServlet, 461–462 TDD, 371 servers, 450 unit tests, 371 servlets and JSP, 455–456 Thread local allocation buffer structure, 460–461 (TLAB), 570 URL, context path value, 454–455 toBinaryString method, 227 urlPattern property, 457 @WebServlet, 458–459 Writing files U, V Files.write(..), 493–494 Unboxing, 190 Files.write(Path, byte[]), 492 Unchecked exceptions, 143 Files.writeString(..), 493 Uniform Resource Identifier (URI), 474 OutputStream, 499–502 Unit tests, 371 Writer class BufferedWriter, 495, 498 W Files.newBufferedWriter(..), 497 flush() method, 495 Web application hierarchy, 498 Apache Tomcat server, 451 nullWriter(), 499 DateServlet, 467–468 OutputStreamWriter, 499 embedded Tomcat server, 453–454 PrintWriter, 499 HttpServletRequest, 457–458 String instances, 495, 496 index.jsp page, 463–466 StringWriter, 499 Internet, 451 JavaScript, 468 javax.servlet.http.HttpServlet, 456–457 X, Y JSP scriptlets, directive tags, 463 XML serialization, 507–511 JSTL, 465–466 network debugger view, Firefox, 452 request method, 452–453 Z resource/dynamic directory, 461 zipWith(..) method, 557
612