The Java Workshop
eBook - ePub

The Java Workshop

A Practical, No-Nonsense Introduction to Java Development

David Cuartielles, Andreas Göransson, Eric Foster-Johnson

Partager le livre
  1. 604 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

The Java Workshop

A Practical, No-Nonsense Introduction to Java Development

David Cuartielles, Andreas Göransson, Eric Foster-Johnson

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

Get to grips with the fundamentals of Java programming and learn to build useful applications with the help of real-world examples and engaging practical activities

Key Features

  • Build a solid foundation in Java and focus on developing real-world applications
  • Implement the fundamental concepts of object-oriented programming in your code
  • Work with external data storage systems and learn how to efficiently handle data

Book Description

Java is a versatile, popular programming language used across a wide range of industries. Learning how to write effective Java code can take your career to the next level, and The Java Workshop will help you do just that. This book is designed to take the pain out of Java coding and teach you everything you need to know to be productive in building real-world software.

The Workshop starts by showing you how to use classes, methods, and the built-in Collections API to manipulate data structures effortlessly. You'll dive right into learning about object-oriented programming by creating classes and interfaces and making use of inheritance and polymorphism. After learning how to handle exceptions, you'll study the modules, packages, and libraries that help you organize your code. As you progress, you'll discover how to connect to external databases and web servers, work with regular expressions, and write unit tests to validate your code. You'll also be introduced to functional programming and see how to implement it using lambda functions.

By the end of this Workshop, you'll be well-versed with key Java concepts and have the knowledge and confidence to tackle your own ambitious projects with Java.

What you will learn

  • Write clean, well-commented Java code that's easy to maintain
  • Debug logical errors and handle exceptions in your Java programs
  • Implement object-oriented and functional programming paradigms
  • Use regular expressions to search for information in text data
  • Work with information stored in databases using JDBC
  • Make HTTP requests from Java applications and parse the response data
  • Secure your data with cryptography and encryption
  • Write unit tests to validate your code with JUnit

Who this book is for

This Java coding book is designed for anyone who is new to Java. Whether you're an aspiring software developer, or are just curious about learning to code, then this book will get you on the right track. No prior programming experience is required.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que The Java Workshop est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  The Java Workshop par David Cuartielles, Andreas Göransson, Eric Foster-Johnson en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Informatique et Programmation. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2019
ISBN
9781839218118
Édition
1
Sous-sujet
Programmation

1. Getting Started

Overview
In this chapter, we will be covering the fundamentals of Java. You will first learn to write and compile your first "Hello World!" program—traditionally the first step to practicing any new language. We will then discuss the differences between the command-line interface (CLI) and Graphical User Interface (GUI), and the relative benefits of both. By the end of this chapter, you will understand the basic concepts behind variables, know how to hold data within them, and, even, how to comment on your own code.

Introduction

When learning how to program in almost any programming language, the first example you will typically test is called "hello world." It is the simplest application possible; the aim is to write the expression "hello world" to whatever user interface the programming environment offers. Executing this program will introduce you to the basics of writing code using the IntelliJ editor, utilizing different types of data to be printed to the user interface and adding comments to your code.
When writing your first program, you will also discover how Java's syntax is constructed and how it relates to other languages such as C or C++. Understanding the syntax is key to starting to read code. You will learn how to distinguish where commands and functions begin and end, how parameters are passed over between blocks of code, and how to leave comments that will help you when revisiting your software in the future.
This chapter covers the basics of writing and testing programs as a first step toward building all the code that you will find in this book.

Writing, Compiling, and Executing Your Hello World Program

In the preface, you saw how to install the IntelliJ development environment. While it is possible to write Java code with literally any text editor, we believe it is good to see how to create applications using state-of-the-art tools such as the aforementioned software package.
However, prior to guiding you step by step through getting your first program to run, we should take a look at the code that will become your first executable running on Java. The following code listing shows the program. Read through it, and we will later revise what each one of the parts is doing:
public class Main {
public static void main (String[] args) {
System.out.println("Hello World!");
}
}
The first line is what we call a class definition. All programs in Java are called classes. A program might consist of several classes. Classes carry inside them everything they need to perform the task they were designed for. For a class to be executable in Java, it must contain a method called main. In this program, you can see how the Main class contains a method called main that will be printing the sentence "Hello World!" to the system's default output.
The code included in the class definition (public class Main) indicates that the class itself is public, which means that it will be accessible from other programs running on your computer. The same happens for the method definition (public static void main(String[] args)). There is, however, a series of other things that require our attention:
  • static signifies that there is nothing in the system instantiating the main method. Because of the way the Java Virtual Machine works, the main method needs to be static, or it will not be possible to execute it.
  • void indicates that the main method will not be returning anything to any code calling it. Methods could, in fact, send an answer to a piece of code executing it, as we will see later in the book.
  • main is the name of the method. You cannot assign this a different name, since it is the method that makes the program executable and needs to be named this way.
  • String[] args are the parameters of the main method. Parameters are passed as a list of strings. In other words, the program could take arguments from other parts within your computer and use them as data. In the particular case of the main method, these are strings that could be entered on the command-line interface (CLI) when calling the program.

Exercise 1: Creating Your Hello World Program in Java

IntelliJ provides you with a pre-made "hello world" template. Templates help you to get started faster with your code, as they provide the components you may need to speed up development. Templates can also be used for educational purposes; this is the case when it comes to testing "hello world."
For this first exercise, start with the editor. We will leave some options as they are by default. We will later see how to personalize some of the options to better suit our needs:
  1. Open IntelliJ and you will see a window giving you several options. Click on Create New Project. It should be the first option in the list:
    Figure 1.1: Creating a new project on IntelliJ IDE
    Figure 1.1: Creating a new project on IntelliJ IDE
  2. A new interface should appear. The default options here are meant for creating a Java program, so you just need to click Next:
    Figure 1.2: Creating a new Java project
    Figure 1.2: Creating a new Java project
  3. Check the box to create the project from a template. Click on Java Hello World and then click Next:
    Figure 1.3: Create a Java Hello World project from template
    Figure 1.3: Create a Java Hello World project from template
  4. Name the project chapter01. Then, click Finish:
    Figure 1.4: Create a Hello World Project
    Figure 1.4: Create a Hello World Project
  5. As we haven't chosen a folder to store the projects (intentionally), IntelliJ will offer you the possibility to create a default project folder inside your user space. Click OK:
    Figure 1.5: Default project folder option on IntelliJ IDE
    Figure 1.5: Default project folder option on IntelliJ IDE
  6. You will see a popup with tips on how to use the software. If you have never used a development environment of this type before, then this is a good way to get information about how it functions every time IntelliJ boots up. Choose your preferences and then click Close:
    Figure 1.6: Tip on how to use the IDE
    Figure 1.6: Tip on how to use the IDE
  7. IntelliJ reminds you regarding the possibility of using a special tab dedicated to learning more about the environment in relation to programming. Click Got It.
  8. The editor presents a menu bar, a code navigation bar, a project navigation area, and the actual editor where you can see the code we explained earlier. Now it is time to test it. Click on the Run button (this is the triangle on the right-hand side of the code navigation bar).
    Figure 1.7: Execute the program by clicking on the Run button
    Figure 1.7: Execute the program by clicking on the Run button
  9. When the program runs, a terminal window unfolds at the bottom of IntelliJ. Here, you can see how the software called your JVM, the program's outcome, and a line from the ...

Table des matiĂšres