Unit I Java API - Application Programming Interface
• The Java API is the set of classes included with
the Java Development Environment.
• These classes are written using
the Java language and run on the JVM.
• The Java API includes everything from
collection classes to GUI classes. Java API - Application Programming Interface
• The Java API is a document which gives you
the list of all the packages, classes, and interfaces, along with their fields and methods.
• Using these API’s, the programmer can know
how to use the methods, fields, classes, interfaces provided by Java libraries. API Specification • java.sql : Provides the API for accessing and processing data stored in a data source (usually a relational database) using the Java programming language.
• java.awt.color: Provides classes for color spaces.
• java.awt.font: Provides classes and interface relating
to fonts.
• java.io: Provides for system input and output through
data streams Java Virtual Machine (JVM) & its Architecture
• Java Virtual Machine (JVM) is a engine that provides
runtime environment to drive the Java Code or applications.
• It converts Java bytecode into machines language.
• JVM is a part of Java Run Environment (JRE).
• In other programming languages, the compiler produces
machine code for a particular system.
• However, Java compiler produces code for a Virtual Machine
known as Java Virtual Machine. How JVM works • First, Java code is complied into bytecode.
• This bytecode gets interpreted on different machines
Between host system and Java source, Bytecode is an intermediary language.
• JVM is responsible for allocating memory space.
• The JVM performs following operation:
• Loads code • Verifies code • Executes code • Provides runtime environment JVM Architecture JVM Architecture 1) Class Loader: The class loader is a subsystem used for loading class files. It performs three major functions viz. Loading, Linking, and Initialization.
2) Method Area: JVM Method Area stores class
structures like metadata and the code for methods.
3) Heap: All the Objects, their related instance variables,
and arrays are stored in the heap. This memory is common and shared across multiple threads. JVM Architecture 4) JVM language Stacks : Java language Stacks store local variables, and it’s partial results.
5) PC Registers : PC register store the address of the
Java virtual machine instruction which is currently executing.
6) Native Method Stacks: Native method stacks hold
the instruction of native code depends on the native library. JVM Architecture 7) Execution Engine: It is a type of software used to test hardware, software, or complete systems. The test execution engine never carries any information about the tested product.
8) Native Method interface : The Native Method
Interface is a programming framework. It allows Java code which is running in a JVM to call by libraries and native applications.
9) Native Method Libraries: Native Libraries is a
collection of the Native Libraries(C, C++) which are needed by the Execution Engine. JDK: Java Development Kit • JDK is an acronym for Java Development Kit.
• The Java Development Kit (JDK) is a software
development environment which is used to develop java applications and applets.
• It physically exists.
• It contains JRE development tools.
JDK: Java Development Kit • JDK is an implementation of any one of the below given Java Platforms released by Oracle corporation:
• The JDK contains a private Java Virtual Machine (JVM)
and a few other resources such as an interpreter/loader (Java), a compiler (javac), an archiver (jar), a documentation generator (Javadoc) etc. to complete the development of a Java Application. Java Compiler And Interpreter Compiler • A compiler is a program that reads a program written in the high-level language and converts it into the machine or low-level language and reports the errors present in the program.
• The returned target code file can be run with
many different inputs, over and over.
• the compiler doesn’t need to be around for any
subsequent reruns. Compiler stages can be grouped into two parts
• Analysis Phase of the compiler is also referred
to as the front end in which program is divided into fundamental constituent parts and checks grammar, semantic and syntax of the code after which intermediate code is generated.
• Analysis phase includes lexical analyzer,
semantic analyzer, and syntax analyzer. Compiler stages can be grouped into two parts
• Synthesis phase of the compiler is also known
as the back end in which intermediate code is optimized, and the target code is generated.
• Synthesis phase includes code optimizer and
code generator. PHASES OF COMPILER- Analysis Phase • Lexical Analyzer: It scans the code as a stream of characters, groups the sequence of characters into lexemes and outputs a sequence of tokens with reference to the programming language.
• Syntax Analyzer: In this phase, the tokens that are
generated in the previous stage are checked against the grammar of programming language, whether the expressions are syntactically correct or not. It makes parse trees for doing so. PHASES OF COMPILER- Analysis Phase • Semantic Analyzer: It verifies whether the expressions and statements generated in the previous phase follow the rule of programming language or not and it creates annotated parse trees.
• Intermediate code generator: It generates an
equivalent intermediate code of the source code. PHASES OF COMPILER- Synthesis phase • Code Optimizer: It improves time and space requirement of the program. • For doing so, it eliminates the redundant code present in the program.
• Code generator: This is the final phase of the compiler
in which target code for a particular machine is generated.
• It performs operations like memory management,
Register assignment, and machine-specific optimization. Interpreter • The interpreter is an alternative for implementing a programming language and does the same work as a compiler.
• Interpreter performs lexing, parsing and type
checking similar to a compiler.
• But interpreter processes syntax tree directly to
access expressions and execute statement rather than generating code from the syntax tree. Interpreter • An interpreter may require processing the same syntax tree more than once that is the reason why interpretation is comparatively slower than executing the compiled program.
• A compiler is comparatively faster than
Interpreter as the compiler take the whole program at one go whereas interpreters compile each line of code after the other. • The Compiler of java called as javac converts source code into an Intermediate file known as Bytecode file.
• The Bytecode file is unique for all types of OS means
bytecode is platform-independent.
• The Interpreter of java (java) converts Bytecode into
the specific OS-compatible machine code.
• This code will vary according to OS.
Java Applications • Mobile Applications. • Desktop GUI Applications. • Web-based Applications. • Enterprise Applications. • Scientific Applications. • Gaming Applications. • Big Data technologies. • Business Applications. Java Mobile Applications • Android OS is closely based on Java
• most mobile app developers call Java their
official programming language.
• Java is compatible with app designing
software such as Kotlin and Android Studio. Java Desktop GUI Applications • GUI stands for Graphic User Interface, and Java enables GUI development through resources like Abstract Windowing Toolkit (AWT), JavaFX, and Swing.
• AWT features several pre-made components such as
button, list, menu, and several third-party components.
• JavaFX is composed of a set of graphics and media
packages, providing Swing interoperability and 3D graphics features. Java Desktop GUI Applications
• Swing is a GUI widget that offers advanced
elements such as lists, scroll panes, tables, tabbed panels, and trees.
• with these tools, programmers can develop
any desktop application. Java Web-based Applications • Java provides high security and simple coding, two elements that attract web application developers.
• Servlets and JSPs give effective support to web
applications and offer the potential to develop whatever kind of programs needed. Java Web Servers and Application Servers
• The robust Java ecosystem has given rise to
numerous Java web and application servers.
• Web server space is home to servlets like Apache
Tomcat, Project Jigsaw, and Rimfaxe Web Server (RWS).
• Meanwhile, servlets like WebLogic, WebSphere,
and JBoss EAP have a firm foothold in commercial application server space. Java Enterprise Applications • Java Enterprise Edition (Java EE) is a popular platform that offers API and runtime environments for scripting tasks, including web services and network applications, to name a couple.
• According to Oracle, Java runs on 97% of
enterprise-owned computers.
• Java is also recognized as being the foundation for
many banking applications that use Java in their entire process, from front-end users to back-end servers. Java Scientific Applications • Science-related mathematical operations and calculations require developing apps that are extremely fast, highly secure, easily maintained, and highly portable.
• Java fills this need nicely.
• Powerful scientific applications like MATLAB rely
on Java as part of the core system and interacting user interfaces. Java Gaming Applications • Java and the gaming industry are a match made in heaven.
• Java supports the jMonkey engine, one of the most
potent 3D engines available today.
• And 2D games are a snap too; just couple Java with
CSS, and you’re good to go.
• So, no matter what kind of games developers are
designing, Java has them covered. Java Big Data Technologies • Hadoop, arguably the most well-known and well-used big data platform, is written in Java.
• Additionally, Scala, a competing programming
language, owes its origins to Java.
• Scala was created to address some of Java’s
drawbacks. Java Business Applications • Big enterprises turn to the Java EE platform to develop large-scale, multi-tiered network applications that are scalable, reliable, and secure.
• Java offers features that deliver a powerful app
that is less complex by providing tools like a development model, API, and runtime environment.
• These features free up developers to concentrate
more on the app’s functionality. Java Distributed Applications • Distributed applications are programs that run on multiple computers linked to the same network.
• For example, Internet Explorer is a distributed
application.
• These applications are split into two separate
programs: client software and server software. • Distributed applications bring their unique challenges due to their distributed characteristics and the dynamic quality of the servers and systems that run them.
• The Java Intelligent Networking Infrastructure, or JINI
for short, represents an infrastructure that provides, registers, and finds distributed services by their specifications.
• JavaSpaces, a JINI component, supports distribution,
persistence, and object migration within a network. Java Cloud-based Applications • Cloud computing is defined as using off-site servers via the internet for processing, managing, and storing data.
• It’s a pay-as-you-go model and replaces local, in-house networks.
• Cloud computing is often used for distributed computing systems.
• There are many Java Cloud development tools available, such as
the Oracle Java Cloud Service.
• It serves as a platform for easily creating and configuring Oracle
WebLogic servers and their application environments.