© Ron Dai 2019
R. DaiLearn Java with Mathhttps://doi.org/10.1007/978-1-4842-5209-3_3

3. Java Basics

Ron Dai1 
(1)
Seattle, WA, USA
 

Today, computers use so many different kinds of programming languages. Each of them plays an essential role in a certain area to solve a specific type of problem. Java was invented and developed by Sun Microsystems in the early 1990s; it was then acquired by Oracle, Inc. After 20 years of development, Java has now become one of the most popular programming languages in the world.

Java is a typical OOP, a.k.a. object-oriented programming language, which deals with a bunch of “objects.” These objects contain data and operations. Operations are about what can be done to data within the object.

In the Java world, there is an open source development tool called Eclipse. It has rich features, and it is free to use. Eclipse is also a suitable tool for beginners. We will be using Eclipse to start exploration of the Java world.

What Features Does Java Have?

Object-Oriented

An object is a “thing” that has some attributes (a.k.a. Properties). The object performs a set of operations (a.k.a. Methods). The operations define behaviors of the object.

../images/485723_1_En_3_Chapter/485723_1_En_3_Figa_HTML.png

Class-Based

A class is simply a representation of a type of object. It is a template that describes details of an object. A class is composed of three elements: a name, attributes, and operations.

Java Bytecode

Java bytecode is the machine language of the Java virtual machine (JVM). Java bytecode will be translated to a machine-specific native code by the JVM, when it runs on that machine. So, on a Windows computer, the JVM bytecode is translated into Windows-specific native code; and on a Linux computer, it is translated into Linux-specific native code. This is called write once, run anywhere (shown in Figure 3-1).
../images/485723_1_En_3_Chapter/485723_1_En_3_Fig1_HTML.png
Figure 3-1

Write once, run anywhere

When a JVM loads a class file, it gets one stream of bytecodes for each method in the class. The bytecodes for a method are executed when that method is invoked during the execution of the program.

Although it might be overwhelming to beginners, we also want to introduce some of the other powerful features built into the Java language as well as its runtime engine.
  • Multi-threading

    Java language supports multi-threading capabilities, which enable multiple tasks running at the same time. This feature boosts up the computing power of the Java code and makes Java applications highly responsive.

  • Secure code

    Java doesn’t use pointers like in other languages (i.e., C or C++). This has avoided a traditional security loophole. In addition to runtime checking, Java does static-type checking using strict rules during compilation. Java has its exception handling to catch unexpected errors. Java provides a cryptographic security mechanism when users are getting code across networks and so on. These security functionalities make Java a more secure programming language than other ones.

  • Garbage collection

    Java has its own uniquely designed memory-management mechanism. Unlike C/C++ language, Java doesn’t require developers to take care of memory management in terms of when to register or free the memory. It will automatically collect and free up the unused memories. This has made development work much easier.

The last but not least powerful feature to mention is Java’s super-rich open source libraries. This is one of the big reasons why Java is increasingly so popular among developers. And, because Java’s developer community is getting bigger and stronger, Java will evolve to be an even more powerful programming language over time.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.218.184