From the beginning, Java has followed some clearly stated principles—it's a simple, object-oriented, and familiar language. Its simplicity lies greatly in its consistency. Once you learn how to do one thing in Java, you know how to do it the same way throughout the language because it never deviates from the way the language is architected. It's an object-oriented language.
- [Facilitator] From the beginning, Java has followed some clearly stated principles. First of all, it's a simple, object oriented, and familiar language. Its simplicity lies in its consistency. Once you learn how to do one thing in Java, you always know how to do it throughout the language, because it never deviates from the way the language is architected. Java is object oriented, so once you understand the principles of encapsulation, inheritance, and polymorphism, and how those are implemented in Java, you'll have a much better sense of how to architect your applications.
Java was created to be robust and secure. Its robustness lies greatly in its object oriented characteristics, because everything is built in functions, which are known as methods, and in properties, which are known as fields. You create applications by combining classes together. This lets you create your code in small chunks, and it makes it easy to debug and maintain your applications over time. Java is portable, so you are able to compile at once and then run your application on multiple operating systems and processors.
In the world of Android, this means that you can build your app once, and then deploy it to multiple devices, regardless of who made the devices and which version of Android it's running. Java was created to be high performance. The original version of the Java Virtual Machine wasn't as fast as C++ applications, but over the years, it's improved enormously. Today, Java applications run just as fast or sometimes even faster than applications built in C++.
Finally, Java was created as an interpreted language. It supports multi-threading and it's dynamic. Interpreted means that the application is compiled to a format that's interpreted at runtime, rather than being run as machine code directly. That's what makes the applications portable. It's multi-threaded, which makes it easy to build applications that do more than one thing at the same time. And, it's dynamic. In the context of Java, this refers to polymorphic behavior, where you can declare a variable or an object as a particular type and then refer to it either as its native type or as any of the types it's extended from.
Java's runtime architecture is designed for this portability. As I mentioned, Java is an interpreted language. Your text-based code is compiled to bytecode instead of machine language. That bytecode can be moved between operating systems or platforms without having to be recompiled. Here is the stack that Java runs on. At the lowest level is the operating system itself, which could be Windows, Mac OS, some form of Linux or Unix.
On top of that is the Java Virtual Machine. When you install the JRE, or Java Runtime Environment, or the JDK, you're getting the Java Virtual Machine as part of that installation. There's a different version of the Java Virtual Machine for each operating system, and there are custom JVMs from different vendors. For this course, we'll always be using the JVM from Oracle. But, compatible JVMs from other vendors are available. On top of the JVM, you'll find the runtime libraries.
The JRE includes bundled runtime libraries. Prior to Java 9, these came as a single monolithic file. Starting with Java 9, the core runtime is modular, and you can pick and choose which elements you want to package your application with. Then you can add in your own custom libraries, or libraries from other software developers. Finally, on top of all that is your custom bytecode. Your own application. Your code in Java, you'll compile it to bytecode.
You'll package it with all the runtime libraries your application needs, and then deploy it to a system that has the Java Virtual Machine. If you're working in Android, this process is somewhat different. Instead of a Java Virtual Machine, you'll be using the Android runtime or ART. But, either way-- And your Java bytecode is turned into another kind of bytecode called DEX. But, either way, you're deploying portable bytecode instead of operating system specific machine code.
Java has some syntactical similarities to C++, but at its core it's a very different language. C++, for example, is compatible with C. It's built on top of C. So, if you have code that you wrote in C, you can include it in a C++ application without significant rewriting. Java does not have that backward compatibility with C or with any other language. Code you write in Java only runs in Java. C++ compiles to native machine language that only runs on a single operating system, while Java compiles to portable bytecode.
And there are many other differences between the two languages that are shown here. One of the most important improvements in Java compared to C++ was the introduction of managed memory access. That is, in Java, you don't have to explicitly allocate and deallocate memory the way you do in C++. This results in fewer bugs and easier maintained ability. Also, Java does not implement multiple inheritance, like C++ does. You're limited to single inheritance.
And there's a third edition known as Java Platform, Micro Edition, that's used to program micro devices. Microcontrollers, sensors, and mobile devices. Now, if you're working in Android, you're working in Java Platform, Standard Edition even though you're programming for mobile devices. So, you don't need the Micro Edition and you don't need the Enterprise Edition if you're an Android developer. If, however, you want to build those industrial-strength web applications, you'll need to learn Java EE as well as SE.
The Java Runtime Environment includes the JVM, or Java Virtual Machine. It's supported on all common, popular operating systems. The JRE runs all of the applications that you might run locally on your computer, regardless of whether they're visual applications running on the desktop, applets running in a browser, or server-based applications. They all use the JRE. The JRE should be updated regularly to keep up with any security issues that might emerge.
The JRE is not used on mobile operating systems, particularly on Android. These have their own runtimes as I mentioned previously. The Java Development Kit, or SE, is available at no cost and it includes all the tools you need to compile and package your applications. These include these command line applications: Java, which is the runtime itself, javac, that's the compiler, javadoc, jar, and others.
So, after you've installed the latest JDK from Oracle, you're ready to code, compile, and package your Java applications.
- Reviewing the principles and components of Java
- Choosing a development environment
- Testing simple Java code in JShell
- Creating a project in IntelliJ IDEA
- Working with primitive variables
- Working with Boolean and character values
- Working with String values
- Managing program flow
- Creating reusable code with methods