0% found this document useful (0 votes)
12 views51 pages

Java Programming: ASATH K (717823L204)

This document is an internship report submitted by Asath K for the Bachelor of Engineering degree in Electronics and Communication Engineering at Karpagam College of Engineering. It outlines the internship's focus on Java programming, detailing various concepts such as OOP principles, data types, and control statements, along with a structured overview of activities completed during the internship. The report includes acknowledgments, a bonafide certificate, and a declaration of originality.

Uploaded by

717823l204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views51 pages

Java Programming: ASATH K (717823L204)

This document is an internship report submitted by Asath K for the Bachelor of Engineering degree in Electronics and Communication Engineering at Karpagam College of Engineering. It outlines the internship's focus on Java programming, detailing various concepts such as OOP principles, data types, and control statements, along with a structured overview of activities completed during the internship. The report includes acknowledgments, a bonafide certificate, and a declaration of originality.

Uploaded by

717823l204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 51

JAVA PROGRAMMING

AN INTERNSHIP REPORT

Submitted by

ASATH K [717823L204]

in partial fulfillment for the award of the degree

of

BACHELOR OF ENGINEERING

IN

ELECTRONICS AND COMMUNICATION ENGINEERING

KARPAGAM COLLEGE OF ENGINEERING

COIMBATORE – 641 032

ANNA UNIVERSITY: CHENNAI 600 025

DECEMBER 2024
KARPAGAM COLLEGE OF ENGINEERING
COIMBATORE – 641 032
ANNA UNIVERSITY: CHENNAI 600 025

BONAFIDE CERTIFICATE

Certified that this internship report “ JAVA PROGRAMMING” is the

Bonafide work of“ASATH K [717823L204]” who carried out the project work

under my supervision.

.
SIGNATURE SIGNATURE
Dr. R. SARANKUMAR, M.E., Ph.D, MS. R. DEEPIKA, M.E., Ph.D,
HEAD OF THE DEPARTMENT SUPERVISOR
PROFESSOR, ASSISTANT PROFESSOR,
ELECTRONICS AND COMMUNICATION ELECTRONICS AND COMMUNICATION
ENGINEERING, ENGINEERING,
KARPAGAM COLLEGE OF ENGINEERING, KARPAGAM COLLEGE OF ENGINEERING,
COIMBATORE,641 032 COIMBATORE,641 032

Certified that the candidate was examined during the viva voce examinations held on

SIGNATURE OF INTERNAL EXAMINAR SIGNATURE OF EXTERNAL EXAMINAR


WITH DATE WITH DATE
DECLARATION

I hereby declare that this internship report entitled “ JAVA


PROGRAMMING” submitted by me for the degree of BE in Electronics
and Communication Engineering at Karpagam College of
Engineering, Coimbatore is the record of original work done by me under
the guidance and supervision of Ms. R. DEEPIKA, ASSISTANT
PROFESSOR at the Department of Electronics and Communication
Engineering, Karpagam College of Engineering, Coimbatore – 641032 and
has not formed the basis for the award of any degree, or diploma or titles in
this institution or any other Institution of higher learning.

Date: Name and Signature of the Candidate

Place:Coimbatore ASATH K [717823L204]

III
CERTIFICATE OF INTERNSHIP

IV
ACKNOWLEDGEMENT
First and foremost praises and thanks to the almighty for her showers and blessings

throughout my / our project work to complete it successfully.

I extend my gratitude to the Management of Karpagam College of Engineering, Coimbatore


for the excellent infrastructure and support facilities to undergo the project work.

I am very grateful to Dr. V. KUMAR CHINNAIYAN, the Principal and

Dr. R. SARANKUMAR, M.E., Ph.D, ELECTRONICS AND COMMUNICATION

ENGINEERING for provided the facilities, support and permission to carried out our /my

project work at our esteemed institution.

I record my sincere gratitude to my internship Coordinator Dr. R. SELVA KUMAR, M.E.,


Ph.D for giving inputs, encouragement for the continuous improvement during the progress and to
complete this project work.

I would like to express my sincere gratitude to my Supervisor Ms. R. DEEPIKA, M.E,


Ph.D for the continuous support for my UG study, for her motivation and adequate guidance which
helped me to achieve success in all my accomplishments and to complete this projectwork.

I also thank all the teaching faculty members and non-teaching Staff members of the
department of ELECTRONICS AND COMMUNICATION ENGINEERING, Karpagam
College of Engineering, Coimbatore for their kindness and support.

I would like to thank my parents, family members and friends who sacrificed their time and
energy to complete the project work successfully.

ASATH K
717823L204

V
TABLE OF CONTENTS
CHAPTER. NO. TITLE NAME PAGE .NO.
ABSTRACT i

OVERVIEWOF INTERNSHIP ACTIVITIES ii


iii
LIST OF FIGURES
1. INTRODUCTION ABOUT JAVA
1.1Java Feature 1
1.2 OOPS Concept 4
1.3 Polymorphism 7

2. DATA TYPES, VARIABLES AND ARRAYS


2.1Primitive Data Type 10
2.2 Variables 11
2.3Java Arrays 12
2.4 Multidimensional Array 13

3. OPERATION
3.1Arithemetic Operators 14
3.2 Increment And Decrement Operators 18
3.3Bitwise Operators 20
3.4Assignment Operators 24

4. CONTROL STATEMENT

4.1Conditional Statements 27
4.2Looping Statements 31
Jumping Statements 36

5. CONCLUSION 38

REFERENCE 39

VI
ABSTRACT

This internship focuses on providing hands-on experience in web development,


offering exposure to both front-end and back-end technologies. The candidate will
be involved in the full software development lifecycle, from understanding project
requirements to implementing solutions and testing them. The internship covers a
wide range of skills, including HTML, CSS, JavaScript, and frameworks like React
or Angular for front-end development, as well as server-side programming with
languages like Node.js or Python and database management using MySQL or
MongoDB. By the end of the program, interns will have developed a solid
foundation in web development, along with practical projects that can be added to
their professional portfolios. Interns will also gain exposure to essential
development tools and best practices, including version control with Git,
collaborative workflows through GitHub or GitLab, and testing methodologies such
as unit testing and end- to-end testing using tools like Jest or Mocha. Additionally,
interns will learn about deployment practices, such as deploying applications to
cloud platforms like AWS, Google Cloud, or Heroku, and managing server
environments.

i
OVERVIEWOFINTERNSHIPACTIVITIES
DATE DAY NAME OF THE TOPIC
/MODULE
COMPLETED
15.06.2024 MONDAY Java Features

16.06.2024 TUESDAY OOPS concept

17.06.2024 WEDNESDAY Encapsulation And Interface

18.06.2024 THURSDAY Polymorphism

19.06.2024 FRIDAY Object Oriented Programming

20.06.2024 SATURDAY Datatypes, Variables And Arrays

21.06.2024 SUNDAY Primitive Datatypes

22.06.2024 MONDAY Variables And Java Arrays

23.06.2024 TUESDAY One Dimensional Arrays And Multidimensional Arrays

24.06.2024 WEDNESDAY Operators, Arithmetic Operators And Relational Operators

25.06.2024 THURSDAY Modulus Operator, Increment And Decrement Operator

26.06.2024 FRIDAY Increment And Decrement Operator,


The Bitwise Operator And Logical Operators
27.06.2024 SATURDAY Control Statements, Conditional Statement

28.06.2024 SUNDAY Else If Ladders And Switch Statements,


Looping Statements And Do While Loop
29.06.2024 MONDAY Enhanced For Loop And Jumping Statements

30.06.2024 TUESDAY Conclusion

ii
LIST OF FIGURES

FIG.NO: TITLE PAGE.NO:

Introduction About Java 4

OOPS Concept 8

3.1 Primitive Data Type 10

variables 11

Arithemetic Operators 21

Condidtional Statements 27

Looping Statements 31

iii
CHAPTER 1

INTRODUCTIONABOUTJAVA
Java Features
• Simple

• Secure

• Portable

• Object-oriented

• Robust

• Multithreaded

• Architecture-neutral

• Interpreted

• High performance

• Distributed

• Dynamic

1
Simple
Java was designed to be easy for the professional programmer to learn and use effectively.
Assuming that you have some programming experience, you will not find Java hard to master.
If you already understand the basic concepts of object-oriented programming, learning Java
will be even easier. Best of all, if you are an experienced C++ programmer, moving to Java

will require very little effort . Because Java inherits the C/C++ syntax and many of the
object- oriented features of C++, most programmers have little trouble learning Java.

Object-Oriented
Although influenced by its predecessors, Java was not designed to be source-code compatible
with any other language. This allowed the Java team the freedom to design with a blank slate.
One outcome of this was a clean, usable, pragmatic approach to objects.
“stay out of my way” model. The object model in Java is simple and easy to extend, while
primitive types, such as integers, are kept as high-performance nonobjects.

Robust

The multi platformed environment of the Web places extraordinary demands on a program,
because the program must execute reliably in a variety of systems. Thus, the ability to create
robust programs was given a high priority in the design of Java. To gain reliability, Java
restricts you in a few key areas to force you to find your mistakes early in program
development. At the same time, Java frees you from having to worry about many of the most
common causes of programming errors. Because Java is a strictly typed language, it checks
your code at compile time. However, it also checks your code at run time. Many hard-to-
track-down bugs that often turn up in hard-to-reproduce runtime situations are simply
impossible to create in Java. Knowing that what you have written will behave in a predictable
way under diverse conditions is a key feature of Java. To better understand how Java is robust,
consider two of the main reasons for program failure: memory management mistakes and
mishandled exceptional conditions (that is, runtime errors). Memory management can be a
difficult, tedious task in traditional programming environments.

Multithreaded

Java was designed to meet the real-world requirement of creating interactive ,networked
programs. To accomplish this, Java supports multithreaded programming, which allows you
to write programs that do many things simultaneously.

2
Architecture-Neutral

A central issue for the Java designers was that of code longevity and portability. At the time of
Java’s creation, one of the main problems facing programmers was that no guarantee existed
that if you wrote a program today, it would run tomorrow—even on the same machine.
Operating system upgrades, processor upgrades, and changes in core system resources can all
combine to make a program malfunction. The Java designers made several hard decisions in
the Java language and the Java Virtual Machine in an attempt to alter this situation. Their goal
was “write once; run anywhere, any time, forever.” To a great extent ,this goal was
accomplished. Interpreted and High Performance As described earlier, Java enables the
creation of cross-platform programs by compiling into an intermediate representation called
Java bytecode.

Distributed

Java is designed for the distributed environment of the Internet because it handles TCP/IP
protocols. In fact, accessing a resource using a URL is not much different from accessing a
file. Java also supports Remote Method Invocation(RMI). This feature enables a program to
invoke methods across a network.

Dynamic

Java programs carry with them substantial amounts of runtime type information that is used to
verify and resolve accesses to objects at run time. This makes it possible to dynamically link
code in a safe and expedient manner. This is crucial to the robustness of the Java environment,
in which small fragments of byte code may be dynamically updated on a running system.

3
OOPS Concept

Object-Oriented Programming

Object-oriented programming (OOP) is at the core of Java. In fact, all Java programs are to at
least some extent object-oriented. OOP is so integral to Java that it is best to understand its
basic principles before you begin writing even simple Java programs. Therefore, this chapter
begins with a discussion of the theoretical aspects of OOP.

Abstraction

An essential element of object-oriented programming is abstraction. Humans manage


complexity through abstraction. For example, people do not think of a car as a set of tens of
thousands of individual parts. They think of it as a well-defined object with its own unique
behavior. This abstraction allows people to use a car to drive to the grocery store without
being overwhelmed by the complexity of the parts that form the car. They can ignore the
details of how the engine, transmission, and braking systems work. Instead, they are free to
utilize the object as a whole .

A powerful way to manage abstraction is through the use of hierarchical classifications. This
allows you to layer the semantics of complex systems, breaking them into more manageable
pieces. From the outside, the car is a single object. Once inside, you see that the car consists of
several subsystems: steering, brakes, sound system, seat belts, heating, cellular phone, and so
on. In turn, each of these subsystems is made up of more specialized units. For instance, the
sound system consists of a radio, a CD player, and/or a tape or MP3 player. The point is that
you manage the complexity of the car (or any other complex system) through the use of
hierarchical abstractions.

Hierarchical abstractions of complex systems can also be applied to computer programs. The
data from a traditional process-oriented program can be transformed by abstraction into its
component objects. A sequence of process steps can become a collection of messages between
these objects. Thus, each of these objects describes its own unique behavior. You can treat
these objects as concrete entities that respond to messages telling them to do something. This
is the essence of object-oriented programming.

4
The Three OOP Principles

All object-oriented programming languages provide mechanisms that help you implement the
object-oriented model. They are encapsulation, inheritance, and polymorphism. Let’s take a
look at these concepts now.

Encapsulation

Encapsulation is the mechanism that binds together code and the data it manipulates, and
keeps both safe from outside interference and misuse. One way to think about encapsulation is
as a protective wrapper that prevents the code and data from being arbitrarily accessed by
other code defined outside the wrapper. Access to the code and data inside the wrapper is
tightly controlled through a well-defined interface. To relate this to the real world, consider
the automatic transmission on an automobile. It encapsulates hundreds of bits of information
about your engine, such as how much you are accelerating, the pitch of the surface you are on,
and the position of the shift lever. You, as the user, have only one method of affecting this
complex encapsulation: by moving the gear-shift lever. You can’t affect the transmission by
using the turn signal or windshield wipers, for example. Thus, the gear-shift lever is a well-
defined (indeed, unique)interface to the transmission. Further, what occurs inside the
transmission does not affect objects outside the transmission. For example, shifting gears does
not turn on the headlights! Because an automatic transmission is encapsulated ,dozens of car
manufacturers can implement one in any way they please. However, from the driver’s point of
view, they all work the same. This same idea can be applied to programming. The power of
encapsulated code is that everyone knows how to access it and thus can use it regardless of
the implementation details—and without fear of unexpected side effect

Inheritance

Inheritance is the process by which one object acquires the properties of an other object. This is

important because it supports the concept of hierarchical classification. As mentioned earlier, most knowledge

is made manageable by hierarchical (that is, top-down) classifications. For example, a Golden Retrieveris part

of the classification dog, which in turn is part of the mammal class, which is under the larger class animal.

5
Without the use of hierarchies, each object would need to define all of its characteristics
explicitly. However, by use of inheritance, an object need only define those qualities that
make it unique within its class. It can inherit its general attributes from its parent. Thus, it is
thein heritance mechanism that makes it possible for one object to be a specific instance of a
more general case. Let’s take a closer look at this process.

Most people naturally view the world as made up of objects that are related to each other in a
hierarchical way, such as animals, mammals, and dogs. If you wanted to describe animals in
an abstract way, you would say they have some attributes, such as size, intelligence, and type
of skeletal system. Animals also have certain behavioral aspects; they eat, breathe, and sleep.

This description of attributes and behavior is the class definition for animals. If you
wanted to describe a more specific class of animals, such as mammals, they would have more
specific attributes, such as type of teeth and mammary glands. This is known as a subclass of
animals, where animals are referred to as mammals’ superclass.

Since mammals are simply more precisely specified animals, they inherit all of the attributes
from animals. A deeply inherited subclass inherits all of the attributes from each of its
ancestors in the class hierarchy. Inheritance interacts with encapsulation as well. If a given
class encapsulates some attributes, then any subclass will have the same attributes plus any
that it adds as part of its specialization (see Figure 2-2). This is a key concept that lets object-
oriented programs grow in complexity linearly rather than geometrically. A new subclass
inherits all of the attributes of all of its ancestors. It does no thave unpredictable interactions
with the majority of the rest of the code in the system.

6
Polymorphism

Polymorphism (from Greek, meaning “many forms”) is a feature that allows one interface to
be used for a general class of actions. The specific action is determined by the exact nature of
the situation. Consider a stack (which is a last-in, first-out list). You might have a program
that requires three types of stacks. One stack is used for integer values, one for floating-point
values, and one for characters. The algorithm that implements each stack is the same, even
though the data being stored differs. In a non–object-oriented language, you would bere
quired to create three different sets of stack routines, with each set using different names.
However, because of polymorphism, in Java you can specify ageneral set of stack routines
that all share the same names.

More generally, the concept of polymorphism is often expressed by the phrase “one interface,
multiple methods.” This means that it is possible to design a generic interface to a group of
related activities. This helps reduce complexity by allowing the same interface to be used to
specify a general class of action. It is the compiler’s job to select the specific action (that is,
method) as it applies to each situation. You, the programmer, do not need to make this
selection manually. You need only remember and utilize the general interface.

Polymorphism, Encapsulation, and Inheritance Work Together

When properly applied, polymorphism, encapsulation, and inheritance combine to produce a


programming environment that supports the development of far more robust and scaleable
programs than does the process-oriented model. A well-designed hierarchy of classes is the
basis for reusing the code in which you have invested time and effort developing and testing.
Encapsulation allows you to migrate your implementations over time without breaking the
code that depends on the public interface of your classes. Polymorphism allows you to create
clean, sensible, readable, and resilient code. Of the two real-world examples, the automobile
more completely illustrates the power of object-oriented design. Dogs are fun to think about
from an inheritance standpoint, but cars are more like programs. All drivers rely on
inheritance to drive different types (subclasses) of vehicles.

7
Whether the vehicle is a school bus, a Mercedes sedan, a Porsche, or the family minivan,
drivers can all more or less find and operate the steering wheel, the brakes, and the
accelerator. After a bit of gear grinding, most people can even manage the difference between
a stick shift and an automatic, because they their common superclass, the transmission.

People interface with encapsulated features on cars all the time. The brake and gas pedals hide
an incredible array of complexity with an interface so simple you can operate them with your
feet! The implementation of the engine, the style of brakes, and the size of the tires have no
effect on how you interface with the class definition of the pedals.

Fig 1.2 OOPS CONCEPT


As the name suggests, Object-Oriented Programming or Java OOPs concept refers to
languages that use objects in programming, they use objects as a primary source to implement
what is to happen in the code. Objects are seen by the viewer or user, performing tasks you
assign.

Object-oriented programming

aims to implement real-world entities like inheritance, hiding, polymorphism, etc. in


programming. The main aim of OOPs is to bind together the data and the functions that
operate on them so that no other part of the code can access this data except that function.

8
CHAPTER 2

Data Types, Variables, and Arrays

Primitive Data Types

Java defines eight primitive types of data: byte, short, int, long, char, float,double, and
boolean. The primitive types are also commonly referred to as simple types, and both terms
will be used in this book. These can be put in four groups:

• Integers This group includes byte, short, int, and long, which are for whole-valued
signed numbers.

• Floating-point numbers This group includes float and double, which represent
numbers with fractional precision.

• Characters This group includes char, which represents symbols in a character set,
like letters and numbers.

• Boolean This group includes boolean, which is a special type for representing
true/false values.

Integers

Java defines four integer types: byte, short, int, and long. All of these are signed, positive and
negative values. Java does not support unsigned, positive-only integers. Many other computer
languages support both signed and unsigned integers.

byte

The smallest integer type is byte. This is a signed 8-bit type that has a range from –128 to 127.
Variables of type byte are especially useful when you’re working with a stream of data from a
network or file. They are also useful whenyou’re working with raw binary data that may not
be directly compatible with Java’s other built-in types.

Byte variables are declared by use of the byte keyword.

short

short is a signed 16-bit type. It has a range from –32,768 to 32,767. It isprobably the least-
used Java type. Here are some examples of short variable

9
int

The most commonly used integer type is int. It is a signed 32-bit type that has arange from –
2,147,483,648 to 2,147,483,647. In addition to other uses, variables of type int are commonly
employed to control loops and to index arrays.

Long

long is a signed 64-bit type and is useful for those occasions where an int type is not large
enough to hold the desired value. The range of a long is quite large. This makes it useful when
big, whole numbers are needed.

Fig 2.1 range of data types

float

The type float specifies a single-precision value that uses 32 bits of storage. Single precision
is faster on some processors and takes half as much space as double precision, but will
become imprecise when the values are either very large or very small. Variables of type float
are useful when you need a fractional component, but don’t require a large degree of
precision.

Double

Double precision, as denoted by the double keyword, uses 64 bits to store a value. Double
precision is actually faster than single precision on some modern processors that have been
optimized for high-speed mathematical calculations.

public class Double Example


{ double num1 = 5.5;
double num2 = 3.2;
double result = num1 + num2;
System.out.println("The result is: " + result);
}

10
Variables
The variable is the basic unit of storage in a Java program. A variable is defined by the
combination of an identifier, a type, and an optional initializer. In addition, all variables have
ascope, which defines their visibility, and a life time.These elements are examined next.

Declaring variables

In Java, all variables must be declared before they can be used. The basic formof a
variable declaration is shown here:

datatype variableName;

Dynamic Initialization

Although the preceding examples have used only constants as initializers, Java allows
variables to be initialized dynamically, using any expression valid at the time the variable is
declared.

For example, here is a short program that computes the length of the hypotenuse of a right
triangle given the lengths of its two opposing sides:

Syntax:

datatype variable Name = expression;

Example:

public class Dynamic Initialization {

public static void main(String[] args)

int a = 5;

int b = 10; // Dynamic initialization of a

variable int sum = a + b;

// Another example with a method

double squareRoot =

Math.sqrt(49);

System.out.println("Sum: " + sum);


11
System.out.println("Square Root: " + squareRoot);

}}

12
2.4 JAVAARRAYS

An array is a group of like-typed variables that are referred to by a common name. Arrays of
any type can be created and may have one or more dimensions. A specific element in an
array is accessed by its index. Arrays offer a convenient means of grouping related
information.

One-Dimensional Arrays

A one-dimensional array is, essentially, a list of like-typed variables. To createan array, you
first must create an array variable of the desired type. The generalform of a one-dimensional
array declaration istype var-name[ ];

example

public class OneDimensionalArray {

public static void main(String[] args)

{ int[] numbers = {10, 20, 30, 40,

50}; for (int i = 0; i < numbers.length;

i++) {

System.out.println(numbers[i]);

OUTPUT

Elements of the array: 10 20 30 40 50

13
Multidimensional Arrays

In Java, multidimensional arrays are actually arrays of arrays. These, as you might expect,
look and act like regular multidimensional arrays. However, asyou will see, there are a couple
of subtle differences. To declare a multidimensional array variable, specify each additional
index using another set of square brackets. For example, the following declares a two-
dimensional array variable called twoD:

Example

public class MultiDimensionalArray {

public static void main(String[] args) {

int[][] numbers = {

{1, 2, 3},

{4, 5, 6},

{7, 8, 9}

};

for (int i = 0; i < numbers.length; i++) {

for (int j = 0; j < numbers[i].length; j++) {

System.out.print(numbers[i][j] + " ");

System.out.println();

}}

OUTPUT

123

456

789

14
CHAPTER 3

OPERATORS

Arithmetic Operators

Arithmetic operators are used in mathematical expressions in the same way that

they are used in algebra. The following table lists the arithmetic operators:

Fig 3.1 Arimetic operators

The operands of the arithmetic operators must be of a numeric type. You cannot use them on
boolean types, but you can use them on char types, since the char type in Java is, essentially, a
subset of int.

The Basic Arithmetic Operators

The basic arithmetic operations—addition, subtraction, multiplication, and division—all


behave as you would expect for all numeric types. The unaryminus operator negates its single
operand. The unary plus operator simply returns the value of its operand. Remember that
when the division operator is applied to an integer type, there will be no fractional
component

15
attached to the result. The following simple example program demonstrates the arithmetic
operators .It also illustrates the difference between floating-point division and integer
division.

Example

public class Arithmetic Operators {

public static void main(String[] args)

{ int a = 10, b = 5;

System.out.println("Addition: " + (a + b));

System.out.println("Subtraction: " + (a - b));

System.out.println("Multiplication: " + (a * b));

System.out.println("Division: " + (a / b));

System.out.println("Modulus: " + (a % b));

Output

Addition: 15

Subtraction: 5

Multiplication: 50

Division: 2

Modulus: 0

The program performs arithmetic operations (+, -, *, /, %) on two numbers, 10 and

5. addition (15)

subtraction (5)

multiplication (50)

division (2)and modulus (0).

16
The Modulus Operator

The modulus operator, %, returns the remainder of a division operation. It canbe applied to
floating-point types as well as integer types. The followingexample program demonstrates
the
%:

public class ModulusOperator {

public static void main(String[] args)

{ int a = 17, b = 4;

int result = a % b;

System.out.println("The remainder of " + a + " divided by " + b + " is: " + result);

Output

The remainder of 17 divided by 4 is: 1

Arithmetic Compound Assignment Operators

Java provides special operators that can be used to combine an arithmetic operation with
an assignment. As you probably know, statements like the following are quite common in
programming:

Arithmetic compound assignment operators are shorthand notations in Java for performing an
operation and assigning the result to a variable in one step. Here are the arithmetic compound
assignment operators:

1. += (Addition Assignment)

2. -= (Subtraction Assignment)

3. *= (Multiplication Assignment)

4. /= (Division Assignment)

5. %= (Modulus Assignment)

Example Program Using Arithmetic Compound Assignment Operators:


17
publicclass ArithmeticCompound Assignment

public static void main(String[] args) {

int a = 10, b = 5;

a += b; // a = a + b

System.out.println("a += b: " +

a); a -= b; // a = a - b

System.out.println("a -= b: " + a);

a *= b; // a = a * b

System.out.println("a *= b: " +

a); a /= b; // a = a / b

System.out.println("a /= b: " + a);

a %= b; // a = a % b

System.out.println("a %= b: " +

a);

Output:

a += b: 15

a -= b: 10

a *= b: 50

a /= b: 10

a %= b: 0

Explanation:

1. a += b;: Adds b to a and assigns the result back to a.

2. a -= b;: Subtracts b from a and assigns the result back to a.


18
3. a *= b;: Multiplies a by b and assigns the result back to a.

4. a /= b;: Divides a by b and assigns the result back to a.

5. a %= b;: Finds the remainder of a divided by b and assigns the result back to a.

Increment and Decrement Operators:

In Java, the increment (++) and decrement (--) operators are used to increase or decrease
the value of a variable by 1, respectively. These operators can be used in both prefix and
postfix forms.

Increment and Decrement Operators:

1. Increment Operator (++):

o Prefix (++variable): Increments the value of the variable before using it.

o Postfix (variable++): Uses the current value of the variable and


then increments it.

2. Decrement Operator (--):

o Prefix (--variable): Decrements the value of the variable before using it.

o Postfix (variable--): Uses the current value of the variable and


then decrements it.

Example Program Using Increment and Decrement Operators:

public class IncrementDecrement {

public static void main(String[] args)

{ int a = 5, b = 10;

System.out.println("Initial values: a = " + a + ", b = " + b);

System.out.println("Prefix increment of a: " + (++a)); // Increment before usage

System.out.println("Postfix increment of b: " + (b++)); // Use value first, then

increment System.out.println("After postfix increment, b = " + b);

19
System.out.println("Prefix decrement of a: " + (--a)); // Decrement before usage

System.out.println("Postfix decrement of b: " + (b--)); // Use value first, then decrement

System.out.println("After postfix decrement, b = " + b);

Output:

Initial values: a = 5, b = 10

Prefix increment of a: 6

Postfix increment of b: 10

After postfix increment, b =

11 Prefix decrement of a: 5

Postfix decrement of b: 11

After postfix decrement, b =

10 Explanation:

1. Prefix Increment (++a): Increments a before using it. The value printed is 6 since
a was initially 5.

2. Postfix Increment (b++): Prints the current value of b (10), and then increments b
to 11.

3. Prefix Decrement (--a): Decrements a before using it. The value printed is 5
after decrementing from 6.

4. Postfix Decrement (b--): Prints the current value of b (11), and then decrements b
to 10.

20
The Bitwise Operators

Java defines several bitwise operators that can be applied to the integer types:long, int,
short, char, and byte. These operators act upon the individual bits oftheir operands. They
are summarized in the following table:

Fig 3.3 Bitwise Operators

Example

public class BitwiseOperators {

public static void main(String[] args)

{ int a = 5; // Binary: 0101

int b = 3; // Binary: 0011

System.out.println("a & b = " + (a & b)); // AND

System.out.println("a | b = " + (a | b)); // OR

System.out.println("a ^ b = " + (a ^ b)); // XOR

System.out.println("~a = " + (~a)); // Complement

System.out.println("a << 1 = " + (a << 1)); // Left shift

System.out.println("a >> 1 = " + (a >> 1)); // Right

shift

System.out.println("a >>> 1 = " + (a >>> 1)); // Unsigned right shift

}
21
}

Output:

css

Copy code

a&b=1

a|b=7

a^b=6

~a = -6

a << 1 = 10

a >> 1 = 2

a >>> 1 = 2

Explanation:

1. AND (&):
Each bit is 1 only if both corresponding bits are
1. 0101 & 0011 = 0001 → Result is 1.

2. OR (|):
Each bit is 1 if at least one of the corresponding bits is
1. 0101 | 0011 = 0111 → Result is 7.

3. XOR (^):
Each bit is 1 if only one of the corresponding bits is
1. 0101 ^ 0011 = 0110 → Result is 6.

4. Complement (~):
Inverts all the
bits.
~0101 = 1010 (2's complement representation) → Result is -6.

5. Shift Left (<<):


Shifts bits to the left, filling zeros from the
right. 0101 << 1 = 1010 → Result is 10.

22
6. Shift Right (>>):
Shifts bits to the right, preserving the sign bit (arithmetic
shift). 0101 >> 1 = 0010 → Result is 2.

7. Unsigned Shift Right (>>>):


Shifts bits to the right, filling zeros from the
left. 0101 >>> 1 = 0010 → Result is 2.

These bitwise operations are efficient for low-level data manipulation, commonly used
in systems programming, cryptography, and network protocols.

Logical Operators in Java

Logical operators are used to combine multiple conditions or boolean expressions.


They operate on boolean values and return a boolean result.

1. AND (&&): Returns true if both operands are true, otherwise false.

2. OR (||): Returns true if at least one operand is true, otherwise false.

3. NOT (!): Reverses the logical state of its operand. If the condition is true, it
becomes false, and vice versa.

Relational Operators in Java

Relational operators are used to compare two values. They return a boolean result (true
or false) based on the comparison.

1. Equal to (==): Returns true if the values are equal.

2. Not equal to (!=): Returns true if the values are not equal.

3. Greater than (>): Returns true if the left operand is greater than the right.

4. Less than (<): Returns true if the left operand is less than the right.

5. Greater than or equal to (>=): Returns true if the left operand is greater than
or equal to the right.

6. Less than or equal to (<=): Returns true if the left operand is less than or equal to
the right.

Example Program Using Logical and Relational Operators:

23
public class Logical And Relational Operators

{public static void main(String[] args) {

int a = 10, b = 20;

boolean x = true, y = false;

System.out.println("a == b: " + (a == b)); // Equal to

System.out.println("a != b: " + (a != b)); // Not equal to

System.out.println("a > b: " + (a > b)); // Greater than

System.out.println("a < b: " + (a < b)); // Less than

System.out.println("a >= b: " + (a >= b)); // Greater than or equal

to System.out.println("a <= b: " + (a <= b)); // Less than or equal

to System.out.println("x && y: " + (x && y)); // AND

System.out.println("x || y: " + (x || y)); // OR System.out.println("!

x: " + (!x)); // NOT

Output:

a == b:

false a != b:

true a > b:

false a < b:

true

a >= b: false

a <= b: true

x && y:

false x || y:

24
true

25
!x: false

Explanation:

1. Relational Operators:

o a == b: Compares a and b. Since 10 != 20, the result is false.

o a != b: Since 10 is not equal to 20, the result is true.

o a > b: 10 is not greater than 20, so the result is false.

o a < b: 10 is less than 20, so the result is true.

o a >= b: 10 is not greater than or equal to 20, so the result is false.

o a <= b: 10 is less than or equal to 20, so the result is true.

2. Logical Operators:

o x && y: Both x and y must be true for the result to be true. Since y is false,
the result is false.

o x || y: At least one of x or y must be true for the result to be true. Since x


is true, the result is true.

o !x: Reverses the value of x. Since x is true, !x is false.

Assignment Operator

In Java, the assignment operator is used to assign a value to a variable. The most common
assignment operator is the = operator, but there are also compound assignment operators
that combine an operation with an assignment.

1. Basic Assignment Operator:

 =: Assigns the value on the right to the variable on the

left. java

Copy code

int x = 5; // x is assigned the value 5

2. Compound Assignment Operators:

26
These operators combine an arithmetic operation with an assignment. They are shorthand for
performing an operation on a variable and then assigning the result back to the same variable.

1. Addition Assignment (+=): Adds the value on the right to the variable on the left
and assigns the result back to the left variable.

int x = 5;

x += 3; // Equivalent to x = x + 3; Now, x = 8

2. Subtraction Assignment (-=): Subtracts the value on the right from the variable
on the left and assigns the result back to the left variable.

int x = 5;

x -= 2; // Equivalent to x = x - 2; Now, x = 3

3. Multiplication Assignment (*=): Multiplies the variable on the left by the value
on the right and assigns the result back to the left variable.

int x = 5;

x *= 4; // Equivalent to x = x * 4; Now, x = 20

4. Division Assignment (/=): Divides the variable on the left by the value on the
right and assigns the result back to the left variable.

int x = 20;

x /= 4; // Equivalent to x = x / 4; Now, x = 5

5. Modulus Assignment (%=): Assigns the remainder of the division of the variable
on the left by the value on the right back to the left variable.

int x = 20;

x %= 3; // Equivalent to x = x % 3; Now, x =

2 Example Program Using Assignment Operators:

public class Assignment Operators {

public static void main(String[] args)

{ int a = 10, b = 5;

27
a += b; // a = a + b; a = 10 + 5 =

15 System.out.println("a += b: " +

a); a -= b; // a = a - b; a = 15 - 5 =

10 System.out.println("a -= b: " +

a); a *= b; // a = a * b; a = 10 * 5 =

50 System.out.println("a *= b: " +

a); a /= b; // a = a / b; a = 50 / 5 =

10 System.out.println("a /= b: " +

a); a %= b; // a = a % b; a = 10 %

5 = 0 System.out.println("a %= b:

" + a);

Output:

less

Copy code

a += b: 15

a -= b: 10

a *= b: 50

a /= b: 10

a %= b: 0

Summary:

 Basic Assignment (=): Assigns a value to a variable.

 Compound Assignment: Shorthand for arithmetic operations combined with

28
as signment (+=, -=, *=, /=, %=).

29
CHAPTER 4

CONTROLSTATEMENTS

CONDITIONAL STATEMENTS

1. if Statement

The if statement is used to execute a block of code only if a specified condition is

true. public class IfExample {

public static void main(String[] args)

{ int number = 10;

if (number > 5) {

System.out.println("The number is greater than 5.");

Explanation:

 The condition number > 5 is checked.

 Since number is 10, which is greater than 5, the condition evaluates to true, and
the message "The number is greater than 5." is printed.

2. if-else Statement

The if-else statement is used when there are two possible blocks of code to execute: one
for true and one for false.

public class IfElseExample {

public static void main(String[] args)

{ int number = 3;

if (number > 5) {

System.out.println("The number is greater than 5.");

30
} else {

System.out.println("The number is less than or equal to 5.");

Explanation:

 The condition number > 5 is evaluated.

 Since number is 3, which is not greater than 5, the else block is executed,
printing "The number is less than or equal to 5."

3. else-if Ladder

The else-if ladder allows you to check multiple conditions in a

sequence. public class ElseIfExample {

public static void main(String[] args)

{ int number = 8;

if (number > 10) {

System.out.println("The number is greater than 10.");

} else if (number == 8) {

System.out.println("The number is equal to 8.");

} else {

System.out.println("The number is less than 8.");

Explanation:

 The first condition number > 10 is false because number is 8.

31
 The second condition number == 8 is true, so the message "The number is equal to
8." is printed.

Fig 4.1 Control Statements

4. switch Statement

The switch statement is used to select one of many code blocks to be executed based on
a variable's value.

public class Switch Example {

public static void main(String[] args)

{ int day = 3;

switch (day) {

case 1:

System.out.println(Monday");

break;

case 2:

System.out.println("Tuesday");

break;

case 3:

System.out.println("Wednesday");

break;

32
default:

System.out.println("Invalid day");

Explanation:

 The switch statement checks the value of day.

 Since day is 3, it matches case 3 and prints "Wednesday".

5. Ternary Operator (Conditional Expression)

The ternary operator is a shorthand for the if-else statement. It evaluates a condition and
returns one of two values.

public class TernaryOperatorExample

{ public static void main(String[] args)

{ int number = 4;

String result = (number > 5) ? "Greater than 5" : "Less than or equal to 5";

System.out.println(result);

Explanation:

 The condition number > 5 is checked.

 Since number is 4, which is not greater than 5, the ternary operator returns "Less
than or equal to 5", and this is printed.

Summary of Conditional Statements:

 if: Used when you need to execute a block of code if a condition is true.

 if-else: Executes one block of code if the condition is true, and another block if false.

33
 else-if ladder: Used to check multiple conditions sequentially.

 switch: Used for selecting one of many blocks of code to execute based on the
value of a variable.

 Ternary operator: A shorthand for if-else that returns one of two values based on
a condition.

LOOPING STATEMENT

In Java, looping statements allow you to execute a block of code repeatedly, either for a
specified number of times or until a condition is met. There are three main types of loops
in Java:

1. for Loop

The for loop is used when you know beforehand how many times you want to execute
a statement or a block of statements.

Syntax:

for (initialization; condition; update) {

// Code to be executed

 Initialization: Executes once, before the loop starts. Typically used to initialize
a counter variable.

 Condition: Checked before each iteration. If it's true, the loop continues; if false,
the loop terminates.

 Update: Executes after each iteration. Usually used to increment or decrement


the counter.

Example:

public class ForLoopExample {

34
public static void main(String[] args)

{ for (int i = 1; i <= 5; i++) {

System.out.println("i = " + i);

Explanation:

 The loop starts with i = 1 and continues as long as i <= 5.

 After each iteration, i is incremented by 1, printing the values of i from 1 to 5.

Output:

i=1

i=2

i=3

i=4

i=5

2. while Loop

The while loop is used when the number of iterations is not known beforehand, and the
loop continues until the specified condition evaluates to false.

Syntax:

while (condition) {

// Code to be executed

35
 The condition is checked before the code inside the loop is executed. If the
condition is true, the loop will execute. If it's false, the loop will terminate.

Example:

public class WhileLoopExample {

public static void main(String[] args)

{ int i = 1;

while (i <= 5) {

System.out.println("i = " +

i); i++;

Explanation:

 The loop continues as long as i <= 5. It prints the value of i and increments i by 1
on each iteration.

Output:

i=1

i=2

i=3

i=4

i=5

3. do-while Loop

36
The do-while loop is similar to the while loop, but the condition is checked after the
loop executes. This means the block of code will always execute at least once,
regardless of whether the condition is true or not.

Syntax:

do {

// Code to be executed

} while (condition);

 The code inside the loop is executed first, then the condition is checked. If
the condition is true, the loop continues; if false, the loop terminates.

Example:

public class DoWhileLoopExample {

public static void main(String[] args)

{ int i = 1;

do {

System.out.println("i = " +

i); i++;

} while (i <= 5);

Explanation:

 The loop will execute the code at least once, even if the condition is initially
false. After that, the condition is checked, and the loop continues as long as i <=
5.

Output:

i=1

i=2

37
i=3

i=4

i=5

4. Enhanced for Loop (for-each loop)

The enhanced for loop, also known as the for-each loop, is used to iterate over elements in an
array or a collection (like a list). It simplifies the process of looping through elements without
needing to use an index.

Syntax:

for (type variable : array_or_collection) {

// Code to be executed for each element

Example:

public class ForEachLoopExample {

public static void main(String[] args)

{ int[] numbers = {1, 2, 3, 4, 5};

for (int num : numbers) {

System.out.println("num = " +

num);

Explanation:

 The loop iterates through each element in the numbers array. For each iteration,
the value of the element is assigned to the variable num, and the value is printed.

Output:

num = 1
38
num = 2

num = 3

num = 4

num = 5

Fig 4.2 Looping Statements

Summary:

 for loop: Used when you know the number of iterations in advance.

 while loop: Used when the condition is evaluated before each iteration, and you
don't know how many iterations will occur.

 do-while loop: Used when you want to ensure that the loop executes at least
once, with the condition being checked after the first iteration.

 Enhanced for loop: Used to iterate over elements in an array or collection,


simplifying the process of accessing each element.

These loops help you efficiently repeat tasks in your program based on conditions or
iterating through collections of data.

JUMPING STATEMENT

In Java, jump statements are used to control the flow of execution within loops or
methods. These statements allow you to exit, skip, or jump to specific parts of your code.
There are three main jump statements in Java:

1. break Statement

39
The break statement is used to exit or terminate the loop, switch, or case statement
prematurely, before the loop condition becomes false or the switch statement finishes
all cases.

2. continue Statement

The continue statement is used to skip the current iteration of a loop and continue with the
next iteration. It is useful when you want to skip certain steps of a loop based on a
condition but still continue looping.

3. return Statement

The return statement is used to exit a method and optionally return a value. It is
commonly used in functions to exit from the method and pass a result back to the caller.

example

public class BreakExample {

public static void main(String[] args)

{ for (int i = 1; i <= 10; i++) {

if (i == 5) {

break; // Breaks the loop when i equals 5

System.out.println("i = " + i);

System.out.println("Loop terminated.");

40
CHAPTER 5
CONCLUSION

Technical Proficiency and Versatility Java stands out as a versatile and robust
programming language, crucial for a wide range of applications from web development to
large-scale enterprise solutions. Its platform independence, facilitated by the Java Virtual
Machine (JVM), ensures that applications can run seamlessly across different operating
systems.
Additionally, Java's extensive libraries and frameworks, such as Spring and Hibernate,
simplify complex development tasks, enabling developers to build reliable and scalable
applications efficiently. Throughout this internship, the focus on Java has highlight edits
adaptability and importance in developing versatile software solutions. Practical Experience
and Skill Enhancement During this internship, the practical experience gained with Java has
significantly reinforced theoretical knowledge. Engaging in real-world projects has
provided a deep understanding of Java's syntax, object-oriented principles, and best coding
practices. The opportunity to work on live projects has honed problem-solving skills and
taught the importance of writing clean, maintainable code. By collaborating with team
members and utilizing version control systems like Git, the experience has also enhanced
teamwork and project management skills, crucial for professional growth in the software
development industry. Industry Standards and Future Prospects This internship has offered
valuable insights into industry standards and best practices in software development.
Exposure to agile methodologies, continuous integration/continuous deployment (CI/CD)
pipelines, and comprehensive testing strategies has been instrumental in understanding how
professional development teams operate. The proficiency gained in Java during this period
forms a solid foundation for future endeavors in the field. As Java continues to evolve with
new features and improvements, the skills and knowledge acquired will be essential in
staying current and competitive in the ever-evolving tech landscape. This experience not
only prepares for immediate career opportunities but also paves the way for long-term
success in the software development domain.

41
REFERENCES

[1] https://docs.oracle.com/javase/8/docs/api/java/net/URL.htm
[2] https://www.geeksforgeeks.org/url-class-java-examples
[3] https://www.javatpoint.com/URL-class
[4] https://www.baeldung.com/java-url
[5] https://stackoverflow.com/questions/6098472/pass-a-local-file-in-to-url-in-java
[6] https://www.tutorialspoint.com/java/java_url_processing.html
[7] https://www.baeldung.com/javadoc-linking-external-url
[8] https://prutor.ai/url-class-in-java-with-examples/
[9] https://stackoverflow.com/questions/48839053/how-to-use-multiple-classes-in-java- in-one-file
[10] https://www.geeksforgeeks.org/java-for-loop-with-examples/
[11] https://www.w3schools.com/java/java_ref_reference.asp
[12] https://docs.oracle.com/javase/7/docs/api/javax/naming/Reference.html
[13] https://java-programming.mooc.fi/part-5/4-objects-and-references/
[14] https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html
[15] https://www.youtube.com/watch?v=DELCbBuCHHE
[16] https://www.naukri.com/code360/library/reference-variable-in-java
[17] https://www.youtube.com/watch?v=5VED1BML4ck
[18] https://www.youtube.com/watch?v=OS3s7OoGVi0
[19] https://www.youtube.com/watch?v=NScEo47hWo8
[20] https://www.youtube.com/watch?v=bQG5lzlzo6I

42

You might also like