concept option in category java

appears as: Option, Options, options, n option, The option, option, The options, OPTIONS
Java SE 11 Programmer I Certification Guide

This is an excerpt from Manning's book Java SE 11 Programmer I Certification Guide.

Explanation: (a) is incorrect because JRE is an implementation of JVM. (b) is incorrect because JRE is specific to a platform and OS. Unlike a JVM it is not for a virtual machine. Option (d) is incorrect because JDK is a superset of JRE.

Hence, option (d) is incorrect. Because class Test doesn’t define any instance methods, the only way that the question’s line of code can execute is when a method parameter movable is passed to the method walk.

Option (a) is correct. Because the interface Movable defines the method move, you can pass a variable of its type to the method move.

Option (b) is correct. Because the class Person implements the interface Movable and defines the method move, you can pass a variable of its type to the method walk. With this version of the method walk, you can pass it an object of the class Person or any of its subclasses.

Option (c) is correct. Because the class Vehicle implements the interface Movable and defines the method move, you can pass a variable of its type to the method walk. With this version of method walk, you can pass it an object of the class Vehicle or any of its subclasses.

The Java Module System

This is an excerpt from Manning's book The Java Module System.

The option--add-modules ${modules}, available on javac and java, takes a comma-separated list of module names and defines them as root modules beyond the initial module. (As explained in section 3.4.1, root modules form the initial set of modules from which the module graph is built by resolving their dependencies.) This enables users to add modules (and their dependencies) to the module graph that would otherwise not show up because the initial module doesn’t directly or indirectly depend on them.

Chapters 6, 7, and 8 discuss the technical details behind migrating to Java 9+ and turning an existing code base into a modular one. This chapter takes a broader view and looks at how to best compose these details into successful migration and modularization efforts. We’ll first discuss how to perform a gradual migration that cooperates well with the development process, particularly build tools and continuous integration. Next, we’ll look at how to use the unnamed module and automatic modules as building blocks for specific modularization strategies. And finally, we’ll cover options for making JARs modular—yours or your dependencies’. When you’re done with this chapter, you’ll not only understand the mechanisms behind migration challenges and modularization features—you’ll also know how to best employ them in your efforts.

OCA Java SE 8 Programmer I Certification Guide

This is an excerpt from Manning's book OCA Java SE 8 Programmer I Certification Guide.

Explanation: Options (a) and (b) are incorrect.

Option (c) is correct because a Java source code file can define multiple interfaces and classes.

Option (d) is correct because a public interface or class can be defined in a Java source code file with a matching name. The public interface Printable can’t be defined in the Java source code file, Multiple.java. It must be defined in Printable.java.

  • 10.0
    false
    false
  • Functional Programming in Java: How functional techniques improve your Java programs

    This is an excerpt from Manning's book Functional Programming in Java: How functional techniques improve your Java programs.

    You might have trouble understanding some parts of the code presented in this chapter. That’s to be expected, because it’s very difficult to introduce functions without using other functional constructs such as List, Option, and others. Be patient. All the unexplained components will be discussed in the following chapters.

    In this listing, you can see how close Option is to List. They’re both abstract classes with two private implementations. The None subclass corresponds to Nil and the Some subclass to Cons. The getOrThrow method is similar to the head method in List.

    You can use Option for your definition of the max function, as shown here:

    static <A extends Comparable<A>> Function<List<A>, Option<A>> max() {
      return xs -> xs.isEmpty()
          ? Option.none()
          : Option.some(xs.foldLeft(xs.head(),
                        x -> y -> x.compareTo(y) > 0 ? x : y));
    }

    Now your function is a total function, which means it has a value for all lists, including the empty one. Note how similar this code is to the version returning a list. Although the implementation of Option is different from the List implementation, its usage is nearly the same. As you’ll see soon, the similarity extends much further.

    But as it is, the Option class isn’t very useful. The only way to use an Option would be to test the actual class to see if it’s a Some or a None, and call the getOrThrow method to obtain the value in the former case. And this method will throw an exception if there’s no data, which isn’t very functional. To make it a powerful tool, you’ll need to add some methods, in the same way you did for List.

    As an example, look at how the Option class can be used to change the way you use a map. Listing 6.2 shows the implementation of a functional Map. This is not a functional implementation, but only a wrapper around a legacy ConcurrentHashMap to give it a functional interface.

    Listing 6.2. Using Option in a functional Map

    As you can see, Option allows you to encapsulate into the map implementation the pattern for querying the map with containsKey before calling get. The following listing shows how this is intended to be used.

    Listing 6.3. Putting Option to work

    In this (very simplified) program, you can see how various functions returning Option can be composed. You don’t have to test for anything, and you don’t risk a NullPointer-Exception, although you may be asking for the email of a Toon that doesn’t have one, or even for a Toon that doesn’t exist in the map.

    6.5. How and when to use Option

    As you may know, Java 8 has introduced the Optional class that may be seen by some as identical to your Option, although it’s not implemented in the same way at all, and it lacks most of the functional methods you’ve put into Option. There’s much controversy about whether the new features of Java 8 are a move toward functional programming. They certainly are, although this is not official. The official position is that Optional is not a functional feature.

    Portlets in Action

    This is an excerpt from Manning's book Portlets in Action.

    A guest user (an unauthenticated user) in Liferay Portal will see an option to sign in at the top-right corner of the home page, as shown in figure 1.13.

    Figure 1.13. The Sign In option on the Liferay Portal home page

    Clicking on the Sign In option will display a Sign In page. Because you don’t have an account with Liferay Portal when you access it for the first time, you can select the Create Account option (as shown in figure 1.14).

    Figure A.2. The GateIn Portal home page. The Administrator option allows you to log in to the GateIn Portal as an administrator. The Sign In option allows you to provide your own login credentials to log in.

    To log in to the GateIn Portal, you can either choose the Sign In option at the top of the home page or you can log in as one of the predefined users in the system: Administrator, Manager, User, or Demo.

    GWT in Practice

    This is an excerpt from Manning's book GWT in Practice.

    From the GWT shell console GUI, you also have the option to invoke the hosted mode browser. The hosted mode browser is what allows you to explore your Java application using a browser and browser-based events.

    Figure 9.1. The Create-Read-Update-Delete application for our bookstore. Many-to-many relationships between the authors and categories are maintained with select boxes and options to create new entries.

    This appendix provides a set of GWT quick-reference items. The main sections are tools and options, module and host-page configuration elements, supported JRE emulation classes, serializable type information, common UI elements and properties, and event-handling interfaces. You should find this to be a useful quick reference for commonly needed GWT information.