Getting Started With Java Using Eclipse

Mastering the Language and the Development Platform

By Bernhard Steppan

This is an Elektor Publication. Elektor is the media brand of Elektor International Media B.V.

PO Box 11, NL-6144-ZG, Susteren, The Netherlands.

Telephone: +31 46 4389444

All information, procedures and illustrations contained in this book have been prepared to the best of our knowledge and tested with care. Nevertheless, errors cannot be completely ruled out. For this reason, the information contained in this book is not associated with any obligation or guarantee of any kind. Consequently, the authors and publishers assume no responsibility and will not accept any liability, consequential or otherwise, arising in any way from the use of this program material or any part thereof. Likewise, authors and publishers do not guarantee that described procedures etc. are free of third party intellectual property rights. The reproduction of common names, trade names, product designations, etc. in this work does not justify the assumption that such names are to be considered free in the sense of trademark and brand protection legislation and may therefore be used by anyone, even without special identification.

British Cataloguing in Publication Data

A catalogue record for this book is available at the British library.

This work is protected by copyright. All rights reserved, including those of translation, reprint and reproduction of the book or parts thereof. No part of this work may be reproduced in any form (photocopy, microfilm or any other process), not even for the purpose of teaching - with the exception of the special cases mentioned in §§ 53, 54 URG -, or processed, copied or distributed using electronic systems without the written permission of the publisher.

© Copyright 2023: Elektor International Media B.V., www.elektor.com

Prepress Production: Bernard Steppan

Editors: Alina Neacsu; Jan Buiting


Contents

Part I Basics

1 Programming Basics

  1. 1.1 Introduction
  2. 1.2 The Language of the Machine World
  3. 1.3 High-Level Programming Languages
  4. 1.4 Development Environment
    • 1.4.1 Compiler
    • 1.4.2 Editor
    • 1.4.3 Project Management
  5. 1.5 Runtime Environment
  6. 1.6 Summary
  7. 1.7 Literature
  8. 1.8 Exercises

2 Technology Overview

  1. 2.1 Introduction
  2. 2.2 Overview
    • 2.2.1 The Early Days of Java
    • 2.2.2 The Growth Period of Java
    • 2.2.3 The Presence And Future of Java
  3. 2.3 Why Java?
    • 2.3.1 Easy to Read
    • 2.3.2 Object-Oriented
    • 2.3.3 Safe And Robust
    • 2.3.4 Very Powerful
    • 2.3.5 Universally Useable
    • 2.3.6 Free of Charge
    • 2.3.7 Open Source
    • 2.3.8 Easily Portable
    • 2.3.9 Easily Expandable
    • 2.3.10 Easy to Develop And Test
  4. 2.4 What Belongs to Java?
    • 2.4.1 Java Programming Language
    • 2.4.2 Java Virtual Machine
    • 2.4.3 Java Class Libraries
    • 2.4.4 Java Development Tools
  5. 2.5 Java Versions
  6. 2.6 Java Editions
    • 2.6.1 Java Standard Edition
    • 2.6.2 Java Enterprise Edition
    • 2.6.3 Java Micro Edition
  7. 2.7 Summary
  8. 2.8 Literature
  9. 2.9 Exercises

3 Object-Oriented Programming

  1. 3.1 Introduction
  2. 3.2 Overview
  3. 3.3 Object
  4. 3.4 Class
    • 3.4.1 Properties
    • 3.4.2 Methods
  5. 3.5 Abstraction
  6. 3.6 Inheritance
    • 3.6.1 Base Classes
    • 3.6.2 Derived Classes
    • 3.6.3 Multiple Inheritance
  7. 3.7 Access Protection
  8. 3.8 Relationships
    • 3.8.1 Relationships Without Inheritance
    • 3.8.2 Inheritance Relationships
  9. 3.9 Design Flaws
  10. 3.10 Refactoring
  11. 3.11 Modeling
  12. 3.12 Persistence
  13. 3.13 Polymorphism
    • 3.13.1 Static Polymorphism
    • 3.13.2 Dynamic Polymorphism
  14. 3.14 Design Rules
  15. 3.15 Summary
  16. 3.16 Literature
  17. 3.17 Exercises

4 Development Environment

  1. 4.1 Introduction
  2. 4.2 Installation
    • 4.2.1 Operating System
    • 4.2.2 Install Java
    • 4.2.3 Install Eclipse
    • 4.2.4 Install Sample Programs
    • 4.2.5 Installation Check
  3. 4.3 Eclipse Introduction
    • 4.3.1 Overview
    • 4.3.2 Workbench
    • 4.3.3 Perspectives, Views and Editors
    • 4.3.4 Package Explorer
    • 4.3.5 Java Editor
    • 4.3.6 Code Formatter
    • 4.3.7 Build System
    • 4.3.8 Debugger
    • 4.3.9 Modular Structure
    • 4.3.10 Eclipse Workspace
    • 4.3.11 Software Update
    • 4.3.12 Help System
  4. 4.4 Summary
  5. 4.5 Literature
  6. 4.6 Exercises

Part II Java Language

5 Program Structure

  1. 5.1 Introduction
  2. 5.2 Overview
  3. 5.3 Language Elements
    • 5.3.1 Comments
    • 5.3.2 Packages
    • 5.3.3 Classes
    • 5.3.4 Methods
    • 5.3.5 Statements
  4. 5.4 Structure of the Program
  5. 5.5 Program Flow
  6. 5.6 Reserved Keywords
  7. 5.7 Summary
  8. 5.8 Tutorial
  9. 5.9 Exercises

6 Variables

  1. 6.1 Introduction
  2. 6.2 Overview
    • 6.2.1 Variable Purpose
    • 6.2.2 Variable Types
    • 6.2.3 Variable Usage
  3. 6.3 Local Variables
  4. 6.4 Parameters
  5. 6.5 Instance Variables
    • 6.5.1 Individual Instance Variables
    • 6.5.2 Instance Variable »this«
  6. 6.6 Class Variables
  7. 6.7 Constants
  8. 6.8 Summary
  9. 6.9 Literature
  10. 6.10 Tutorial
  11. 6.11 Exercises

7 Statements

  1. 7.1 Introduction
  2. 7.2 Overview
    • 7.2.1 Statement Purpose
    • 7.2.2 Statement Types
  3. 7.3 Declaration
  4. 7.4 Assignment
    • 7.4.1 Java Assignment Structure
    • 7.4.2 Java Assignments Are Not Equal to Mathematical Equations
    • 7.4.3 Is x = y Equal to y = x?
    • 7.4.4 Combination of Declaration and Value Assignment
  5. 7.5 Block
  6. 7.6 Variable Call
  7. 7.7 Method Call
  8. 7.8 Summary
  9. 7.9 Literature
  10. 7.10 Tutorial
  11. 7.11 Exercises

8 Primitive Data Types

  1. 8.1 Introduction
  2. 8.2 Overview
    • 8.2.1 Purpose of Primitive Data Types
    • 8.2.2 Types of Primitive Data Types
    • 8.2.3 Use of Primitive Data Types
  3. 8.3 Integer Data Types
    • 8.3.1 Data Type »byte«
    • 8.3.2 Data Type »short«
    • 8.3.3 Data Type »int«
    • 8.3.4 Data Type »long«
  4. 8.4 Floating Point Data Types
    • 8.4.1 Data Type »float«
    • 8.4.2 Data Type »double«
  5. 8.5 Character Data Type
  6. 8.6 Boolean Data Type
  7. 8.7 Summary
  8. 8.8 Literature
  9. 8.9 Tutorial
  10. 8.10 Exercises

9 Classes and Objects

  1. 9.1 Introduction
  2. 9.2 Overview
    • 9.2.1 Purpose of a Class
    • 9.2.2 Types of Classes
    • 9.2.3 Definition of Classes
    • 9.2.4 Use of Classes
  3. 9.3 Anonymous Classes
    • 9.3.1 Definition of Concrete Classes
    • 9.3.2 Creation of Objects of a Concrete Class
    • 9.3.3 Inner Classes
    • 9.3.4 Local Classes
    • 9.3.5 Anonymous Classes
    • 9.3.6 Inheritance
  4. 9.4 Abstract Classes
  5. 9.5 Interfaces
  6. 9.6 Generics
    • 9.6.1 Definition of Generic Classes
    • 9.6.2 Creation of Generic Objects
  7. 9.7 Summary
  8. 9.8 Literature
  9. 9.9 Tutorial
  10. 9.10 Exercises

10 Enumerations

  1. 10.1 Introduction
  2. 10.2 Overview
    • 10.2.1 Purpose of Enums
    • 10.2.2 Definition And Declaration of Enums
    • 10.2.3 Usage of Enums
  3. 10.3 Enum Classes
    • 10.3.1 Constructor
    • 10.3.2 Method »value()«
    • 10.3.3 Separate Simple Enum Class
    • 10.3.4 Separate Extended Enum Class
    • 10.3.5 Inner Extended Enum Class
  4. 10.4 Summary
  5. 10.5 Literature
  6. 10.6 Tutorial
  7. 10.7 Exercises

11 Arrays

  1. 11.1 Introduction
  2. 11.2 Overview
    • 11.2.1 Purpose of Arrays
    • 11.2.2 Types of Arrays
    • 11.2.3 Usage of Arrays
  3. 11.3 Summary
  4. 11.4 Tutorial
  5. 11.5 Exercises

12 Methods

  1. 12.1 Introduction
  2. 12.2 Overview
    • 12.2.1 Method Purpose
    • 12.2.2 Method Types
    • 12.2.3 Method Definition
    • 12.2.4 Method Usage
  3. 12.3 Constructors
    • 12.3.1 Default Constructors
    • 12.3.2 Constructors Without Parameters
    • 12.3.3 Constructors With Parameters
  4. 12.4 Destructors
  5. 12.5 Operations
  6. 12.6 Getter Methods
    • 12.6.1 Definition
    • 12.6.2 Usage
  7. 12.7 Setter Methods
    • 12.7.1 Definition
    • 12.7.2 Usage
  8. 12.8 Summary
  9. 12.9 Literature
  10. 12.10 Tutorial
  11. 12.11 Exercises

13 Operators

  1. 13.1 Introduction
  2. 13.2 Overview
    • 13.2.1 Operator Types
    • 13.2.2 Operator Precedence
  3. 13.3 Arithmetic Operators
    • 13.3.1 Unary Plus Operator
    • 13.3.2 Unary Minus Operator
    • 13.3.3 Addition Operator
    • 13.3.4 Subtraction Operator
    • 13.3.5 Multiplication Operator
    • 13.3.6 Division Operator
    • 13.3.7 Remainder Operator
    • 13.3.8 Pre-increment Operator
  4. 13.4 Relational Operators
    • 13.4.1 »Equal to« Operator
    • 13.4.2 »Not Equal to« Operator
    • 13.4.3 »Less Than« Operator
    • 13.4.4 »Less Than or Equal to« Operator
    • 13.4.5 »Greater Than« Operator
    • 13.4.6 »Greater Than Or Equal To« Operator
    • 13.4.7 Type Comparison Operator
  5. 13.5 Logical Operators
    • 13.5.1 Logical Complement Operator
    • 13.5.2 AND Operator
    • 13.5.3 OR Operator
    • 13.5.4 Ternary Operator
  6. 13.6 Bitwise Operators
  7. 13.7 Assignment Operators
  8. 13.8 New Operator
  9. 13.9 Cast Operator
  10. 13.10 Access Operators
    • 13.10.1 Dot Operator
    • 13.10.2 Lambda Operator
  11. 13.11 Summary
  12. 13.12 Literature
  13. 13.13 Tutorial
  14. 13.14 Exercises

14 Conditional Statements

  1. 14.1 Introduction
  2. 14.2 Overview
  3. 14.3 If Then Else<< Statement
  4. 14.4 Ternary Operator
  5. 14.5 Switch Statement
    • 14.5.1 Switch Statement at the Level of Java 6
    • 14.5.2 Switch Statement at the Level of Java 7
    • 14.5.3 Yield Statement
    • 14.5.4 Lambda Expression
  6. 14.6 Summary
  7. 14.7 Literature
  8. 14.8 Tutorial
  9. 14.9 Exercises

15 Loops

  1. 15.1 Introduction
  2. 15.2 Overview
    • 15.2.1 Purpose of Loops
    • 15.2.2 Types of Loops
  3. 15.3 While Loop
  4. 15.4 Do Loop
  5. 15.5 Simple For Loop
  6. 15.6 Extended For Loop
  7. 15.7 Summary
  8. 15.8 Literature
  9. 15.9 Tutorial
  10. 15.10 Exercises

16 Packages and Modules

  1. 16.1 Introduction
  2. 16.2 Overview
  3. 16.3 Packages
    • 16.3.1 Class Import
  4. 16.4 Modules
  5. 16.5 Summary
  6. 16.6 Tutorial
  7. 16.7 Exercises

17 Exception Handling

  1. 17.1 Introduction
  2. 17.2 Overview
    • 17.2.1 Motivation
    • 17.2.2 Types of Errors
    • 17.2.3 Use of Exception Handling
  3. 17.3 Base Class »Throwable«
  4. 17.4 Class »Error«
    • 17.4.1 Subclass »OutOfMemoryError«
    • 17.4.2 Subclass »StackOverflowError«
  5. 17.5 Class »Exception«
    • 17.5.1 Subclass »RuntimeException«
    • 17.5.2 Subclass »IOException«
    • 17.5.3 Self-Programmed Exceptions
  6. 17.6 Summary
  7. 17.7 Literature
  8. 17.8 Tutorial
  9. 17.9 Exercises

18 Documentation

  1. 18.1 Introduction
  2. 18.2 Overview
  3. 18.3 Line Comments
  4. 18.4 Block Comments
  5. 18.5 Documentation Comments
  6. 18.6 Summary
  7. 18.7 Literature
  8. 18.8 Tutorial
  9. 18.9 Exercises

19 Annotations

  1. 19.1 Introduction
  2. 19.2 Overview
    • 19.2.1 Annotation Purposes
    • 19.2.2 Annotation Types
    • 19.2.3 Predefined Annotations
    • 19.2.4 Use of Annotations
  3. 19.3 Compiler Control Annotations
    • 19.3.1 Annotations »Deprecated«
    • 19.3.2 Annotations »SuppressWarnings«
    • 19.3.3 Annotation »Override«
  4. 19.4 Summary
  5. 19.5 Literature
  6. 19.6 Tutorial
  7. 19.7 Exercises

Part III Java Technology

20 Development Processes

  1. 20.1 Introduction
  2. 20.2 Overview
    • 20.2.1 Correlation Between Phases And Activities
    • 20.2.2 Activities
    • 20.2.3 Tools
  3. 20.3 Planning Phase
    • 20.3.1 Order Clarification
    • 20.3.2 Requirements Capture
  4. 20.4 Construction Phase
    • 20.4.1 Analysis
    • 20.4.2 Design
    • 20.4.3 Implementation
    • 20.4.4 Test
  5. 20.5 Operating Phase
    • 20.5.1 Deployment
    • 20.5.2 Maintenance
  6. 20.6 Summary
  7. 20.7 Literature
  8. 20.8 Exercises

21 Runtime Environment

  1. 21.1 Introduction
  2. 21.2 Overview
  3. 21.3 Bytecode
  4. 21.4 Java Virtual Machine
    • 21.4.1 Artificial Computer
    • 21.4.2 Interpreter mode
    • 21.4.3 JIT compiler mode
    • 21.4.4 Hotspot Mode
    • 21.4.5 Garbage Collector
  5. 21.5 Libraries
    • 21.5.1 Native Libraries
    • 21.5.2 Class Libraries
    • 21.5.3 Resources And Property Files
  6. 21.6 Portability
    • 21.6.1 Binary Compatible Bytecode
    • 21.6.2 Porting Prerequisites
  7. 21.7 Program Start
    • 21.7.1 Start Script
    • 21.7.2 Native Wrapper
  8. 21.8 JVM Configuration
  9. 21.9 Summary
  10. 21.10 Literature
  11. 21.11 Exercises

22 Class Libraries

  1. 22.1 Introduction
  2. 22.2 Overview
    • 22.2.1 Areas of Application
    • 22.2.2 Reuse
    • 22.2.3 Documentation
    • 22.2.4 Language Extension
    • 22.2.5 Types of Class Libraries
  3. 22.3 Java Standard Edition
    • 22.3.1 Base Classes
    • 22.3.2 Class »System«
    • 22.3.3 Threads
    • 22.3.4 Streams
    • 22.3.5 Properties
    • 22.3.6 Container Classes
    • 22.3.7 Abstract Windowing Toolkit
    • 22.3.8 Swing
    • 22.3.9 JavaBeans
    • 22.3.10 Applets
    • 22.3.11 Java Database Connectivity (JDBC)
    • 22.3.12 Java Native Interface
    • 22.3.13 Remote Method Invocation
  4. 22.4 Java Enterprise Edition
    • 22.4.1 Entity Beans
    • 22.4.2 Session Beans
    • 22.4.3 Message Driven Beans
    • 22.4.4 Interfaces
  5. 22.5 Java Micro Edition
  6. 22.6 External Class Libraries
    • 22.6.1 Apache Software Foundation
    • 22.6.2 Eclipse Community
    • 22.6.3 SourceForge
    • 22.6.4 Other Open-Source Software
    • 22.6.5 Commercial Software
  7. 22.7 Summary
  8. 22.8 Literature
  9. 22.9 Exercises

23 Rules

  1. 23.1 Introduction
  2. 23.2 Overview
  3. 23.3 Writing Conventions
  4. 23.4 Access Protection
    • 23.4.1 Four Levels of Access Protection
    • 23.4.2 Access Level »private«
    • 23.4.3 Access Level »default«
    • 23.4.4 Access Level »protected«
    • 23.4.5 Access Level »public«
    • 23.4.6 Case Study
    • 23.4.7 Scope of Variables
  5. 23.5 Evaluation Order
    • 23.5.1 Dot Before Dash
    • 23.5.2 Dot Before Dot
  6. 23.6 Type Conversion
    • 23.6.1 Implicit Conversion
    • 23.6.2 Explicit Conversion
  7. 23.7 Polymorphism
    • 23.7.1 Method Overloading
    • 23.7.2 Method Overriding
  8. 23.8 Summary
  9. 23.9 Literature
  10. 23.10 Exercises

24 Algorithms

  1. 24.1 Introduction
  2. 24.2 Overview
    • 24.2.1 Developing Algorithms
    • 24.2.2 Types of Algorithms
    • 24.2.3 Use of Algorithms
  3. 24.3 Develop Algorithms
    • 24.3.1 Sorting Algorithms
    • 24.3.2 Graphics Algorithms
  4. 24.4 Algorithm Usage
    • 24.4.1 Sorting Algorithms
    • 24.4.2 Search Algorithms
  5. 24.5 Summary
  6. 24.6 Literature
  7. 24.7 Exercises

Part IV Java Projects

25 Swing Programs

  1. 25.1 Introduction
  2. 25.2 Requirements
  3. 25.3 Analysis and Design
    • 25.3.1 User Interface
    • 25.3.2 Program Logic
  4. 25.4 Implementation
    • 25.4.1 Start Eclipse With the Workspace »Exercises«
    • 25.4.2 Create New Java project »Swing Programs«
    • 25.4.3 Create New class »CourseStatisticsApp«
    • 25.4.4 Implement Class »CourseStatisticsApp«
    • 25.4.5 Create New Class »MainWindow«
    • 25.4.6 Implementing Class »MainWindow«
    • 25.4.7 Implementing Class »CsvParser«
    • 25.4.8 Implementing the Class »TableFilter«
  5. 25.5 Test
  6. 25.6 Deployment
  7. 25.7 Summary

Part V Appendix

26 Frequent Errors

  1. 26.1 Introduction
  2. 26.2 Java Errors
    • 26.2.1 Cannot Make a Static Reference To The Non-Static Field
    • 26.2.2 Output of a »null« Value
    • 26.2.3 NullPointerException
    • 26.2.4 Missing Break in Case Statement
    • 26.2.5 Incorrect Comparison
    • 26.2.6 Unhandled Exceptions
    • 26.2.7 NoClassDefFoundError
    • 26.2.8 ClassNotFoundException
  3. 26.3 Eclipse Errors
    • 26.3.1 Eclipse Could Not Be Started
    • 26.3.2 Chaotic Eclipse Perspective
    • 26.3.3 Missing Window
  4. 26.4 Summary
  5. 26.5 Literature

27 Glossary

PDF preview unavailable. Download the PDF instead.

vA16QxP4kmqFFEM3Tna5YEruslvyKSNt Adobe PDF library 17.00

Related Documents

Preview Fundamentals of Electrical Engineering: Theory and Practice with Multisim
A comprehensive guide to the fundamentals of electrical engineering, covering theory and practical application using Multisim. This book explores electrical quantities, circuits, measurement devices, capacitors, inductors, transformers, and AC circuits.
Preview Fundamentals of Wireless Communication by Hans Kummer | Elektor
An in-depth guide to the fundamentals of wireless communication, covering history, technical principles, modulation techniques, signal processing, antennas, and wave propagation. Authored by Hans Kummer and published by Elektor.
Preview Wireless Power Design: From Theory to Practical Applications in Wireless Energy Transfer and Harvesting
A comprehensive guide to wireless power design, covering theoretical foundations, practical applications, and hands-on projects in wireless energy transfer and harvesting, from historical context to modern IoT devices.
Preview Storing and Visualizing Data with Raspberry Pi on the Network
A comprehensive guide on using Raspberry Pi for data storage and visualization in electronic applications, covering various database models and software like InfluxDB, MariaDB, SQLite, MongoDB, Grafana, and Node-RED.
Preview PID-based Practical Digital Control with Raspberry Pi and Arduino Uno
Master PID control with Raspberry Pi and Arduino Uno. This practical guide by Dogan Ibrahim from Elektor covers digital control systems, sensors, and hands-on projects for embedded systems and electronics enthusiasts.
Preview From Rubbing Amber to Swiping Glass: How Humanity Turned Electricity into Electronics - Elektor
Explore the fascinating history of electricity and electronics, from ancient discoveries like amber's properties to modern touch interfaces, in this comprehensive guide by Clemens Valens from Elektor.
Preview Java Terminal Program: Transfer Application Guide
A comprehensive guide to developing a Java terminal program for directory copying, covering requirements, implementation in Eclipse, and testing. Features detailed explanations of classes like TransferApp and CopyLogic.
Preview Photovoltaïque : Alimentation Électrique Autonome de Sites Isolés - Guide DIY Elektor
Guide pratique par Gérard Guihéneuf (Elektor) pour réaliser votre propre système d'alimentation électrique autonome avec des panneaux photovoltaïques pour abris de jardin, garages et mobile homes. Comprend des explications techniques et des projets.