Java Mannual
Java Mannual
Module : 1
Fundamentals of Object Oriented Programming: Introduction, Object Oriented Paradigm,
Basic concepts of OOP: Class, Object, Inheritance, Polymorphism, Abstraction, Encapsulation..
Task: introduction to Object Oriented Programming and its basic concepts.
Java is known for its simplicity and security features, making it a popular choice for enterprise-level applications.
Java applications are compiled to byte code that can run on any Java Virtual Machine. The syntax of Java is similar
to C/C++.
Java makes writing, compiling, and debugging programming easy. It helps to create reusable code and modular
programs.
The object-oriented paradigm (OOP) is a programming paradigm that uses objects to design computer
programs. Objects are made up of data and code, and programs are built by making objects that interact with each other.
What is OOP?
Procedural programming is about writing procedures or methods that perform operations on the data, while object-
oriented programming is about creating objects that contain both data and methods.The popular object-oriented
languages are Java, C#, PHP, Python, C++, etc.
The main aim of object-oriented programming is to implement real-world entities, for example, object, classes,
abstraction, inheritance, polymorphism, etc.
OOPs (Object-Oriented Programming System)
Object means a real-world entity such as a pen, chair, table, computer, watch, etc. Object-Oriented Programming is a
methodology or paradigm to design a program using classes and objects. It simplifies software development and
o Object
o Class
o Inheritance
o Polymorphism
o Abstraction
o Encapsulation
Object
Any entity that has state and behavior is known as an object. For example, a
chair, pen, table, keyboard, bike, etc. It can be physical or logical.
Example: A dog is an object because it has states like color, name, breed, etc.
as well as behaviors like wagging the tail, barking, eating, etc.
Class
Inheritance
When one object acquires all the properties and behaviors of a parent object, it is known as inheritance. It provides
code reusability. It is used to achieve runtime polymorphism.
Polymorphism
If one task is performed in different ways, it is known as polymorphism. For example: to convince the customer
differently, to draw something, for example, shape, triangle, rectangle, etc.
Abstraction
Encapsulation
Binding (or wrapping) code and data together into a single unit are known as encapsulation. For example, a capsule, it is
wrapped with different medicines.
A java class is the example of encapsulation. Java bean is the fully encapsulated class because all the data members are
private here.
Module : 2
Overview of Java Language: Introduction, Java features, Java program structure, parts of Java, Java
Virtual Machine-Java versus C++, How to Compile & Executing a basic java program.
Task: Differences between Java and C++, Execute “Hello welcome to java” program
Java is a popular, object-oriented programming language that can be used to create a variety of applications, including:
Mobile apps
Web apps
Enterprise software
Internet of Things (IoT) devices
Gaming
Big data
Cloud-based applications
Portability: Java applications can run on any computer with a Java interpreter, regardless of the operating
system or hardware.
Security: Java has built-in security features to protect against malicious programs and erroneous code.
Reliability: Java is designed to create reliable software with compile-time and run-time checking.
Simple memory management: Java uses automatic garbage collection and a simple memory management
model that eliminates many programming errors.
Open standard: Java is an open standard with publicly available source code.
Java virtual machine (JVM): The JVM provides the basis for platform independence.
Java was created by James Gosling in 1995. The original name for the language was Oak, but it was changed to Java
after it was discovered that Oak was already a trademark.
Java is an object-oriented programming, platform-independent, and secure programming language that makes it
popular. Using the Java programming language, we can develop a wide variety of applications. So, before diving in
depth, it is necessary to understand the basic structure of Java program in detail. In this section, we have discussed
the basic structure of a Java program. At the end of this section, you will able to develop the Hello world Java
program, easily.
Differences between Java and C++
C++ Java
C++ is designed to work with compiler only Java can support both compiler and interpreter
Platform dependent Platform independent
C++ uses “cin” and “cout” Complex in/out methods (System.in and System.out)
Incorporates backward compatibility with C No backward compatibility support
C++ is a combination of OOPs and Procedural Supports only Object-Oriented Programming style
type of programming
Memory management is manual, and the user is JVM manages memory without user intervention
responsible for the memory consumed
C++ can provide multiple inheritances Java cannot support multiple inheritances
C++ supports both method overloading and Java supports only method overloading
operator overloading
Source code is not portable between different Source code is portable to any operating system
operating systems
Libraries offer low-level of functionality Libraries offer high-level functionality
The programmer is responsible for run-time errors JVM is responsible for run-time errors and exceptions
and exceptions
C++ needs manual class and object management Java is completely automatic regarding class and object
using new and delete keywords management
C++ needs manual garbage memory clearance Java has an automatic garbage
Execute “Hello welcome to java” program:
public class HelloWorld {
}
}
Save the code: Save the code in a file named HelloWorld.java.
Compile the code: Open a terminal or command prompt, navigate to the directory where you saved the file, and run the
following command:
javac HelloWorld.java
Run the code: After successful compilation, you can run the program using the following command:
Code
java HelloWorld
Module : 3
Variables-Identifiers-Literals- Data types: Integer literals-character literals-Floating point
literals- String Literals, Variables, Keywords, Data types.
Task: implementing data types with variables, find valid/invalid variables, Identifiers
To determine whether a variable name is valid or invalid, follow the basic rules for naming variables in programming
(these rules might slightly vary based on the language, but the general principles are consistent):
Identifiers in Java
// Valid identifiers
System.out.println("Valid Identifiers:");
Output:
Valid Identifiers:
myVar = 10
_value = 20
$amount = 30
value123 = 40
Module : 4
Operators: Arithmetic operators, Relational operators, Assignment operators, Conditional
operators, Type casting/Type Conversion in java.
Task: Perform all arithmetic operators using a single program, program using typecast/type
conversion
JAVA OPERATORS:
1. Assignment Operator
2. Arithmetic Operator
3. Relational Operator
4. Conditional Operators
Operators in programming and mathematics are symbols or keywords used to perform operations on
operands.
1. Arithmetic Operators
Exponentiation ( or pow()): Raises one operand to the power of another (e.g., a ** b or pow(a, b))
Greater than (>): Checks if the left operand is greater than the right.
Less than (<): Checks if the left operand is less than the right.
Greater than or equal to (>=): Checks if the left operand is greater than or equal to the right.
Less than or equal to (<=): Checks if the left operand is less than or equal to the right.
3. Assignment Operators
Add and assign (+=): Adds and assigns (e.g., x += 5 means x = x + 5).
Other Operators
Null Coalescing (?? or or): Returns the first non-null value (varies by language).
// Subtraction
System.out.println("Subtraction (a - b): " + (a - b));
// Multiplication
System.out.println("Multiplication (a * b): " + (a * b));
// Division
System.out.println("Division (a / b): " + ((double)a / b));
// Modulus
System.out.println("Modulus (a % b): " + (a % b));
// Exponentiation
System.out.println("Exponentiation (Math.pow(a, b)): " + Math.pow(a, b));
Output:
Operands: a = 10, b = 3
Addition (a + b): 13
Subtraction (a - b): 7
Multiplication (a * b): 30
Modulus (a % b): 1