Java Fundamentals
eBook - ePub

Java Fundamentals

A fast-paced and pragmatic introduction to one of the world's most popular programming languages

Gazihan Alankus, Rogério Theodoro de Brito, Basheer Ahamed Fazal, Vinicius Isola, Miles Obare

Condividi libro
  1. 408 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

Java Fundamentals

A fast-paced and pragmatic introduction to one of the world's most popular programming languages

Gazihan Alankus, Rogério Theodoro de Brito, Basheer Ahamed Fazal, Vinicius Isola, Miles Obare

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

Enhance your career options with this well-crafted object-oriented programming language that enjoys the support of an enormous ecosystem of tools and libraries

Key Features

  • Get introduced to Java, its features, and its ecosystem
  • Understand how Java uses object-oriented programming
  • Become an expert Java exception handler

Book Description

Since its inception, Java has stormed the programming world. Its features and functionalities provide developers with the tools needed to write robust cross-platform applications. Java Fundamentals introduces you to these tools and functionalities that will enable you to create Java programs.

The book begins with an introduction to the language, its philosophy, and evolution over time, until the latest release. You'll learn how the javac/java tools work and what Java packages are - the way a Java program is usually organized. Once you are comfortable with this, you'll be introduced to advanced concepts of the language, such as control flow keywords. You'll explore object-oriented programming and the part it plays in making Java what it is. In the concluding chapters, you'll get to grips with classes, typecasting, and interfaces, and understand the use of data structures, arrays, strings, handling exceptions, and creating generics.

By the end of this book, you will have learned to write programs, automate tasks, and follow advanced courses on algorithms and data structures or explore more advanced Java courses.

What you will learn

  • Create and run Java programs
  • Use data types, data structures, and control flow in your code
  • Implement best practices while creating objects
  • Work with constructors and inheritance
  • Understand advanced data structures to organize and store data
  • Employ generics for stronger check-types during compilation
  • Learn to handle exceptions in your code

Who this book is for

Java Fundamentals is designed for tech enthusiasts who are familiar with some programming languages and want a quick introduction to the most important principles of Java.

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
Java Fundamentals è disponibile online in formato PDF/ePub?
Sì, puoi accedere a Java Fundamentals di Gazihan Alankus, Rogério Theodoro de Brito, Basheer Ahamed Fazal, Vinicius Isola, Miles Obare in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Informatica e Programmazione in Java. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
2019
ISBN
9781789802955
Edizione
1
Argomento
Informatica

Chapter 1

Introduction to Java

Learning Objectives

By the end of this lesson, you'll be able to:
  • Describe the working of the Java ecosystem
  • Write simple Java programs
  • Read input from the users
  • Utilize classes in the java.util package

Introduction

In this first lesson, we are embarking on our study of Java. If you are coming to Java from a background of working with another programming language, you probably know that Java is a language for programming computers. But Java goes beyond just that. It's more than a very popular and successful language that is virtually present everywhere, it is a collection of technologies. Besides the language, it encompasses a very rich ecosystem and it has a vibrant community working on many facets to make the ecosystem as dynamic as it can be.

The Java Ecosystem

The three most basic parts of the Java ecosystem are the Java Virtual Machine (JVM), the Java Runtime Environment (JRE), and the Java Development Kit (JDK), which are stock parts that are supplied by Java implementations.
Figure 1.1: A representation of the Java ecoystem
Figure 1.1: A representation of the Java ecosystem
Every Java program runs under the control of a JVM. Every time you run a Java program, an instance of JVM is created. It provides security and isolation for the Java program that is running. It prevents the running of the code from clashing with other programs within the system. It works like a non-strict sandbox, making it safe to serve resources, even in hostile environments such as the internet, but allowing interoperability with the computer on which it runs. In simpler terms, JVM acts as a computer inside a computer, which is meant specifically for running Java programs.

Note

It is common for servers to have many JVMs in execution simultaneously.
Up in the hierarchy of stock Java technologies is the JRE. The JRE is a collection of programs that contains the JVM and also many libraries/class files that are needed for the execution of programs on the JVM (via the java command). It includes all the base Java classes (the runtime) as well as the libraries for interaction with the host system (such as font management, communication with the graphical system, the ability to play sounds, and plugins for the execution of Java applets in the browser) and utilities (such as the Nashorn JavaScript interpreter and the keytool cryptographic manipulation tool). As stated before, the JRE includes the JVM.
At the top layer of stock Java technologies is the JDK. The JDK contains all the programs that are needed to develop Java programs, and it's most important part is the Java Compiler (javac). The JDK also includes many auxiliary tools such as a Java disassembler (javap), a utility to create packages of Java applications (jar), system to generate documentation from source code (javadoc), among many other utilities. The JDK is a superset of the JRE, meaning that if you have the JDK, then you also have the JRE (and the JVM).
But those three parts are not the entirety of Java. The ecosystem of Java includes a very large participation of the community, which is one of the reasons for the popularity of the platform.

Note

Research into the most popular Java libraries that are used by the top Java projects on GitHub (according to research that has been repeated in 2016 and 2017) showed that JUnit, Mockito, Google's Guava, logging libraries (log4j, sl4j), and all of Apache Commons (Commons IO, Commons Lang, Commons Math, and so on), marked their presence, together with libraries to connect to databases, libraries for data analysis and machine learning, distributed computing, and almost anything else that you can imagine. In other words, for almost any use that you want to write programs to, there are high chances of an existing library of tools to help you with your task.
Besides the numerous libraries that extend the functionality of the stock distributions of Java, there is a myriad of tools to automate builds (for example, Apache Ant, Apache Maven, and Gradle), automate tests, distribution and continuous integration/delivery programs (for example, Jenkins and Apache Continuum), and much, much more.

Our First Java Application

As we briefly hinted before, programs in Java are written in source code (which are plain text, human-readable files) that is processed by a compiler (in the case of Java, javac) to produce the Java bytecode in class files. The class files containing Java bytecode are, then, fed to a program called java, which contains the Java interpreter/JVM that executes the program that we wrote:
Figure 1.2: The process of compilation in Java
Figure 1.2: The process of compilation in Java

Syntax of a Simple Java Program

Like all programming languages, the source code in Java must follow particular syntaxes. Only then, will the program compile and provide accurate results. Since Java is an object-oriented programming language, everything in Java is enclosed within classes. A simple Java program looks similar to this:
public class Test { //line 1
public static void main(String[] args) { //line 2
System.out.println("Test"); //line 3
} //line 4
} //line 5
Every java program file should have the same name as that of the class that contains main (). It is the entry point into the Java program.
Therefore the preceding program will compile and run without any errors only when these instructions are stored in a file called Test.java.
Another key feature of Java is that it is case-sensitive. This implies that System.out.Println will throw an error as it is not capitalized correctly. The correct instruction should be System.out.println.
main() should always be declared as shown in the sample. This is because, if main() is not a public method, it will not be accessed by the compiler, and the java program will not run. The reason main() is static is because we do not call it using any object, like you would for all other regular methods in Java.

Note

We will discuss these the public and static keywords later in this book, in greater depth.
Comments are used to provide some additional information. The Java compiler ignores these comments.
Single line comments are denoted by // and multiline comments are denoted by /* */.

Exercise 1: A Simple ...

Indice dei contenuti