DEV Community

Cover image for Java for Beginners: Introduction to Java
Jeff Odhiambo
Jeff Odhiambo

Posted on

Java for Beginners: Introduction to Java

What is JAVA?

Java is a high-level, third generation programming language, like C,C++, Perl, and many others. You can use Java to write computer applications that play games, store data etc. Compared to other programming languages, Java is most similar to C++.
What's special about Java in relation to other programming languages is that it lets you write special programs called applets that can be downloaded from the Internet and played safely within a web browser.

History

Java is an object-oriented programming language created by James Gosling from Sun Microsystems (Sun) in 1991. The first publicly available version of Java (Java 1.0) was released in 1995.
Sun Microsystems was acquired by the Oracle Corporation in 2010.
Over time new enhanced versions of Java have been released. The current version of Java is Java 8.
From the Java programming language, the Java platform evolved. The Java platform is usually associated with the Java virtual machine and the Java core libraries.
In 2006, Sun started to make Java available under the GNU General Public License (GPL).

The Java compiler

A compiler is a program that converts a high-level language to a machine language, i.e. from source code to binary code.
When you program from the Java platform, you write source code with a .java file extension and then compile them. The java compiler converts high-level java code into bytecode.
The compiler checks your code against the language's syntax rules, then writes out bytecodes in a .class files. Bytecodes are standard instructions targeted to run on a Java virtual machine (JVM).
In adding this level of abstraction, the Java compiler differs from other language compilers, which write out instructions suitable for the CPU chipset the program will run on.
An interpreter is a program that translates or converts a high-level language to a machine-language line by line. In Java, the Just In Time Code generator converts the bytecode into the native machine code which are at the same programming levels. Hence java is both compiled as well as an interpreted language.

Java virtual machine(JVM)

Java programs are compiled by the Java compiler into bytecode. The JVM is a software implementation of a computer that executes programs like a real machine. At run time, the JVM reads and interprets a .class files and executes the program's instructions on the native hardware platform for which the JVM was written. The Java virtual machine is written specifically for a specific operating system, e.g., for Linux a special implementation is required as well as for Windows.
The JVM is the heart of the Java language's "write-once, run-anywhere" principle. Your code can run on any chipset for which a suitable JVM implementation is available. JVMs are available for major platforms like Linux and Windows, and subsets of the Java language have been implemented in JVMs for mobile phones and hobbyist chips.
JVM

What are the tasks of JVM?

JVM performs byte-code interpretation, garbage collection, exception handling, thread management, initialization of variables, and type definition.

Java platform

The Java platform is the name given to the computing platform from Oracle that helps users to run and develop Java applications. The platform does not just enable a user to run and develop Java applications but also features a wide variety of tools that can help developers work efficiently with the Java programming language. The platform consists of two essential components:

  • Java Runtime Environment (JRE), which is needed to run Java applications and applets.
  • Java Development Kit (JDK), which is needed to develop those Java applications and applets. If you have installed the JDK, it comes equipped with a JRE as well.

When installed on a computer the JRE provides the operating system with the means to run Java programs, whereas the JDK is a collection of tools used by a programmer to create Java applications.
The JDK has as its primary components a collection of programming tools, including:

Basic Tools

These tools are the foundation of the JDK. They are the tools you use to create and build applications.

  • appletviewer - Run and debug applets without a web browser.
  • apt - Annotation processing tool.
  • extcheck - Utility to detect Jar conflicts.
  • jar - Create and manage Java Archive (JAR) files.
  • java - The launcher for Java applications. The old deployment launcher, JRE, is no longer provided.
  • javac - The compiler for the Java programming language.
  • javadoc - API documentation generator.
  • javah - C header and stub generator. Used to write native methods.
  • javap - Class file disassembler
  • jdb - The Java Debugger. See JPDA for the debugger architecture specifications. ###Security Tools These security tools help you set security policies on your system and create applications that can work within the scope of security policies set at remote sites. keytool - Manage keystores and certificates. jarsigner - Generate and verify JAR signatures. policytool - GUI tool for managing policy files.

More

Characteristics of Java

Object Oriented
In Java, everything is an Object. Java can be easily extended since it is based on the Object model.
Simple
Java is designed to be easy to learn. If you understand the basic concept of OOP Java, it would be easy to master.
Platform Independent
When Java is compiled, it is not compiled into platform-specific machine, rather into platform-independent byte code. This byte code is distributed over the web and interpreted by the Virtual Machine (JVM) on whichever platform it is being run on.
Secure
With Java's secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are based on public-key encryption.
Portable
Being architecture-neutral and having no implementation-dependent aspects of the specification makes Java portable.
Multithreaded
With Java's multithreaded feature it is possible to write programs that can perform many tasks simultaneously. This design feature allows the developers to construct interactive applications that can run smoothly.
Architecture-neutral
Java compiler generates an architecture-neutral object file format, which makes the compiled code executable on many processors, with the presence of Java runtime system.
Interpreted
Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is more rapid and analytical since the linking is an incremental and lightweight process.
Dynamic
Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment. Java programs can carry an extensive amount of run-time information that can be used to verify and resolve accesses to objects at run-time.
High Performance
With the use of Just-In-Time compilers, Java enables high performance.
Distributed
Java is designed for the distributed environment of the internet.

Development process with java

Java source files are written as plain text documents. The programmer typically writes Java source code in an Integrated Development Environment (IDE) for programming. An IDE supports the programmer in the task of writing code, e.g., it provides auto-formatting of the source code, highlighting of the important keywords, etc. At some point, the programmer (or the IDE) calls the Java compiler (javac). The Java compiler creates the bytecode instructions. These instructions are stored in a .class file and can be executed by the Java Virtual Machine.

Garbage collector

The JVM automatically recollects or reclaims the memory which is not in use by the program. The Java garbage collector checks all object references and finds the objects which can be automatically released. While the garbage collector relieves the programmer from the need to explicitly manage memory, the programmer still needs to ensure that he does not keep unneeded object references, otherwise the garbage collector cannot release the associated memory.
Keeping unneeded object references is typically called memory leaks.

Classpath

The classpath defines where the Java compiler and Java runtime look for a .class files to load. These instructions can be used in the Java program. For example, if you want to use an external Java library you have to add this library to your classpath to use it in your program. Java is case-sensitive, e.g., variables called jeff and Jeff are treated as different variables

Java Development Tools

Java source files are written as plain text documents. The programmer writes Java source code in an Integrated Development Environment(IDE) for programming. An integrated development environment (IDE) or interactive development
environment
is a software application that provides comprehensive facilities for programmers to use for software development. An IDE normally consists of a source code editor, build automation tools, and a debugger.
Several modern IDEs integrate with Intelli-sense coding features. An IDE also supports the programmer in the task of writing code, e.g., it provides auto-formatting of the source code, highlighting of the important keywords, etc.
Common Java IDE Tools include:

  • IntelliJ IDEA
  • Eclipse Java development tools (JDT)
  • JCreator — Java IDE
  • Java-Editor
  • NetBeans IDE among others

In the next article, we will discuss the Installation of Java

Thanks for taking your time to read this article

Discussion (4)

Collapse
vishnusanal profile image
Vishnu Sanal. T

Awesome read!

Collapse
killallnano profile image
Jeff Odhiambo Author

thanks

Collapse
suhakim profile image
sadiul hakim

I am learning Java.

Collapse
killallnano profile image
Jeff Odhiambo Author

Hope you find these articles useful 😀