From the course: Java 8 Essential Training
Principles and components of Java - Java Tutorial
From the course: Java 8 Essential Training
Principles and components of Java
- From the beginning, Java has followed some clearly stated principles. First of all, it's a simple, object-oriented and familiar language. It's simplicity lies greatly in its consistency. Once you learn how to do one thing in Java, you know how to do it the same throughout the language because it never deviates from the way the language is architected. It's an object-oriented language 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. For developers who've worked with C-style languages like C and C++, the syntax of Java is very familiar. Java was created to be robust and secure. It's robustness lies greatly in its object-oriented characteristics. Because you're designing everything as an object, everything has methods or functions and properties also known as fields that are members of classes. This lets you create your code in small chunks and it makes it easy to debug and maintain your applications over time. Java was designed to be portable so that you'd be able to compile it once and then run your application on multiple operating systems and processors. The language was designed 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 been improved enormously. Today Java applications run just as fast as, or sometimes even faster than applications built in C++. Finally, Java was created as an interpreted language, it supports multithreading and it's dynamic. Interpreted means that the application is compiled to a format that's interpreted at runtime rather than being run directly as machine code, that's what makes the applications portable. It's multithreaded and it makes it easy to build applications that can do more than one thing at a time. And it's dynamic in that it can change data types at runtime so long as those data types are compatible with each other. Let's talk about Java's runtime architecture. Again, it's an interpreted language. Your text-based code is compiled to bytecode rather than machine language. That's what makes it portable between operating systems. Here's the software stack that's used runtime. You start with the operating system. You can run Java applications on Windows, Mac, Linux, Solaris and any other operating system for which there is a usable Java Virtual Machine. The Java Virtual Machine or JVM that you use most of the time will be the one provided by Oracle, that was originally created by Sun Microsystems. But there are other JVMs out there including one provided by IBM and one that's provided for Android by Google, and there are many others. On top of the Virtual Machine, you add the core runtime and additional libraries. The core runtime is sometimes called the Java Class Library. It's included with both the JDK and the Java Runtime Environment or JRE. Finally, your application is compiled into bytecode and that bytecode runs on top of all of those other layers. Let's compare Java to a couple of popular languages. First, C++. Java was originally create by C++ developers and they had in mind improving the developers' lot. Here are some ways in which Java is different from C++. If you're a C developer, all of your code can run on C++ as well. The two languages are compatible with each other, that's not true for Java. Even though Java has syntax that's very similar to C and C++, its code is unique. It has its own rules and its own syntax. I've mentioned earlier that C++ is complied to native machine language and while that makes it very fast and gives it access to low-level functionality, it means that your application has to be recompiled for each operating system and processor that you want to target. Java is compiled to bytecode. Because C++ is compiled to native machine language, it allows direct calls to the native system. In Java there's an interface called Java Native Interface, or JNI, referred to sometimes as JNI. It lets you call those native functions through the JVM. If you use JNI, you have to create your own native code, typically with C++. C++ lets you write once and then as long as you followed standard C++ syntax and libraries, you can recompile for each operating system you're targeting. Whereas with Java, you can write and compile once and then run anywhere. Java runs in a protected virtual machine environment, and again, you have to go through that JNI interface to make those low-level system function calls. Memory management is also very different. C++ requires explicit memory management, allocating and deallocating memory as you need it. In Java, memory is managed for you. There are also certain areas where C++ can do things that Java can't. C++, for example, supports multiple inheritance while Java is limited to single inheritance, although you can implement multiple interfaces in Java. Let's also compare Java to JavaScript. Even though the names of these languages share the term Java, they're not really closely related. They share C-style syntax but otherwise have very different purposes and very different principles. JavaScript is based on the ECMAScript standard and there are many implementations of that standard, including JavaScript itself, a version of JavaScript that Microsoft has implemented, sometimes known as JScript, Adobe's ActionScript used in Flash and many, many others. Java is compiled to bytecode, whereas JavaScript is not compiled at all, it's interpreted at runtime. JavaScript is the dominant programming language in web browsers. To run Java code in a web browser, you would need an additional plugin. In Java, you can call native functions through the JNI interface. But JavaScript, at least when executed within a web browser, runs in a security sandbox that doesn't allow it access to local resources. Both Java and JavaScript are broadly portable, Java through its JVMs and JavaScript through broad implementation of the language in various browsers and other runtimes. Both Java and JavaScript use managed memory access but they have very different inheritance models. Java uses a class-based inheritance model while JavaScript uses something called prototype-based inheritance. Java is published in three distinct editions. The language itself is known as Java Platform, Standard Edition or SE. This is the core language and runtime environment. On top of that, you can add Java Platform, Enterprise Edition or Java EE. This is a standard for building industrial-strength web applications. And there are many JEE application servers out there including some that are paid and some that are free. Java Platform, Micro Edition or ME is the standard for programming micro-controllers, sensors, and mobile devices. For example, the SIM card on most smartphones is programmed in Java. I've mentioned the terms JRE and JDK previously. The JRE is the runtime environment. In the past, the JRE was installed automatically on common operating systems such as Mac and Windows. Modern distributions of these operating systems come without the JRE so it's up to the user to install it. But the JRE is free and can be downloaded from Oracle individually. There are versions of the JRE for Windows, Linux, OS X, Solaris and other operating systems. The JRE runs all Java applications on the desktop and is also used at runtime in a JEE environment to run server-based applications. The Java Runtime Environment has reputation for having security issues. It's very hackable but Oracle does its best to keep up with these challenges through issuing regular updates. It's up to the individual computer user or administrator to install these updates to make sure that their systems are secure. Again, mobile operating systems, such as Android, have their own distinct runtimes. They don't use Oracle's JRE. The JDK or the Java SE Development Kit is also available at no cost from Oracle. It lets you compile and package your Java-based applications and includes these critical command line tools in addition to many others. If you code and compile Java from the command line, you'll need to learn how to use these tools. But if you use one of the common Java IDEs, or Integrated Development Environments, they protect you from having to know the details of how these command line tools operate. So that's a look at the principles and components of the Java programming language. In this course, I'm going to focus on Java SE, just the programming language. I won't be getting into Enterprise Edition or Micro Edition but those are also critical elements of the Java ecosystem.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.