Java Fundamentals
Java Fundamentals
Programming
● The language like C, Pascal, Fortran, etc are called procedure oriented
programming languages.
● On the other hand language like C++, Java and Python use classes and
objects in their programs and are called object oriented programming
language
Java is a programming language and a platform. Java is a high level, robust, object-oriented and secure
programming language.
James Gosling
Metrics C C++ Java
Course Name: Fundamental of Java Programming Course Instructor: Prof. S. R. Badiger, E&TC Dept, BSCOER, Pune
6. Java is Portable Programming Language
● In C/C++, the source code may run slightly differently on different hardware platforms,
● You can run Java bytecode on any hardware that has a compliant JVM which can
● Moreover, any changes and updates made in Operating Systems, Processors and
● This buzzword means that the program written on one platform or OS is independent of
other platforms or environments and can run on any other Operating System without
recompiling them.
● Byte-code is not dependent on any machine architecture and Java Virtual Machine
● This feature is very useful when we develop applets or download applications from the
Internet.
8. Java is Dynamic Programming Language
● Java is dynamic and extensible means with the help of OOPs, we can add classes and add
new methods to classes, creating new classes through subclasses. This makes it easier for
● Java gives the facility of dynamically linking new class libraries, methods, and objects. It is
● Java even supports functions written in other languages such as C and C++ to be written in
Java programs. These functions are called “native methods”. These methods are
● Usually, a computer language can be either compiled or interpreted. Java integrates the
power of Compiled Languages with the flexibility of Interpreted Languages.
● Java compiler (javac) compiles the java source code into the bytecode.
● Java Virtual Machine (JVM) then executes this bytecode which is executable on many
operating systems and is portable.
● The diagram below shows the above process:
10. Java is High Performance Programming Language
Advantages:
Hyperlink: The hyperlink contains the URL of the webpages. In a general way, a hyperlink is
referenced when a hypertext navigated. These hyperlinks are hidden under the text, image,
graphics, audio, video, and gets highlighted once we hover the mouse over it.
Hypertext: Ted Nelson introduced the term Hypertext in 1956. Hypertext is a text which contains
the visible text to redirect the targeted page(page URL contained by Hyperlink)
Java Support Systems
Support System Description
Web Server A Program that accept request for information and sends the required
documents
Web Browser A Program that provide access to WWW and runs Java applets
Bytecode Compiled Java Code that is referred to in the APPLET tag and transferred to
the user computer
Proxy Server An intermediate server between the requesting client workstation and
original sever. It is typically implemented for ensuring security.
Java Environment
● Java Environment includes a large number of development tools and hundreds of
classes and methods.
● The development tools are the part of the system known as Java Development Kit
(JDK).
● The class and methods are the part of the Java System Library (JSL), also known as the
Application Programming Interface (API).
Java Development Kit
Java Development Kit comes with a collection of tools that are used for developing and running Java
programs. They include
Tool Description
● The Java standard library ( or API) includes hundreds of classes and methods grouped into several
functional packages. Most commonly used packages are
1. Language Support Package : A Collection of classes and methods required for implementing
basic feature of Java.
2. Utilities Package : A collection of classes to provide utility function such as date and time
functions.
3. Input/Output Packages: A collection of classes required for input/output manipulation.
4. Networking Packages: A collection of classes for communicating with other computer via internet
5. AWT Packages: The abstract Window Toolkit package contains classes that implements platform
independent graphical user interface
6. Applet packages: This includes a set of classes that allows us to create Java Applets
Process of building and Running Java Languages
JVM Architecture
Class Loader
It mainly responsible for three activities
a) Loading : The class loader reads .class file and generate the corresponding
binary data and save in the method area. For each .class file, JVM stores the
following information in method area.
❖ Class and its immediate parent class
❖ Variables and Method information
a) Linking : Linking performs
❖ Verification : Ensure correctness of the JVM
❖ Preparation : JVM allocated memory for class variable
❖ Resolution : It is the process of replacing symbolic reference from
the type with direct references
Cont…
C. Initialization: in this phase all the static variable are assigned with their values
defined in the code and static block. This is executed from top to bottom in a class
and from parent to child in the class hierarchy.
In general there are three class loaders
There is only one method area per JVM and it is shared resource.
b) Heap area: Information of all objects is stored in the heap area. There is also
one heap area per JVM and it is also shared resource
c) Stack area: For every thread JVM creates one runtime stack which is stored in
stack area
d) PC register: Store address of current instructions of thread. Obviously each
thread has separate PC register.
e) Native method stacks: For every thread, a separate native stack is created. It
stores native method information.
Cont…
Execution Engine
Execution engine executes the .class (bytecode). It reads byte code line by line,
uses and information present in various memory area and execute instructions. It
can be classified into three parts.
● It is an interface that interacts with the Native Method Libraries and provide
native libraries (C,C++) required for the execution.
● It enables JVM to call C/C++ libraries and to be called by C/C++ libraries
which may be specific to hardware
Native Method Libraries
1. Stand-alone applications
2. Web applets
Applets are small Java programs developed for internet applications. We can develop applets for doing
everything from simple animated graphics to comlex games and utilities.
Stand-alone programs can read and write files and perform certain operations that applets cannot do.
Applet can run only within web browser
Two ways of using Java
Simple Java Program Public : the keyword public is an access specifier that
declares the main method as unprotected an therefore
making it accessible to all other classes. This is similar
class SampleOne
to the C++ public modifier
{
Statistic : Next appears the keyword statistic, which
public static void main (String[ ] args ) declares this method as one that belongs the entire
{ class and not a part of any object of the class.
1. Keywords
2. Identifier
3. Literals
4. Operator
5. Separator
Keywords
A Java keyword is one of 50 reserved terms that have a special function and a set definition
in the Java programming language.
Identifiers
Identifiers are used to naming classes, methods, variables, objects, labels,
packages and interfaces in a program. Java identifier follow the following rules
1. They can have alphabets, digits and the underscore and dollar sign
character
2. They must not begin with digit
3. Uppercase letter and Lowercase letter are distinct
4. They can be of any length
● Name of all public methods and instance variables start with leading
lowercase letter example
Example : dayTempreture
● All private and local variables use only lowercase letters combined with
underscores
Example : Student
HelloJava
Literals
A literal is a notation for representing a fixed value in source code. Java language
specifies five major types of literals. They are
1. Integer literals : 1
2. Floating point literals : 10.1
3. Character literals : a
4. String literals : “java”
5. Boolean literals : True, False
Operators
An operator is a symbol that takes one or more arguments and operates on them
to produce a result
Separators
Separators are the symbol used to indicate where group of code divided and
arranged. They basically define the shape and functions of our code
● Parenthesis → ( )
● Braces → { }
● Brackets → [ ]
● Semicolon → :
● Comma → ,
● Period → .
Java Statements
Java statements are like sentences in natural languages. A statement is an
executable combination of tokens ending with semicolon (;) mark.
Installing and configuring Java
Constants in Java
Constant in Java refer to fixed values that do not change during the execution of
program.
Integer constants
There are three types of integer constants
mantissa e exponent
Single Character Constant
A single character constant contains a single character enclosed within a pair of
single quote marks. Example of character constants are
String Constant
A string is a sequence of characters enclosed between double quote.
Example
int count;
float x,y;
double pi;
byte b;
Giving values to variable
We may also give values to variable interactively through the keyboard using
readLine() method
Scope of variable {
int x=0;
}
Type Casting
The process of converting one data type to another data type is called type casting.
The syntax is
Example :
byte m = 50;
int n = (int) m;
System.out.println(“Hello”)
System.out.println(“Java”)
Operator and Expressions
1. Arithmetic operator
2. Relational operator
3. Logical operator
4. Assignment operator
5. Increment and Decrement operator (Unary Operator)
6. Conditional operator
7. Bitwise operator
8. Special operator
Arithmetic operator
Relational Operator
Assignment Operator
Logical Operator
Unary Operator
Bitwise Operator
Conditional Operator (Ternary Operator)
● The ternary operator is a conditional operator that decreases the length of code while
performing comparisons and conditionals.
● This method is an alternative for using if-else and nested if-else statements. The
order of execution for this operator is from left to right.
Syntax:
Statement 1:It is the statement to be executed if the condition results in a true state.
Statement 2:It is the statement to be executed if the condition results in a false state.
Arithmetic Expression
● An arithmetic expression is a combination of variables, constants, and operators
arranged as per the syntax of the language.
● An arithmetic expression without any parenthesis will be evaluated from left to right
using the rules of precedence of operators. There are two distinct priority levels of
arithmetic operator in java.
High priority * / %
Low priority + -
x =a-b/3+c*2-1
Decision making and Branching
● Java compiler executes the code from top to bottom. The statements in the code
are executed according to the order in which they appear. However,
● Java provides statements that can be used to control the flow of Java code.
Such statements are called control flow statements.
● It is one of the fundamental features of Java, which provides a smooth flow of
program.
● When a program break the sequential flow and jumps to another part of the
code it is called branching
Java provides three types of control flow statements.