Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Introduction to Programming
Introduction to Programming

Introduction to Programming: Learn to program in Java with data structures, algorithms, and logic

Arrow left icon
Profile Icon Nick Samoylov
Arrow right icon
$43.99
Paperback Jun 2018 722 pages 1st Edition
eBook
$24.99 $35.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Nick Samoylov
Arrow right icon
$43.99
Paperback Jun 2018 722 pages 1st Edition
eBook
$24.99 $35.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$24.99 $35.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Introduction to Programming

Java Virtual Machine (JVM) on Your Computer

This book will be your guide to achieving an intermediate level of Java programming skills. Programming is not just about knowing the language syntax. It is also about the tools and sources of information necessary to write, compile, and execute a program or run a whole software system. The first step on this road is to learn the important components of Java, including Java Development Kit (JDK) and Java Virtual Machine (JVM).

This chapter will introduce Java as a language and a tool, and establish the most important terminology. It will also describe the motivation behind Java's creation, cover its history, editions, versions, and technologies, and outline Java's marketing position and main areas of application. Then, a sequence of practical steps will walk readers through the process of Java installation and configuration on their computers, and introduce the main Java commands.

In this chapter, we will cover the following topics:

  • What is Java?
  • Java platforms, editions, versions, and technologies
  • Java SE Development Kit (JDK) installation and configuration
  • Main Java commands
  • Exercise – JDK tools and utilities

What is Java?

Since this book is written for beginners, we will assume that you know almost nothing about Java. But even if you do know something, or even a lot, it is always helpful to review the basics, even if it's just so you can feel good about yourself by appreciating how much you have mastered already. So, we will start by defining the terms Java, JVM, compilation, bytecode, and more.

Basic terms

When talking about Java, people use Java, JVM, JDK, SDK, and Java platform as synonyms. The legal definition treats Java as Sun's trademark for a set of technologies, but we typically do not think about Java as a trademark. Most often, when somebody says Java, they mean a programming language that is used by humans to express sets of instructions (programs) that can be executed by a computer (not directly, but after the program is compiled/transformed into code that a computer understands). The human-readable Java program is called source code, and the computer-readable program (after all transformations) is called binary code, because it is expressed only using 1 and 0.

You can find the complete Java Language Specification (description) at https://docs.oracle.com/javase/specs/. It is much more accessible than one might expect, and it can be helpful even for a novice, especially if one uses it as a reference document. Do not feel discouraged by the formal language of the first few sections. Read what you can and come back later, as your understanding of Java grows and the motivation for deeper and more precise definitions increases.

JVM is a program that translates byte code of Java .class files into binary machine code and sends it to a microprocessor for execution.

Have you noticed that there are two similar terms, bytecode and byte code? In conversation, the difference is hardly noticeable, so people use them interchangeably. But there is a difference. Byte code (or Byte Code, to be precise) is a language that can be executed by a special program called JVM. By contrast, bytecode is the format (each instruction occupies one byte, thus the name) of the instructions generated by the Java compiler (another program) that reads the human-readable source code and transforms it into Byte Code.

Bytecode is a binary code expressed in the format JVM understands. JVM then reads (loads, using a program called class loader) bytecodes, transforms the instructions into binary code (instructions in a format a particular computer microprocessor, where JVM is running, understands), and passes the result to the CPU, a microprocessor that executes it.

A class is a file (with the extension .class) produced by the Java compiler (from the source code in a file with the same name and the extension .java). There are more than a dozen JVM implementations, created by different companies, but we will be focusing on Oracle JVM's implementation, which is called HotSpot. In Chapter 11, JVM Processes and Garbage Collection, we will look more closely at JVM's functionality, architecture, and processes.

On the same page as the Java Language Specification (https://docs.oracle.com/javase/specs), you can find the Java Virtual Machine Specification. We recommend that you use it as a source of references for the terminology and for the understanding of JVM functionality.

JDK is a collection of software tools and supporting libraries that allow for the creation and execution of Java language programs.

Since Java 9, applets (components that can be executed in a browser) are not supported anymore, so we will not talk much about them. An application is a Java program that can be (after compilation) executed on a computer where JVM is installed. So, JDK includes at minimum a compiler, JVM, and Java Class Library (JCL)—a collection of ready-to-use procedures that can be called by an application. But in reality, it has many other tools and utilities that can help you to compile, execute, and monitor a Java application. The subset of JDK that includes JVM, JCL, class loader, and supporting files allows the execution (running) of bytecode. Such a combination is called the Java Runtime Environment (JRE). Each Java application is executed in a separate JVM instance (copy) that has its own allocated computer memory, so two Java applications cannot talk to each other directly, but only via the network (web-services and similar means).

Software Development Kit (SDK) is a collection of software tools and supporting libraries that allow the creation of an application using a certain programming language. SDK for Java is called JDK.

So, when people use SDK in reference to JDK, they are correct, but not precise.

The Java platform is composed of a compiler, JVM, supporting libraries, and other tools from JDK.

The supporting libraries in the preceding definitions are Java standard libraries, also called JCL, and are necessary for executing bytecode. If a program requires some other libraries (not included in JCL), they have to be added at compilation time (see Chapter 3, Your Development Environment Setup, which describes how to do it) and included in the generated bytecode. Java platform can be one of the four: Java Platform Standard Edition (Java SE), Java Platform Enterprise Edition (Java EE), Java Platform Micro Edition (Java ME), or Java Card. There used to be the JavaFX Platform, too, but it has been merged into Java SE since Java 8. We will talk about the differences in the next section.

Open JDK is a free and open source implementation of Java SE.

These are the most basic terms. Other terms will be introduced as needed throughout the book, in the corresponding contexts.

History and popularity

Java was first released in 1995 by Sun Microsystems. It was derived from C and C++, but did not allow users to manipulate computer memory on a very low level, which is the source of many difficulties, including memory leak related issues, that C and C++ programmers experience if they are not very careful about it. Java stood out due to its simplicity, portability, interoperability, and safety net, which allowed it to become one of the most popular programming languages. It is estimated that as of 2017, there are close to 20 million programmers in the world (close to 4 million of them are in the US), and approximately half of them use Java. And there are good reasons to believe that the need for software developers, including Java developers, will only grow in the future. So, studying Java looks like a step towards a stable career. And learning Java is not actually very difficult. We will show you how to do it; just continue reading, thinking, and trying all the suggestions in practice on your computer.

Java was conceived as a facility that allows users to write once, run anywhere – that is another term to explain and understand. It means that compiled Java code can run on all computers with operating systems that support Java, without the need for recompilation. As you understand already, support Java means that for each operating system, an interpreter exists that can transform bytecode into binary code. That's how run anywhere is implemented: anywhere where a Java interpreter is available.

After the concept proved to be popular and Java was firmly established as one of the major players among other object-oriented languages, Sun Microsystems made much of its JVM free and open source software, governed by the GNU General Public License (GPL). In 2007, Sun Microsystems made all of its JVM's core code available under free and open source distribution terms, except for a small portion of code to which Sun did not have the copyright. In 2010, Oracle acquired Sun Microsystems and declared itself a steward of Java technology with a relentless commitment to fostering a community of participation and transparency.

Today, Java is used in many areas, most prominently in Android programming and other mobile applications, in various embedded systems (various chips and specialized computers), desktop Graphical User Interface (GUI) development, and a huge variety of web applications, including network applications and web services. Java is also widely used for scientific applications, including the rapidly expanding areas of machine learning and artificial intelligence.

Principles

There were five primary goals in the creation of the Java language, according to Design Goals of the Java TM Programming Language (http://www.oracle.com/technetwork/java/intro-141325.html). The Java language had to be:

  • Object-oriented and familiar: This meant that it had to look like C++, but without unnecessary complexities (we will discuss the term object-oriented in Chapter 2, Java Language Basics)
  • Architecture-neutral and portable: This meant the ability to use JVM as the environment that isolates the language (source code) from the knowledge of each particular operating system (often called the platform)
  • High performance: It should work on par with the leading programming languages of the time
  • Interpreted: It can be moved to an executing phase without linking (creating a single executable file from multiple .class files), thus allowing a quicker write-compile-execute cycle (modern JVMs, though, are optimized to keep the binary version of the often used .class files, to avoid repeating interpretation)
  • Multithreaded: It should allow several concurrent execution jobs (threads), such as downloading an image and processing other user commands and data at the same time
  • Dynamic: Linking should happen during execution
  • Secure: It had to be well protected from an unauthorized modification at runtime

The result proved these goals to be well-defined and fruitful, because Java became one of the main languages of the internet era.

Java platforms, editions, versions, and technologies

In everyday discussions, some programmers use these terms interchangeably, but there is a difference between Java platforms, editions, versions, and technologies. This section is focuses on explaining it.

Platforms and editions

We hear the term platform almost every day. Its meaning changes depending on the context, but in the most general sense, it means a device or environment that allows someone to do something. It serves as a foundation, an environment, a platform. In the information technology realm, a platform provides an operating environment where a software program can be developed and executed. An operating system is a typical example of a platform. Java has its own operating environment, which comes, as we have mentioned in the previous sections, in four platforms (and six editions):

  • Java Platform Standard Edition (Java SE): This is the edition most people mean when they say Java. It includes JVM, JCL, and other tools and utilities that allow for the development and deployment of Java applications on desktops and servers. In this book, we are going to stay within the boundaries of this edition, and will mention the other editions only in this section.
  • Java Platform Enterprise Edition (Java EE): This is composed of Java SE, servers (computer programs that provide services to the applications), enhanced libraries, code samples, tutorials, and other documentation for developing and deploying large-scale, multitiered, and secure network applications.
  • Java Platform Micro Edition (Java ME): This is a small-footprint (using little resources) subset of Java SE, with some specialized class libraries for developing and deploying Java applications for embedded and mobile devices – phones, personal digital assistants, TV set-top boxes, printers, sensors, and so on. There is also a variation of Java ME for Android programming (with its own JVM implementation), developed by Google. It is called Android SDK.
  • Java Card: This is the smallest of the Java platforms, for developing and deploying Java applications onto small embedded devices, such as smart cards. It comes in two editions (quotes are taken from the official Oracle documentation found at http://www.oracle.com/technetwork/java/embedded/javacard/documentation/javacard-faq-1970428.html#3):
    • Java Card Classic Edition, which targets smart cards as deployed today on all vertical markets, based on ISO7816 and ISO14443 communication.
    • Java Card Connected Edition, which is developed to support a web application model, with servlets running on the card, and TCP/IP as basic protocol and runs on high-end secure microcontrollers, typically based on a 32-bit processor and supporting a high-speed communication interface like USB.

Versions

Since its first release in 1996, Java has evolved through nine major versions:

  • JDK 1.0 (January 23, 1996)
  • JDK 1.1 (February 19, 1997)
  • J2SE 1.2 (December 8, 1998)
  • J2SE 1.3 (May 8, 2000)
  • J2SE 1.4 (February 6, 2002)
  • J2SE 5.0 (September 30, 2004)
  • Java SE 6 (December 11, 2006)
  • Java SE 7 (July 28, 2011)
  • Java SE 8 (March 18, 2014)
  • Java SE 9 (September 21, 2017)
  • Java SE 10 (March 20, 2018)

There are several suggestions regarding changing the Java versioning scheme. Since Java 10, a new time-based versioning $YEAR.$MONTH of JDK has been introduced. Also, a new Java version is planned to be released every six months, in March and in September of each year. So, Java 11 will be released in September 2018, with JVM version 18.9. We will show you how to display which JDK version you are using shortly.

Technologies

The word technology is overloaded. Programmers use it for almost anything. If you look at Oracle's list of Java technologies (https://www.oracle.com/java/technologies/index.html), you will find the following list:

  • Embedded, which includes all of the previously listed Java platforms except for Java EE, with some modifications, usually with a smaller footprint and other optimizations
  • Java SE, which covers Java SE and Java SE Advanced, which includes Java SE and some monitoring and management tools for an enterprise level (larger than just a development computer) installation
  • Java EE, as described previously
  • Cloud, which includes cloud-based reliable, scalable, and elastic services

But in the Oracle glossary (http://www.oracle.com/technetwork/java/glossary-135216.html), the following technologies are added to the list:

  • JavaSpaces: A technology that provides distributed persistence
  • Jini Technology: An Application Programming Interface (API) that enables the networking of devices and services automatically

Elsewhere, on the front page of the Oracle Java 10 documentation (https://docs.oracle.com/javase/10), client technologies are listed as follows:

Meanwhile, in the Oracle Java tutorial (https://docs.oracle.com/javase/tutorial/getStarted/intro/cando.html), Java Web Start and Java Plug-In are mentioned as deployment technologies for deploying your applications to end users.

However, the biggest list of Java technologies that Oracle provides is on the page dedicated to the Technology Network (http://www.oracle.com/technetwork/java/index.html). In addition to Java SE, Java SE Advanced and Suite, Java Embedded, Java EE, Java FX, and Java Card, there are also listed Java TV, Java DB, and Developer Tools. If you go to the Java SE or Java EE pages, under the Technologies tab, you will find more than two dozens APIs, and various software components listed as technologies, too. So, one should not be surprised to find anywhere any kind of list of Java technologies.

It seems that anything related to Java has been called a technology at least once, somewhere. To avoid further confusion, from now on, in this book, we will try to avoid using word technology.

Java SE Development Kit (JDK) installation and configuration

From now on, every time we talk about Java, we mean Java SE version 10. We will refer to it as Java 10, or Java, or JDK, used as synonyms, unless otherwise specified.

Where to start

Before you can do any Java development on your computer, you will need JDK installed and configured. In order to do this, search the internet for the JDK download and select any link that starts with https://www.oracle.com/. The best, as of this writing, should be http://www.oracle.com/technetwork/java/javase/downloads/index.html.

If you follow the preceding link, you will see this section:

Let us call this page Page1, for further references. Now, you can click the Download link under JDK. The other two download links offer JRE, which, as you know already, only allows you to run already compiled Java programs; we need to write a program, compile it into bytecode, and then run it.

The page with Java installers

After you click, you will see a page (Page2) with this section:

These are the Java installers for different operating systems (OS). You need to choose the one that fits your OS and click the corresponding link (do not forget to click Accept License Agreement using the radio button; if in doubt, read the license agreement via the link Oracle Binary Code License Agreement for Java SE). For Linux, there are two installers – one in Red Hat Package Manager Format (.rpm), and one that is just an archived (.tar) and compressed (.gz) version. Also, noticed that in this list, there are only installers for 64-bit operating systems. As of this writing, it is not clear yet if the 32-bit version is to be dropped officially, although it was available as an early access build.

Select the installer that you need, and download it.

How to install

Now is the time to install Java, which basically consists of the following four steps:

  1. Expand the installer
  2. Create directories
  3. Copy files into these directories
  4. Make the Java executables accessible without typing the full path

To find the detailed installation instructions, go back to Page1 and click on the Installation Instructions link. Find the link for your operating system and follow the provided steps, but choose only those that are related to JDK.

Eventually, you will come to the point when you are able to run the command java -version, which will display the following:

As you can see, it shows the version for Java as 10.0.1, and for JRE and JVM as 18.3 (build 10.0.1). It is not clear yet if future versions of Java, JRE, and JVM are going to follow the same format.

Anyway, if the java -version command displays the version you tried to install, it means that you have installed Java correctly and can now enjoy working with it. From now on, every time a new version comes out, you are going to be prompted to upgrade, and you can do it by just clicking the provided link. Alternatively, you can go to the page with the installers (Page2), download the corresponding installer, launch it, and repeat the process already familiar to you.

In practice, though, programmers do not upgrade their Java installation every time. They keep their development version the same as the Java in their production environment (in order to avoid potential incompatibility). If they would like to play with a new version before upgrading the production, they might have two versions of Java installed on their computer, in parallel. In Chapter 3, Your Development Environment Setup, you will learn how to do this, and how to switch between them.

Main Java commands

In the previous section, you saw one example of a Java command, the one that displays the JVM version. By the way, the command java starts the JVM, and is used to run bytecodes of the compiled Java programs (we will demonstrate how to do this in detail in Chapter 4, Your First Java Project).

The JVM execution command

Now, if you only run java, the output will display the short version of help. Since it is quite long, we will show it in several parts. Here is the first section:

It shows three ways to run JVM:

  • To execute a class, a .class file that contains bytecode
  • To execute a jar file, a file with the extension .jar that contains .class files (may be even the whole application) in a ZIP format, which also includes a Java-specific manifest file
  • To execute the main class in a module (a group of .class files and other resources that is better structured than a .jar file), typically an application, or a part of it

As you can see, in each of the preceding commands, a main class has to be supplied explicitly. It is the .class file that has to be executed first. It acts as the main entrance into the application, and starts the chain of loading other classes (as they are needed) to run the application. An example of such a command would be:

java MyGreatApplication

In fact, this means that there is a file, MyGreatApplication.class, in the current directory, but we should not specify the file extension. Otherwise, JVM will look for the file MyGreatApplication.class.class, which it will not find, of course, and fail to run anything.

In this book, we are not going to use any of these commands explicitly, and will leave it up to the editor to run it behind the scenes, because a modern editor does not just help write and modify the source code; it can also compile and execute the written code. That's why it is called not just the editor, but the Integrated Development Environment (IDE).

Nevertheless, we will continue to overview all of the java command options, so you will have an idea what is going behind the scenes in your IDE. To enjoy car driving, one does not need to know the details of the engine's inner workings, but it is helpful to have some idea about the principles of its operation. Besides, as your professional level grows and the applications you work on grow too and have to handle many requests, you will need to adjust the JVM configuration, so here is the first sneak peek under the hood.

Here is the next section of the output of the java command:

In the preceding screenshot, you can see two deprecated options followed by options related to classpath and module path. The last two are very important options. They allow the specifying of the location of the classes your application consists of, and the location of the libraries your application uses. The latter can be classes written by you or third-party libraries.

The concept of modules is out of the scope of this book, but module path is used very similarly to the classpath. The classpath option tells JVM where to look for the classes, while the module path tells JVM about the location of the modules. It is possible to use both in the same command line.

For example, let us assume that you have the file MyGreatApplication.class (which contains the bytecode of your program, MyGreatApplication.java) stored in the directory dir2, which is a subdirectory of the directory dir1, and your terminal window currently shows the content of the directory dir1:

As you can see, there is another directory, dir3, which we created to store another file, SomeOtherProgram.class, that is used by your application. We also put in dir4 a library of other supporting .class files, collected in SomeLibrary.jar. The command line to run your application then looks like this:

java -cp dir2:dir3:dir4/SomeLibrary.jar  MyGreatApplication //on Unix
java -cp dir2;dir3;dir4\SomeLibrary.jar MyGreatApplication //on Windows

Alternatively, we can put SomeOtherProgram.class and MyGreatApplication.class in some.jar or a some.zip file, and place it in dir5. Then, the command will take one of the following forms:

java -cp dir4/SomeLibrary.jar:dir5/some.zip MyGreatApplication //Unix
java -cp dir4/SomeLibrary.jar:dir5/some.jar MyGreatApplication //Unix
java -cp dir4\SomeLibrary.jar;dir5\some.zip MyGreatApplication //Windows
java -cp dir4\SomeLibrary.jar;dir5\some.jar MyGreatApplication //Windows

Instead of -cp, we could use the options -classpath or --class-path. They are just three different conventions, so that people used to one of them can write a command line intuitively. None of the styles are better or worse than the others, although each of us has preferences and opinions. If neither of the classpath options is used, JVM looks for classes only in the current directory. Some of the classes (standard libraries) are always located in certain directories of Java installation, so there is no need to list them with a classpath option. We will talk about setting the classpath in more detail in Chapter 3, Your Development Environment Setup.

The next section of the java command output lists options that allow for validating that everything is set correctly before actually executing the application:

Since modules are outside of the scope of this book, we are skipping these and moving on to the next section of the output:

The -D option allows for setting a parameter with a value that is accessible to the application. It is often used to pass some values or flags to the application, which the application can use to change its behavior. If more information needs to be passed, then the .properties file is used (with many flags and various values), while the location of the property file is passed with the option -D. It is completely up to the programmer what has to be in the .properties file or in the value passed with the option -D. But there are best practices related to the application configuration, which also depend on the particular framework or libraries you are using. You will learn them over time, and these practices are beyond the beginner programmer course.

The -verbose option provides more information (than we have seen on these screenshots) and some specific data, depending on the flags class, module, gc, or jni, where gc stands for garbage collector, which will be discussed in Chapter 11, JVM Processes and Garbage Collection. For the other flags, you can read the official Oracle documentation, but chances are, you will not use them anytime soon.

The -version option displays the version of Java that is installed. This is very useful from day one, because it allows for checking, at any time, what version of Java is currently in use. In the previous section, we demonstrated how to do it, and the output it produces. When a new version of Java is released, many programmers install it in parallel with the one they are currently using, and switch between them, either to learn new features or to start writing code for a new version, while maintaining the old code written for the old version. You will learn how to have two versions of Java installed on the same computer, and how to switch between them, in Chapter 3, Your Development Environment Setup.

We will skip the module-related options.

The rest of the options in the preceding screenshot are related to the help. The options -?, -h, -help, and --help display what we are showing in these screenshots, and the options -X and --help-extra provide additional information. You can try all of them on your own.

The last section of the help output looks as follows:

We will not discuss these options. Just note how to use the long option (with two hyphens) explained in the last preceding line.

The compilation command

As mentioned earlier, a program written in Java is called a source code, and is stored in a .java file. The compilation command javac reads it and creates a corresponding .class file with Java Byte Code.

Let us run the command javac without specifying a .java file. It will show help. Let us review it in sections:

The help tells us that this command has the following format:

javac <options> <source files>

To compile just a few files, one can list them in the command line after options (if the file is not in the current directory, one has to prepend the filename with an absolute or relative path). Listed files are separated by colons (:) for Oracle Solaris, or semicolons (;) for Windows, and can be directories, .jar files, or .zip files. It is also possible to list all source files in a file and provide this filename using the @filename option (see the preceding screenshot). But do not try to remember all of this. You will rarely (if ever) run the commands java or javac explicitly. You will probably use an IDE that will do it for you (see Chapter 3, Your Development Environment Setup). That is also the reason we are going to skip most of the options listed in the preceding screenshot and will mention only two of them: --class-path (or -classpath, or -cp), which specifies where to find the .class files required by the currently compiled code, and -d, which indicates where to put the created .class files.

Here is the next section of javac help:

The only option from the preceding screenshot that we will mention here is --help (or -help), which provides the same help message that we are going through now.

Finally, the last section of javac help is as follows:

We have already described the option --source-path (or -sourcepath). The option -verbose asks the compiler to provide a more detailed report about what it is doing, while the option --version (or -version) displays the JDK version:

Command jcmd and other commands

There are more than a dozen other Java commands (tools and utilities) that you will only start using probably after several years of professional programming, if at all. They are all described in the Oracle Java documentation online. Just search the Java utilities and tools.

Among them, we find only one command that is very useful from day one of Java programming. It is the command jcmd. If you run it, it displays all of the Java processes (JVM instances) that are running on your computer. In this example, you can see three Java processes, with the process IDs 3408, 3458, and 3454:

Process 3408 runs the Maven server (your IDE will typically start it). Process 3458 is our running of jcmd. And process 3454 is an editor (IDE) IntelliJ IDEA that is running the small demo application com.packt.javapath.App.

This way, you can always check to see if there is a runaway Java process on your computer. If you would like to stop it, you can use a Task Manager, or the command kill, which requires PID.

Knowledge of PID is also needed when you would like to monitor your Java application. We will talk about that in Chapter 11, JVM Processes and Garbage Collection.

With this, we complete our overview of Java commands. As we already mentioned, your IDE will use all of these commands behind the scenes, so you will probably never use them unless you do production support (which is several years out, after you start learning Java). But we feel that you need to know them, so that you can connect the dots of the Java development process.

Exercise – JDK tools and utilities

On your computer, find the Java installation directory, and list all of the commands (tools and utilities)—the executables—present there.

You are in the right spot if you see java and javac among other executables.

Answer

Here is the list of all of the executables installed with Java 10.0.1:

One of the ways to find this directory is to look at the value of the environment variable PATH. For example, on a Mac computer, Java is installed in the directory /Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home/bin.

The Oracle documentation that describes the JVM installation location can be found at https://www.java.com/en/download/help/version_manual.xml.

Summary

In this chapter, you have learned the most important Java related terms—JVM, JDK, SDK, Java platform, and others, covering the main phases of a Java program's life cycle, from source code to bytecode to execution. You also learned about Java's history, the motivation behind its creation, its editions, and its versions. The practical steps and advice provided have helped you to install Java on your computer and exercise its main commands, java, javac, and jcmd. For more details, you were referred to the official Oracle documentation. The ability to find and understand this documentation is a prerequisite for a successful career as a Java programmer, so we recommend that you follow all of the provided links and do some related searching on the internet, so that you feel comfortable finding good sources of information.

In the next chapter, we will dive into Java as a programming language, and will cover the basics. This will become a foundation (or a jumping board, if you will) for the following chapters. If you are new to Java, we recommend that you continue reading without skipping, because each chapter is built on knowledge from the previous one. Even if you have some Java exposure, it is always helpful to review the basics again. Repetitio est mater studiorum (Repetition is the mother of study/learning), says a Latin proverb.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Enjoy your first step into the world of programming
  • Understand what a language is and use its features to build applications
  • Learn about a wide variety of programming applications

Description

Have you ever thought about making your computer do what you want it to do? Do you want to learn to program, but just don't know where to start? Instead of guiding you in the right direction, have other learning resources got you confused with over-explanations? Don't worry. Look no further. Introduction to Programming is here to help. Written by an industry expert who understands the challenges faced by those from a non-programming background, this book takes a gentle, hand-holding approach to introducing you to the world of programming. Beginning with an introduction to what programming is, you'll go on to learn about languages, their syntax, and development environments. With plenty of examples for you to code alongside reading, the book's practical approach will help you to grasp everything it has to offer. More importantly, you'll understand several aspects of application development. As a result, you'll have your very own application running by the end of the book. To help you comprehensively understand Java programming, there are exercises at the end of each chapter to keep things interesting and encourage you to add your own personal touch to the code and, ultimately, your application.

Who is this book for?

Introduction to Programming is for anybody who wants to learn programming. All you’ll need is a computer, internet connection, and a cup of coffee.

What you will learn

  • •Understand what Java is
  • •Install Java and learn how to run it
  • •Write and execute a Java program
  • •Write and execute the test for your program
  • •Install components and confgure your development environment
  • •Learn and use Java language fundamentals
  • •Learn object-oriented design principles
  • •Master the frequently used Java constructs
Estimated delivery fee Deliver to Taiwan

Standard delivery 10 - 13 business days

$12.95

Premium delivery 5 - 8 business days

$45.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 15, 2018
Length: 722 pages
Edition : 1st
Language : English
ISBN-13 : 9781788839129
Category :
Languages :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Taiwan

Standard delivery 10 - 13 business days

$12.95

Premium delivery 5 - 8 business days

$45.95
(Includes tracking information)

Product Details

Publication date : Jun 15, 2018
Length: 722 pages
Edition : 1st
Language : English
ISBN-13 : 9781788839129
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 131.97
Java Programming for Beginners
$38.99
Mastering Java 11
$48.99
Introduction to Programming
$43.99
Total $ 131.97 Stars icon
Banner background image

Table of Contents

20 Chapters
Java Virtual Machine (JVM) on Your Computer Chevron down icon Chevron up icon
Java Language Basics Chevron down icon Chevron up icon
Your Development Environment Setup Chevron down icon Chevron up icon
Your First Java Project Chevron down icon Chevron up icon
Java Language Elements and Types Chevron down icon Chevron up icon
Interfaces, Classes, and Object Construction Chevron down icon Chevron up icon
Packages and Accessibility (Visibility) Chevron down icon Chevron up icon
Object-Oriented Design (OOD) Principles Chevron down icon Chevron up icon
Operators, Expressions, and Statements Chevron down icon Chevron up icon
Control Flow Statements Chevron down icon Chevron up icon
JVM Processes and Garbage Collection Chevron down icon Chevron up icon
Java Standard and External Libraries Chevron down icon Chevron up icon
Java Collections Chevron down icon Chevron up icon
Managing Collections and Arrays Chevron down icon Chevron up icon
Managing Objects, Strings, Time, and Random Numbers Chevron down icon Chevron up icon
Database Programming Chevron down icon Chevron up icon
Lambda Expressions and Functional Programming Chevron down icon Chevron up icon
Streams and Pipelines Chevron down icon Chevron up icon
Reactive Systems Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact [email protected] with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at [email protected] using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on [email protected] with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on [email protected] within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on [email protected] who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on [email protected] within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela