Skip to main content
main-content

Über dieses Buch

This easy-to-follow textbook teaches Java programming from first principles, as well as covering design and testing methodologies. The text is divided into two parts. Each part supports a one-semester module, the first part addressing fundamental programming concepts, and the second part building on this foundation, teaching the skills required to develop more advanced applications.

This fully updated and greatly enhanced fourth edition covers the key developments introduced in Java 8, including material on JavaFX, lambda expressions and the Stream API.

Topics and features: begins by introducing fundamental programming concepts such as declaration of variables, control structures, methods and arrays; goes on to cover the fundamental object-oriented concepts of classes and objects, inheritance and polymorphism; uses JavaFX throughout for constructing event-driven graphical interfaces; includes advanced topics such as interfaces and lambda expressions, generics, collection classes and exceptions; explains file-handling techniques, packages, multi-threaded programs, socket programming, remote database access and processing collections using streams; includes self-test questions and programming exercises at the end of each chapter, as well as two illuminating case studies; provides additional resources at its associated website (simply go to springer.com and search for "Java in Two Semesters"), including a guide on how to install and use the NetBeans™ Java IDE.

Offering a gentle introduction to the field, assuming no prior knowledge of the subject, Java in Two Semesters is the ideal companion to undergraduate modules in software development or programming.

Inhaltsverzeichnis

Frontmatter

Semester One

Frontmatter

Chapter 1. The First Step

Abstract
By the end of this chapter students should be able to:
  • explain the meaning of the terms software, program, source code, program code;
  • distinguish between application software and system software;
  • explain how Java programs are compiled and run;
  • provide examples of different types of java applications;
  • write Java programs that display text on the screen;
  • join messages in output commands by using the concatenation (+) operator;
  • add comments to programs.
Quentin Charatan, Aaron Kans

Chapter 2. Building Blocks

Abstract
Outcomes:
By the end of this chapter you should be able to:
  • distinguish between the eight built-in primitive types of Java;
  • declare and assign values to variables;
  • create constant values with the keyword final;
  • use the input methods of the Scanner class to get data from the keyboard;
  • design the functionality of a method using pseudocode.
Quentin Charatan, Aaron Kans

Chapter 3. Selection

Abstract
Outcomes:
By the end of this chapter you should be able to:
  • explain the difference between sequence and selection;
  • use an if statement to make a single choice in a program;
  • use an if…else statement to make a choice between two options in a program;
  • use nested if…else statements to make multiple choices in a program;
  • use a switch statement to make multiple choices in a program.
Quentin Charatan, Aaron Kans

Chapter 4. Iteration

Abstract
By the end of this chapter students should be able to:
  • explain the term iteration;
  • repeat a section of code with a for loop;
  • repeat a section of code with a while loop;
  • repeat a section of code with a do…while loop;
  • select the most appropriate loop for a particular task;
  • use a breakstatement to terminate a loop;
  • use a continue statement to skip an iteration of a loop;
  • explain the term input validation and write simple validation routines.
Quentin Charatan, Aaron Kans

Chapter 5. Methods

Abstract
By the end of this chapter students should be able to:
  • explain the meaning of the term method;
  • declare and define methods;
  • call a method;
  • explain the meaning of the terms actual parameters and formal parameters;
  • devise simple algorithms with the help of pseudocode;
  • identify the scope of a particular variable;
  • explain the meaning of the term polymorphism;
  • declare and use overloaded methods.
Quentin Charatan, Aaron Kans

Chapter 6. Arrays

Abstract
By the end of this chapter students should be able to:
  • create arrays;
  • use for loops to process arrays;
  • use an enhanced for loop to process an array;
  • use arrays as method inputs and outputs;
  • use arrays to send a variable number of arguments to a method;
  • develop routines for accessing and manipulating arrays;
  • distinguish between one-dimensional arrays and multi-dimensional arrays;
  • create and process two-dimensional arrays
  • create ragged arrays
Quentin Charatan, Aaron Kans

Chapter 7. Classes and Objects

Abstract
By the end of this chapter students should be able to:
  • explain the meaning of the term object-oriented;
  • explain and distinguish between the terms class and object;
  • create objects in Java;
  • call the methods of an object;
  • use a number of methods of the String class;
  • create and use arrays of objects;
  • create an ArrayLis t and make use of the add and get methods of this class.
Quentin Charatan, Aaron Kans

Chapter 8. Implementing Classes

Abstract
By the end of this chapter students should be able to:
  • design classes using the notation of the Unified Modeling Language (UML);
  • write the Java code for a specified class;
  • explain the difference between public and private access to attributes and methods;
  • explain the meaning of the term encapsulation;
  • explain the use of the static keyword;
  • pass objects as parameters;
  • develop their own collection classes in Java;
  • identify the advantages of object-oriented programming.
Quentin Charatan, Aaron Kans

Chapter 9. Inheritance

Abstract
By the end of this chapter students should be able to:
  • explain the term inheritance;
  • design inheritance structures using UML notation;
  • implement inheritance relationships in Java;
  • distinguish between method overriding and method overloading;
  • explain the term type cast and implement this in Java;
  • explain the use of the abstract modifier when applied to classes and methods;
  • explain the use of the final modifier, when applied to classes and methods;
  • describe the way in which all Java classes are derived from the Object class.
Quentin Charatan, Aaron Kans

Chapter 10. Introducing JavaFX

Abstract
By the end of this chapter students should be able to:
  • briefly describe the history of graphics programming in Java;
  • explain the structure and life cycle of a JavaFX application;
  • produce 2D graphical shapes in JavaFX;
  • build an interactive graphics application in JavaFX using common components such as buttons, textfields and labels;
  • program a JavaFX control to listen for events using a lambda expression;
  • make use of a variety of different JavaFX containers;
  • create borders, fonts and colours;
  • format decimal numbers so that they appear in an appropriate form in a graphics application.
Quentin Charatan, Aaron Kans

Chapter 11. Case Study—Part 1

Abstract
By the end of this chapter students should be able to:
  • describe each stage of the software development process;
  • design a complete application using UML;
  • implement a detailed UML design in Java;
  • document their code using Javadoc comments;
  • distinguish between unit testing and integration testing;
  • test individual program units by creating suitable drivers;
  • document their test results professionally using a test log.
Quentin Charatan, Aaron Kans

Chapter 12. Case Study—Part 2

Abstract
By the end of this chapter students should be able to:
  • design an attractive graphical user interface;
  • use pseudocode to design event handling routines;
  • implement the design in Java using a variety of JavaFX components;
  • devise a testing strategy for a complete application and carry out the necessary steps to implement that strategy.
Quentin Charatan, Aaron Kans

Semester Two

Frontmatter

Chapter 13. Interfaces and Lambda Expressions

Abstract
By the end of this chapter students should be able to:
  • explain what is meant by the term interface in Java
  • create and use their own interfaces
  • implement inner classes and anonymous classes
  • explain the purpose and the importance of lambda expressions in Java
  • describe the syntax of lambda expressions, and utilize these expressions in a variety of contexts
  • create and use generic classes and interfaces
  • create generic classes and interfaces containing upper bounded parameters
  • utilize wildcards in conjunction with generic types
  • describe how a programming language can support polymorphic types
  • summarize the ways in which polymorphism can be achieved in Java.
Quentin Charatan, Aaron Kans

Chapter 14. Exceptions

Abstract
By the end of this chapter students should be able to:
  • explain the term exception;
  • distinguish between checked and unchecked exception classes in Java;
  • claim an exception using a throws clause;
  • throw an exception using a throw command;
  • catch an exception in a try…catch block;
  • use a finally block or a try-with-resources construct to deal with clean-up issues;
  • use the Optional class to avoid NullPointerException errors;
  • define and use their own exception classes
Quentin Charatan, Aaron Kans

Chapter 15. The Java Collections Framework

Abstract
Outcomes:
By the end of this chapter you should be able to:
  • use the ArrayList class to store a list of objects;
  • use the HashSet class to store a set of objects;
  • use the HashMap class to store objects in a map;
  • use the enhanced for loop and a forEach loop to scan through a collection;
  • use an Iterator object to scan through a collection;
  • create objects of your own classes, and use them in conjunction with Java’s collection classes;
  • sort elements in a collection using the Comparable <T>  and Comparator <T>  interfaces.
Quentin Charatan, Aaron Kans

Chapter 16. Advanced JavaFX

Abstract
By the end of this chapter you should be able to:
  • program components to respond to mouse events and key events;
  • explain the term property as applied to JavaFX components;
  • bind properties of two or more components;
  • use a slider to change the value of a variable;
  • embed images, videos and webpages in applications;
  • format applications by using cascading style sheets.
Quentin Charatan, Aaron Kans

Chapter 17. JavaFX: Interacting with the User

Abstract
By the end of this chapter students should be able to:
  • create applications that utilize pull-down menus and context menus;
  • create a modal dialogue by defining a secondary stage;
  • write applications that offer choices via combo boxes, check boxes and radio buttons;
  • use a stack pane to create a card menu;
  • enable user interaction by using the subclasses of the Dialog class.
Quentin Charatan, Aaron Kans

Chapter 18. Working with Files

Abstract
By the end of this chapter students should be able to:
  • explain the principles of input and output and identify a number of different input and output devices;
  • explain the concept of an I/O stream;
  • describe the basic file-handling techniques used in the Java language;
  • distinguish between text, binary and object encoding of data;
  • distinguish between serial access files and random access files;
  • create and access files in Java using all the above encoding and access methods.
Quentin Charatan, Aaron Kans

Chapter 19. Packages

Abstract
By the end of this chapter students should be able to:
  • identify the role of packages in organizing classes;
  • create and deploy their own packages in Java;
  • access classes residing in their own packages;
  • run Java applications from the command line;
  • deploy Java applications as JAR files;
  • access libraries that are not part of the standard Java framework to access data on a remote database using the Java Database Connectivity (JDBC) and Hibernate ORM technologies.
Quentin Charatan, Aaron Kans

Chapter 20. Multi-threaded Programs

Abstract
Outcomes:
By the end of this chapter students should be able to:
  • explain how concurrency is achieved by means of time-slicing;
  • distinguish between threads and processes;
  • implement threads in Java;
  • explain the difference between asynchronous and synchronized thread execution;
  • explain the terms critical section and mutual exclusion, and describe how Java programs can be made to implement these concepts;
  • explain how busy waiting can be avoided in Java programs;
  • provide a state transition diagram to illustrate the thread life-cycle;
  • describe how the javafx.concurrent package is used to produce multithreaded JavaFX applications;
  • use the Task class and the Service class from the above package in JavaFX applications;
  • use the above classes to create animated applications in JavaFX.
Quentin Charatan, Aaron Kans

Chapter 21. Advanced Case Study

Abstract
By the end of this chapter you should be able to:
  • specify system requirements by developing a use case model;
  • annotate a composition association on a UML diagram;
  • specify enumerated types in UML and implement them in Java;
  • develop test cases from behaviour specifications found in the use case model;
  • use the TabPane class to create an attractive user interface;
  • add tool tips to JavaFX components.
Quentin Charatan, Aaron Kans

Chapter 22. The Stream API

Abstract
By the end of this chapter students should be able to:
  • explain the term stream in the context of the java stream API;
  • identify the advantages of stream processing over iteration;
  • describe the three stages involved in processing a stream;
  • explain what is meant by lazy evaluation;
  • create streams from scratch, from collections and from files;
  • use a variety of intermediate methods to process streams;
  • use appropriate methods to terminate streams;
  • explain the difference between stateless and stateful operations;
  • explain how streams can be created in parallel mode;
  • identify the possible pitfalls with parallel stream processing and explain how to avoid them.
Quentin Charatan, Aaron Kans

Chapter 23. Working with Sockets

Abstract
By the end of this chapter students should be able to:
  • explain the terms client, server, host and port;
  • describe the client–server model;
  • explain the function of a socket;
  • distinguish between the Java Socket and ServerSocket classes and explain their function;
  • write a simple client–server application using sockets;
  • write a server application that supports multiple clients;
  • write multi-threaded client-server applications;
  • create client and server applications that utilise a JavaFX interface.
Quentin Charatan, Aaron Kans

Chapter 24. Java in Context

Abstract
By the end of this chapter students should be able to:
  • provide a brief history of the development of the Java language;
  • identify the potential problems with pointers, multiple inheritance and aliases;
  • develop clone methods and copy constructors to avoid the problem of aliases;
  • identify immutable objects;
  • explain the benefits of Java’s garbage collector.
Quentin Charatan, Aaron Kans

Backmatter

Weitere Informationen

Premium Partner

    Bildnachweise