Java Programming: ASATH K (717823L204)
Java Programming: ASATH K (717823L204)
AN INTERNSHIP REPORT
Submitted by
ASATH K [717823L204]
of
BACHELOR OF ENGINEERING
IN
DECEMBER 2024
KARPAGAM COLLEGE OF ENGINEERING
COIMBATORE – 641 032
ANNA UNIVERSITY: CHENNAI 600 025
BONAFIDE CERTIFICATE
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
III
CERTIFICATE OF INTERNSHIP
IV
ACKNOWLEDGEMENT
First and foremost praises and thanks to the almighty for her showers and blessings
ENGINEERING for provided the facilities, support and permission to carried out our /my
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
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
i
OVERVIEWOFINTERNSHIPACTIVITIES
DATE DAY NAME OF THE TOPIC
/MODULE
COMPLETED
15.06.2024 MONDAY Java Features
ii
LIST OF FIGURES
OOPS Concept 8
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
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.
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.
Object-oriented programming
8
CHAPTER 2
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.
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.
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.
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:
Example:
int a = 5;
double squareRoot =
Math.sqrt(49);
}}
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
i++) {
System.out.println(numbers[i]);
OUTPUT
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
int[][] numbers = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
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:
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.
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
{ int a = 10, b = 5;
Output
Addition: 15
Subtraction: 5
Multiplication: 50
Division: 2
Modulus: 0
5. addition (15)
subtraction (5)
multiplication (50)
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
%:
{ int a = 17, b = 4;
int result = a % b;
System.out.println("The remainder of " + a + " divided by " + b + " is: " + result);
Output
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)
int a = 10, b = 5;
a += b; // a = a + b
System.out.println("a += b: " +
a); a -= b; // a = a - b
a *= b; // a = a * b
System.out.println("a *= b: " +
a); a /= b; // a = a / b
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:
5. a %= b;: Finds the remainder of a divided by b and assigns the result back to a.
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.
o Prefix (++variable): Increments the value of the variable before using it.
o Prefix (--variable): Decrements the value of the variable before using it.
{ int a = 5, b = 10;
19
System.out.println("Prefix decrement of a: " + (--a)); // Decrement before usage
Output:
Initial values: a = 5, b = 10
Prefix increment of a: 6
Postfix increment of b: 10
11 Prefix decrement of a: 5
Postfix decrement of b: 11
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:
Example
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.
22
6. Shift Right (>>):
Shifts bits to the right, preserving the sign bit (arithmetic
shift). 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.
1. AND (&&): Returns true if both operands are 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 are used to compare two values. They return a boolean result (true
or false) based on the comparison.
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.
23
public class Logical And Relational Operators
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:
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.
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.
left. java
Copy code
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 =
{ 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:
28
as signment (+=, -=, *=, /=, %=).
29
CHAPTER 4
CONTROLSTATEMENTS
CONDITIONAL STATEMENTS
1. if Statement
if (number > 5) {
Explanation:
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.
{ int number = 3;
if (number > 5) {
30
} else {
Explanation:
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
{ int number = 8;
} else if (number == 8) {
} else {
Explanation:
31
The second condition number == 8 is true, so the message "The number is equal to
8." is printed.
4. switch Statement
The switch statement is used to select one of many code blocks to be executed based on
a variable's value.
{ 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 ternary operator is a shorthand for the if-else statement. It evaluates a condition and
returns one of two values.
{ int number = 4;
String result = (number > 5) ? "Greater than 5" : "Less than or equal to 5";
System.out.println(result);
Explanation:
Since number is 4, which is not greater than 5, the ternary operator returns "Less
than or equal to 5", and this is printed.
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:
// 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.
Example:
34
public static void main(String[] args)
Explanation:
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:
{ 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:
{ int i = 1;
do {
System.out.println("i = " +
i); i++;
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
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:
Example:
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
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.
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
if (i == 5) {
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