0% found this document useful (0 votes)
62 views155 pages

VAMSI27 Compressed

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

VAMSI27 Compressed

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

A SHORT-TERM INTERNSHIP REPORT

On

JAVA FULL-STACK
PROGRAMMING

Submitted to The Department of Computer Science

By

MADUGULA VAMSI
III B.Sc

Under the Esteemed Guidance of


Mrs. M DEEPTHI M.Tech
Vice Principal
Department of Computer Science

ADITYA DEGREE
COLLEGE-TUNI
ADITYA DEGREE
COLLEGE
Department of Computer Science

CERTIFICATE
This is to certify that The Short Term Internship entitled,
“JAVA FULL STACK PROGRAMMING” is a
bonified work of MADUGULA VAMSI, bearing
211177146174,III B.Sc, submitted to the Department of
Computer Science, Aditya Degree College, Tuni for the
Academic year 2021-2024.

Internship Guide Head of the Department


Smt.MDeepth,M.Tech Sri. B. Srinivas, Mech

External examiner Principal


ADITYA DEGREE COLLEGE

Department of Computer Science

DECLARATION BY THE STUDENT


I hereby declare that the work described in this Short Term
Internship, entitled “JAVA FULL STACK
PROGRAMMING” which is being submitted by me in partial
fulfilment of the requirements for the award of degree of
Bachelor of Computer Science in MCCS from the
Department of Computer Science to Aditya Degree College,
Tuni under the guidance of Mrs. M Deepthi, M.Tech, Vice
Principal in Aditya Degree College, Tuni.

Place: Tuni (M VAMSI)


Date:
ADITYA DEGREE
COLLEGE
Department of Computer Science

CERTIFICATE FROM THE SUPERVISOR

This is to certify that the Short Term Internship entitled,


”JAVA FULL STACK PROGRAMMING”, that is being
submitted by MADUGULA VAMSI bearing 211177146174,
III B.Sc, which is being submitted by me in partial fulfilment of
the requirements for the award of degree of Bachelor of
Computer Science in MCCS from the Department of
Computer Science to Aditya Degree College, bonified work
carried out by him under my guidance and Supervision.

Mr.G..Maniyya (M.Sc,B.Ed.,APSET)
ACKNOWLEDGEMENT
No endeavour is completed without the valuable support of others. I would like to
take this opportunity to extend my sincere gratitude to all those who have
contributed to the successful completion of this Short-Term Internship Project
Report.

At this juncture I feel deeply honoured in expressing my sincere thanks to


Miss.DEVIKA PAKRUTHI, Founder & CEO of Adhoc Network Tech Company,
Visakhapatnam for making the resources available at right time and providing
valuable insights leading to the successful completion of my Short-Term
Internship Project Report.

It is privilege to thank Dr.N.SESHA REDDY, Chairman, Aditya group of


institutions for providing state-of-the-Art facilities, experienced and talented
faculty members.
It is privilege to thank Dr.N.SUGUNA REDDY,Secretary Madam,Aditya of
for providing short term internship project report from ADHOC
I thank Dr.B.E.V.L.NAIDU, Academic Director, Aditya Degree College for his
continuous support and encouragement in my endeavour.

I express my deep sense of gratitude to Mr. MD.SHAIDDEN, Principal, for his


Efforts andfor giving us permission for carrying out this Short-Term Internship.

I thank Mr.B.SRINIVAS, Head of the Department of Bachelor of Computer


Science, Aditya Degree College-Tuni, for supporting and encouraging me in
completion of my Short-Term Internship.

Finally I thank all the faculty members of our Department who contributed their
valuable suggestions in completion of Short-Term Internship report and I also put
my sincere thanks to My Parents who stood with me during the whole Short-Term
Internship. -M Vamsi
INDEX
DESCRIPTION
ABSTRACT
1. INTRODUCTION 1-4

1.1 Short Term Internship Overview 5

1.2 Existing System 5

1.3 Proposed System 6

2. SYSTEM REQUIREMENTS

2.1 Functional Requirements 8

2.2 Non-functional Requirements 8

2.3 Software Requirements Specifications 9

3. PROGRAMS
3.1 Write a Demo program to print Hello World. 11

3.2 Write a program on Data Types. 12

3.3 Write a demo program on type conversion. 13

3.4 Write a demo program on One-Dimensional array. 14

3.5 Write a demo program on Two-Dimensional array. 15-16

3.6 Write a demo program on Arithmetic operators. 17

3.7 Write a demo program on Relational operators. 18

3.8 Write a demo program on bitwise operators. 19

3.9 Write a program to print elements in matrix form. 20-21

3.10 Write a program to print stars in increasing Triangular Format. 22

3.11 Write a demo program on Conditional Operator. 23

3.12 Write a program on Instance operator. 24


3.13 Write a demo program on Vehicle using Instanceof Operator. 25
3.14 Write a program on Inheritance 26

3.15 Write a demo program on If-Else statement. 27

3.16 Write a program on Nested ifelse 28

3.17 Write a program on While Loop. 29

3.18 Write a demo program on If-else ladder. 30

3.19 Write a program on Do-While loop. 31

3.20 Write a program on Switch Demo. 32

3.21 Write a program on Pyramid. 33

3.22 Write a program on Break statement. 34

3.23 Write a program on Continue Statement. 35

3.24 Write a program to find minimum value. 36

3.25 Write a program by using this instance. 37

3.26 Write a program on usage of class and new. 38

3.27 Write a program on Default constructor. 39

3.28 Write a program on parameter constructor. 40

3.29 Write a program on constructor overloading. 41

3.30 Write a program on copy constructor. 42

3.31 Write a program on copying object without constructor. 43

3.32 Write a program on this pointer. 44

3.33 Write a program on without this pointer. 45

3.34 Write another example program on this pointer. 46

3.35 Write a program on this pointer in constructor. 47

3.36 Write a program on this keyword with method ?//this: to invoke current. 48

3.37 Write a program on this() can be used to invoked current class constructor. 49

3.38 Write a program on counter without static variable . 50

3.39 Write a program on counter with static variable. 51

3.40 Write a program to implement string methods. 52

3.41 Write a program on command line arguments. 53

3.42 Write a program to implement Hybrid Inheritance. 54-55

3.43 Write a program to implement Method Overriding with super. 56

3.44 Write a program on creating packages. 57


3.45 Write a program on interface. 58

3.46 Write a program on to implement try, catch block. 59

3.47 Write a program on to implement Exception handling mechanism of try, catch and finally blocks. 60

3.48 Write a program to create our own thread using extended Thread class. 61

3.49 Write a program to create our own Thread using Runnable Interface (Implements). 62

3.50 Write a program to implements Thread Methods using Thread class. 63

4. JAVA FRAMES
4.1 Java program to create frame by frame class. 65

4.2 Creating a frame by extending frame class. 66

4.3 Java program to create a button. 67

4.4 Java program to create a Border Layout. 68

4.5 Write a program to create a Flow layout. 69

4.6 Java program to create panel layout. 70-71

4.7 Java program to create Textfield and Label. 72

4.8 Java program on Checkbox. 73

4.9 Java program to create TextArea. 74

4.10 Java program to create Grid Layout. 75

4.11 Java program to create Event. 76

4.12 Java program to create Focus Layout. 77-78

4.13 Java program to create Menu Bar. 79-80

4.14 Java program to create a scroll Bar. 81-82

4.15 Java program to create a Key Event. 83-84

5. MINI PROJECT 85-144

6. CONCLUSION 145
ABSTRACT

This Short Term Internship revolves around the comprehensive


development of a Java-based full-stack web application, aiming to
deliver a robust and user-friendly platform.

The internship also delved into object-oriented programming


paradigms, covering various aspects of constructors and
demonstrating the use of this pointer to enhance code readability
and maintainability. The implementation of counters and string
methods further enriched the understanding of object-oriented
concepts.

Advanced topics such as Hybrid Inheritance, Method Overriding


with super, and the creation of packages were explored to promote
code modularity and reusability. The internship
culminated in the study of multi-threading and exception handling
mechanisms, showcasing practical implementations of these
crucial Java features.

In summary, this Java internship equipped me with a diverse skill


set ranging from basic programming constructs to advanced
object-oriented principles. The projects undertaken not only
improved my proficiency in Java but also instilled a problem-
solving mindset essential for real-world application development.
INTRODUCTION

1
Introduction
Launched on 16th January, 2016, the Startup India Initiative has rolled out several
programs with the objective of supporting entrepreneurs, building a robust startup
ecosystem and transforming India into a country of job creators instead of job
seekers. These programs are managed by a dedicated Startup India Team, which
reports to the Department for Industrial Policy and Promotion (DPIIT). This startup
culture, or startup mindset, features several key characteristics, including a
commitment to innovation and a willingness to take risks and make decisions
quickly. This atmosphere attracts potential workers who seek out that environment.
A startup is in the first stage of operations and comprises one or more entrepreneurs.
The primary aim is to answer market demand by creating new and innovative
products or services.
Startups begin with high costs and have limited revenue. Also, they do not have a
developed business model and lacks adequate capital to move to the next phase. As a
result, these companies seek funding from various sources, such as venture
capitalists, angel investors and banks. Investors or lenders might offer additional
funds for a share of future profits and partial ownership. Often, these companies use
seed capital for investing in research and developing business plans. Research helps
them determine the demand for a specific product and a business plan outlines the
company's goals and marketing strategies.
About Adhoc Network:
Adhoc Network is started in the year 2020 at Visakhapatnam by an young Women
entrepreneur Miss. Devika Pakruthi Founder & CEO with an intention to provide
employment opportunities to the youth and also to impart the best quality training
and practical exposure to the Students which enhances their employability Skills. Her
journey started and collapsed with the wide spread of Covid-19 but her determination
and aspirations made her journey more futuristic and she never gave up the thought to
GIVE-UP. This is where Devika made her dreams come true and alive. She never
expected with a sole objective of making Profit but her determination to impart the
quality training made her to reach the peaks of success at the young age.

2
Adhoc Network-we are proud to have been awarded a Hattrick of Awards. This
Achievement is a testament to our commitment to Excellence and Innovation in the
Software development Best heading company in the market. Devika Pakruthi, a name
synonymous with innovation, empowerment, and success. As the proud recipient of
the Young Entrepreneur Award, Best Women-Led Startup Award, Women Rising
Star of the Year Award and Youngest CEO of the Year Award, Devika Pakruthi has
etched her name into the annals of contemporary business history.
Vision, Mission and values of the Organization:-
VISION:-
Due vision is to be a leading global provider of interactive and reliable
Software Solution empowering business to Thrive in the digital age.
MISSION:-
Our mission is to develop cutting-edge Software Solutions that Solve compare
business challenges, enhance Operations efficiency and drive Sustainable growth for
our client we strive to deliver exceptional value by leveraging emerging technologies,
fostering Strategic partnerships and maintaining a Customer, Centric approach
Values

⚫ Innovation

⚫ Excellence

⚫ Collaboration

⚫ Integrity

⚫ Customer Centricity

⚫ Continuous Learning

We are providing services to the following Clients-


• MTA Canada
• Aleph Nation-Wide Solutions India
• Botta Associates

3
Introduction to Java:-
Java is an Object-Oriented, General-Purpose Programming Language. It is
a widely used robust technology. It was developed by James Gosling by
sun microsystems. Later, it was named as Oak and JDK (Java
Development Kit) developed in 1950s.Java programs can run on any
device with a Java Virtual Machine (JVM), ensuring platform
independence I.e, it runs on any platforms like Windows, Linux etc. Java
syntax is similar to C++, making it accessible to programmers familiar
with C-style languages.
Java is an object oriented because everything in a java program is an
object. Itincludes classes and objects
Java has a better security to protect the data by setting passwords and easy
to handle threats and errors.
Inheritance, polymorphism, and encapsulation are the
three main OOP features supported in Java.

4
1.1. SHORT TERM INTERSHIP OVERVIEW
This Java full-stack web application project is designed to create a
responsive and efficient platform, combining front-end and back-end
development. The front-end utilizes Angular, React, or Vue.js for an
intuitive user interface with a focus on responsiveness across various
devices. On the back-end, Spring Boot is employed to establish a
scalable server-side architecture, incorporating a relational database for
secure data management. Rigorous testing, including unit, integration,
and end-to-end testing, is implemented to ensure application reliability,
with automation through continuous integration and deployment
pipelines. Security measures, such as encryption and authentication
protocols, are integrated to safeguard sensitive information. Overall, this
project adopts modern development practices to deliver a high-
performance web application that prioritizes simplicity, efficiency, and a
positive user experience.

1.2. EXISTING SYSTEM :


The current system in place lacks the necessary efficiency and
responsiveness required for modern web applications. It exhibits
limitations in terms of user interface design, often resulting in a
suboptimal user experience. Additionally, the absence of a robust back-
end architecture hinders scalability and secure data management.
Furthermore, the absence of comprehensive testing practices increases
the risk of reliability issues, and security measures are minimal, posing a
potential threat to sensitive information. In summary, the existing system
falls short in meeting contemporary standards for web application
development, necessitating the implementation of a more sophisticated
and streamlined solution.

5
1.3. PROPOSED SYSTEM :
To ensure reliability, the proposed system will implement rigorous testing
methodologies, including unit testing, integration testing, and end-to-end
testing.Continuous integration and deployment pipelines will be
established to automate the testing and deployment processes, reducing the
risk of errors and enhancing development efficiency.
Security measures, including encryption and authentication protocols, will
be implemented to safeguard sensitive information, addressing the
shortcomings of the existing system. The proposed system thus aims to
deliver a high-performance web application that adheres to modern
development practices, ensuring simplicity, efficiency, and an improved
user experience.

APPLICATIONS OF PROPOSED SYSTEM :


Intuitive user interface enhances the learning experience for students and
educators.
Robust security measures protect confidential HR information.
Intuitive design improves collaboration and task management.
Reliable back-end architecture ensures real-time data synchronization.

6
SYSTEM REQUIREMENTS

7
1. Functional Requirements:
User Authentication: Users should be able to register, log in, and log out
securely.
User Interface: The system should provide an intuitive and responsive user
interface, supporting multiple devices and screen sizes.
Data Management: The application should enable users to perform CRUD
(Create, Read, Update, Delete) operations on relevant data.
Search Functionality: Users should be able to search and filter data efficiently
based on specified criteria.
Security Measures: The system should implement encryption and
authentication protocols to ensure the confidentiality and integrity of user data.

2. Non-functional Requirements:
Performance: The system should respond to user requests within acceptable
time frames, even under peak loads.
Scalability: The architecture should be scalable to accommodate a growing
userbase and increasing data volumes.
Compatibility: The system should be compatible with various web browsers
andoperating systems.

8
3. Software Requirements Specifications (SRS):
Operating System: The application should be compatible with Windows,
Linux,and macOS.
Web Server: Apache or Nginx for hosting the web application.
Database Management System (DBMS): MySQL or PostgreSQL for efficient
data storage and retrieval.
Programming Language: Java for back-end development.

4. Hardware Components:
Server: A dedicated server or cloud-based infrastructure to host the web
application.
Processor: Multi-core processors for handling concurrent user requests.
Memory (RAM): A sufficient amount of RAM to support the application's
performance requirements.

5. Network Components:
Internet Connection: A high-speed and reliable internet connection for
seamless user interactions.
Firewall: Network firewall to protect against unauthorized access and potential
security threats.
Load Balancer: If applicable, a load balancer to distribute incoming traffic
acrossmultiple servers for optimal performance and scalability.

9
PROGRAMS

10
1.Write a Demo program to display Hello World.
class Hello
{
public static void main(String args[])
{
System.out.println("Hello World!");
}
}
Output:

11
2. Write a Demo program on Datatype.
public class PrimitiveDemo
{
public static void main(String args[])
{
Byte b=100;
Short s=123;
int v=123543;
int calc=-9876345;
long amountval=1234567891;
Float interestrate=12.25f;
Double sineval=12345.234d;
Boolean flag=true;
Boolean val=false;
char ch1=88;
char ch2='y';
System.out.println("Byte value:"+b);
System.out.println("Short value:"+s);
System.out.println("Int value:"+v);
System.out.println("Int second value:"+calc);
System.out.println("long value:"+amountval);
System.out.println("Float value:"+v);
System.out.println("Double value:"+v);
System.out.println("Boolean value:"+flag);
System.out.println("Byte value:"+val);
System.out.println("Char value:"+ch1);
System.out.println("Char value:"+ch2);
}
}
Output:

12
3. Write a Demo program on type conversion.
class Demo
{
public static void main(String args[])
{
char ch1='A';
double d1=ch1;
System.out.println(d1);
System.out.println(ch1*ch1);
double d2=66.0;
char ch2=(char)d2;
System.out.println(ch2);
}
}
Output:

13
4. Write a Demo program on one-Dimensional Array.
class Average
{
public static void main(String args[])
{
double num[]={10.1,11.2,12.3,13.4,14.5};
double result=0;
for(int i=0;i<5;i++)
result=result+num[i];
System.out.println("Average of numbers:"+result/5);
}
}
Output:

14
5. Write a Demo program on Two-Dimensional Array.
class TwoDim
{
public static void main(String args[])
{
int a[][]=new int[2][2];
int b[][]=new int[2][2];
a[0][0]=1;
a[0][1]=2;
a[1][0]=3;
a[1][1]=4;
b[0][0]=5;
b[0][1]=6;
b[1][0]=7;
b[1][1]=8;
int c[][]=new int[2][2];
System.out.println("elements of first matrix:");
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
System.out.println(a[i][j]);
}
}
System.out.println("elements of second matrix:");
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
System.out.println(b[i][j]);
}
}
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
System.out.println("Addition of two matrices");
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)

15
{
System.out.println(c[i][j]);
}
}
}
}
Output:

16
6. Write a Demo program on Arithmetic operators.

import java.util.Scanner;
class BasicArithmeticDemo
{
public static void main(String args[])
{
int a,b;
System.out.println("Value of a and b:");
Scanner input=new Scanner(System.in);
a=input.nextInt();
b=input.nextInt();
System.out.println("Addition:"+(a+b));
System.out.println("Substraction:"+(a-b));
System.out.println("Multiplication:"+(a*b));
System.out.println("Division:"+(a/b));
System.out.println("Percentage:"+(b%a));
}
}
Output:

17
7. Write a Demo program on Relational operators.
import java.util.Scanner;
class ReIOpDemo
{
public static void main(String args[])
{
int a,b;
System.out.println("Value of a and b:");
Scanner input=new Scanner(System.in);
a=input.nextInt();
b=input.nextInt();
System.out.println("Greater than operator(a>b):"+(a>b));
System.out.println("Greater than or equal to operator(a>=b):"+(a>=b));
System.out.println("Less than operator(a<b):"+(a<b));
System.out.println("Less than or equal to operator(a<=b):"+(a<=b));
System.out.println("Not equal to operator(a!=b):"+(a!=b));
System.out.println("Equal to operator(a==b):"+(a==b));
}
}
Output:

18
8. Write a Demo program on Bitwise operators.

public class BitwiseOpDemo


{
public static void main(String args[])
{
int a=60;
int b=13;
int c=0;
c=a&b;
System.out.println("a&b="+c);
c=a|b;
System.out.println("a|b="+c);
c=a^b;
System.out.println("a^b="+c);
c=-a;
System.out.println("-a="+c);
c=a<<2;
System.out.println("a<<2="+c);
c=a>>2;
System.out.println("a>>2="+c);
c=a>>>2;
System.out.println("a>>>2="+c);
}
}
Output:

19
9. Write a program to print elements in matrix form.
class MatrixAddition
{
public static void main(String args[])
{
int a[][]=new int[2][2];
int b[][]=new int[2][2];
a[0][0]=1;
a[0][1]=2;
a[1][0]=3;
a[1][1]=4;
b[0][0]=5;
b[0][1]=6;
b[1][0]=7;
b[1][1]=8;
int c[][]=new int[2][2];
System.out.println("elements of first matrix:");
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
System.out.println("elements of second matrix:");
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
System.out.print(b[i][j]+" ");
}
System.out.println();
}
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
System.out.println("Addition of two matrices");
for(int i=0;i<2;i++)

20
{
for(int j=0;j<2;j++)
{
System.out.print(c[i][j]+" ");
}
System.out.println();
}
}
}
Output:

21
10. Write a program to print stars in increasing Triangular Format.
class TriangleStarPattern
{
public static void main(String args[])
{
int n=5;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
Output:

22
11.write a demo program on conditional operators.
public class ConditionalOp
{
public static void main(String args[])
{
int a,b;
a=10;
b=(a==1)?20:30;
System.out.println("Value of b is:"+b);
b=(a==10)?20:30;
System.out.println("Value of b is:"+b);
}
}
Output:

23
12. write a demo program on typecasting.
public class InstanceOfOperator
{
public static void main(String args[])
{
String name="James";
boolean result=name instanceof String;
System.out.println(result);
}
}
Output:

24
13. write a demo program on typecasting.
class Vehicle
{
}
public class Car extends Vehicle
{
public static void main(String args[])
{
Vehicle ve=new Car();
boolean result=ve instanceof Car;
System.out.println(result);
}
}
Output:

25
14.write a demo program on if statement.
class If
{
public static void main(String args[])
{
int test=10;
if(test>6)
{
System.out.println("Success!");
}
System.out.println("Execyted successfully");
}
}
Output:

26
15. write a demo program on ifelse statement.
class Ifelse
{
public static void main(String args[])
{
int test=10;
if(test==10)
{
System.out.println("The value is equal to 10");
}
else
{
System.out.println("Value not equal to 10");
}
}
}
Output:

27
16. write a demo program on ifelse statement.
public class NestedIfElse
{
public static void main(String args[])
{
int test1=3;
int test2=3;
if(test1==5)
{
if(test2==3)
{
System.out.println("hi,test1 is 5 and test2 is 3");
}
else
{
System.out.println("hi,test1 is 5 and test2 is somevalue is other than 3");
}
}
else if(test1==4)
{
System.out.println("hi,test1 is 3 and test2 is 3");
}
else if(test1==3)
{
if(test2==3)
{
System.out.println("hi,test1 is 3 and test2 is 3");
}
else if(test2==2)
{
System.out.println("hi,test1 is 3 and test2 is 2");
}
}
else
System.out.println("hi,test1 is somevalue other than 5,4, 3");
}
}
Output:

28
17. write a demo program on while loop.
class WhileLoopEx3
{
public static void main(String args[])
{
int arr[]={2,11,45,9};
int i=0;
while(i<4)
{
System.out.println(arr[i]+"");
i++;
}
}
}
Output:

29
18. write a demo program on if else ladder.
public class Ifelseladder
{
public static void main(String args[])
{
int test=2;
if(test==1)
System.out.println("Hello");
else if(test==2)
System.out.println("Hi");
else if(test==3)
System.out.println("Good");
else
System.out.println("No match found");
}
}
Output:

30
19. write a demo program on dowhile loop.
class DoWhile
{
public static void main(String args[])
{
int i=20;
do
{
System.out.println(i);
i--;
}while(i<1);
}
}
Output:

31
20. write a demo program on switch case.
class SwitchDemo2
{
public static void main(String args[])
{
int month=2;
int year=2000;
int numDays=0;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
numDays=31;
break;
case 2:
if(((year%4==0)&&!(year%100==0))||(year%400==0))
numDays=29;
else
numDays=28;
break;
default:
System.out.println("Invalid month");
break;
}
System.out.println("Number of days="+numDays);
}
}
Output:

32
21.write a program for reverse pattern.
import java.util.Scanner;
class Pattern1
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n,i,j,s,m;
n=sc.nextInt();
s=sc.nextInt();
for(i=0;i<=n;i++)
{
m=s;
while(s>0)
{
System.out.print(" ");
s--;
}
for(j=0;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
s=m-1;
}
}
}
Output:

33
22.write a program on break statement.
class Breaks
{
public static void main(String args[])
{
int i,n=7,c=0;
for(i=2;i<=10;i++)
{
if(n%i==0)
{
System.out.println(n+"is prime");
c++;
break;
}
}
if(c==0)
System.out.println(n+"is not prime");
}
}
Output:

34
23.write a program on continue statement.
class Continu
{
public static void main(String args[])
{
int n=10,i=0;
for(i=0;i<=n;i++)
{
if(n!=i)
continue;
System.out.println(i);
}
}
}
Output:

35
24.write a program on addition of two numbers.
class Function
{
public static void main(String args[])
{
int a=20,b=30,c;
c=fun(a,b);
System.out.println(c);
}
public static int fun(int n,int m)
{
return(n+m);
}
}
Output:

36
25. write a program on this for instance variable.
class Box
{
int len=10;
void meth()
{
int len=40;
System.out.println("Length is:"+len);
System.out.println("Instance value="+this.len);
}
}
class ThisInstance
{
public static void main(String args[])
{
Box obj=new Box();
obj.meth();
}
}

37
26. write a program on using class and new.
class Student2
{
int rollno;
String name;
void insertRecord(int r,String n)
{
rollno=r;
name=n;
}
void displayInformation()
{
System.out.println(rollno+" "+name);
}
public static void main(String args[])
{
Student2 s1=new Student2();
Student2 s2=new Student2();
s1.insertRecord(111,"praneeth");
s2.insertRecord(112,"prayaga");
s1.displayInformation();
s2.displayInformation();
}
}
Output:

38
27. write a program on Default constructor.
public class MyDefaultCons
{
public MyDefaultCons()
{
System.out.println("I am inside default constructor");
}
public static void main(String args[])
{
MyDefaultCons mdc=new MyDefaultCons();
}
}
Output:

39
28. write a program on parameter constructor.
class Student4
{
int id;
String name;
Student4(int i,String n)
{
id=i;
name=n;
}
void display()
{
System.out.println(id+" "+name);
}
public static void main(String args[])
{
Student4 s1=new Student4(2003,"praneeth");
Student4 s2=new Student4(2003,"Abida");
s1.display();
s2.display();
}
}
Output:

40
29. write a program on constructor overloading.
class Student5
{
int id;
String name;
int age;
Student5(int i,String n,int a)
{
id=i;
name=n;
age=a;
}
void display()
{
System.out.println(id+" "+name+" "+age);
}
public static void main(String args[])
{
Student5 s1=new Student5(2003,"praneeth",19);
Student5 s2=new Student5(2003,"Abida",20);
s1.display();
s2.display();
}
}
Output:

41
30.write a program on copy constructor.
class Student6
{
int id;
String name;
Student6(int i,String n)
{
id=i;
name=n;
}
Student6(Student6 s)
{
id=s.id;
name=s.name;
}
void display()
{
System.out.println(id+" "+name);
}
public static void main(String args[])
{
Student6 s1=new Student6(2003,"praneeth");
Student6 s2=new Student6(s1);
s1.display();
s2.display();
}
}
Output:

42
31.write a program on coping object without constructor.
class Student7
{
int id;
String name;
Student7(int i,String n)
{
id=i;
name=n;
}
Student7()
{
}
void display()
{
System.out.println(id+" "+name);
}
public static void main(String args[])
{
Student7 s1=new Student7(2003,"praneeth");
Student7 s2=new Student7();
s2.id=s1.id;
s2.name=s1.name;
s1.display();
s2.display();
}
}
Output:

43
32.write a program on this pointer.
class Student8
{
int id;
String name;
Student8(int id,String name)
{
this.id=id;
this.name=name;
}
void display()
{
System.out.println(id+" "+name);
}
public static void main(String args[])
{
Student8 s1=new Student8(2003,"praneeth");
Student8 s2=new Student8(2003,"prayaga");
s1.display();
s2.display();
}
}
Output:

44
33.write a program on this pointer.
class Student10
{
int id;
String name;
Student10(int id,String name)
{
id=id;
name=name;
}
void display()
{
System.out.println(id+" "+name);
}
public static void main(String args[])
{
Student10 s1=new Student10(2003,"praneeth");
Student10 s2=new Student10(2003,"prayaga");
s1.display();
s2.display();
}
}
Output:

45
34.write another example program on this pointer?
class JBT
{
int variable=5;
public static void main(String args[])
{
JBT obj=new JBT();
obj.method(20);
obj.method();
}
void method(int variable)
{
variable=10;
System.out.println("Value of instance variable:"+this.variable);
System.out.println("Value of local variable:"+variable);
}
void method()
{
int variable=40;
System.out.println("Value of instance variable:"+this.variable);
System.out.println("Value of local variable:"+variable);
}
}
Output:

46
35.write a program on this pointer in constructor?
class JBT2
{
JBT2()
{
this("JBT2");
System.out.println("inside constructor without parameter");
}
JBT2(String str)
{
System.out.println("inside constructor without parameter"+str);
}
public static void main(String args[])
{
JBT2 obj=new JBT2();
}
}
Output:

47
36.write a program on this keyword with method.
class JBT3
{
public static void main(String args[])
{
JBT3 obj=new JBT3();
obj.methodTwo();
}
void methodOne()
{
System.out.println("inside method one");
}
void methodTwo()
{
System.out.println("inside method two");
this.methodOne();
}
}
Output:

48
37.write a program on this() can be used to invoked current class constructor.
class Student9
{
int id;
String name;
Student9()
{
System.out.println("default constructor is invoked");
}
Student9(int i,String n)
{
this();
id=i;
name=n;
}
void display()
{
System.out.println(id+" "+name);
}
public static void main(String args[])
{
Student9 e1=new Student9(2002,"shannu");
Student9 e2=new Student9(2003,"virat");
e1.display();
e2.display();
}
}
Output:

49
38.write a program on counter without static variable.
class Counter
{
int count=0;
Counter()
{
count++;
System.out.println(count);
}
public static void main(String args[])
{
Counter c1=new Counter();
Counter c2=new Counter();
Counter c3=new Counter();
}
}
Output:

50
39.write a program on counter with static variable.
class Counter2
{
static int count=0;
Counter2()
{
count++;
System.out.println(count);
}
public static void main(String args[])
{
Counter2 c1=new Counter2();
Counter2 c2=new Counter2();
Counter2 c3=new Counter2();
}
}
Output:

51
40.write a program to implement string Methods.
class StringMethods
{
public static void main(String args[])
{
String s1=new String("charles");
String s2="p"+"CHARLES"+"(MTECH)";
String s3=s1;
char[] helloArray={'H','E','L','L','O','.'};
String s4=new String(helloArray);
System.out.println(s4);
System.out.println(s1);
System.out.println(s2);
System.out.println(s1.toUpperCase());
System.out.println(s2.toLowerCase());
System.out.println(s2.length());
System.out.println(s1.charAt(3));
System.out.println(s1.equals(s3));
System.out.println(s1.concat("RAJI"));
System.out.println(s1.replace('c','C'));
System.out.println(s1.equalsIgnoreCase("CHARLES"));
System.out.println(s1.substring(5));
if(s1.equals(s2))
System.out.println("string 1 and string 2 are equal");
else
System.out.println("string 1 and string 2 are not equal");
}
}
Output:

52
41.write a program on commend line arguments.
class CommandLineArugumentsDemo
{
public static void main(String args[])
{
System.out.println("Command line arguments length is:"+args.length);
System.out.println("Array index 0 value is:"+args[0]);
System.out.println("Array index 1 value is:"+args[1]);
}
}
Output:

53
42.write a program to implement Hybrid Inheritance.
class A
{
public void methodA()
{
System.out.println("class A methodA");
}
}
class B extends A
{
public void methodA()
{
System.out.println("child class B is over ridding inherited method");
}
public void methodB()
{
System.out.println("class B methodB");
}
}
class C extends A
{
public void methodA()
{
System.out.println("child class C is over ridding inherited method");
}
public void methodC()
{
System.out.println("class C methodC");
}
}
class D extends B
{
public void methodD()
{
System.out.println("class D methodD");
}
public static void main(String args[])
{
D obj1=new D();
obj1.methodD();
obj1.methodA();
}
}

54
Output:

55
43.write a program to implement method Overriding with super.
class ABC
{
public void mymethod()
{
System.out.println("class ABC:mymethod()");
}
}
class Test1 extends ABC
{
public void mymethod()
{
super.mymethod();
System.out.println("class test:mymethod():");
}
public static void main(String args[])
{
Test1 obj=new Test1();
obj.mymethod();
}
}
Output:

56
44.write a demo program on creating packages.
AccessDemo.java
package abc;
public class AccessDemo
{
public void test()
{
System.out.println("Hi.....");
}
}
AccessExample.java
import abc.AccessDemo;
public class AccessExample
{
public static void main(String args[])
{
AccessDemo ad=new AccessDemo();
ad.test();
}
}
Output:

57
45.write a program on interface.
interface Myinterface
{
public void method1();
public void method2();
}
class XYZ implements Myinterface
{
public void method1()
{
System.out.println("implementation of method1");
}
public void method2()
{
System.out.println("implementation of method2");
}
public static void main(String args[])
{
Myinterface obj=new XYZ();
obj.method1();
}
}
Output:

58
46.write a program to implement try ,catch blocks.
import java.io.*;
public class ExceptHan
{
public static void main(String args[])
{
try
{
int a[]=new int[2];
System.out.println("accessing element three:"+a[3]);
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Exception:"+e);
}
System.out.println("out of the block");
}
}
Output:

59
47.write a program to implement Exception Handling mechanisms of try,catch
and finally blocks.
public class Myfinallyblock
{
public static void main(String args[])
{
try
{
int i=10/0;
}
catch(ArithmeticException ex)
{
System.out.println("Inside 1st catch block");
}
finally
{
System.out.println("Inside 1st finally block");
}
try
{
int i=10/10;
}
catch(ArithmeticException ex)
{
System.out.println("Inside 2nd catch block");
}
finally
{
System.out.println("Inside 2nd finally block");
}
}
}
Output:

60
48.write a program to create our own thread using extended threadclass
class MyThread extends Thread
{
public void run()
{
System.out.println("implementation of thread using the extended thread class");
}
}
class MyThreadExtendsThread
{
public static void main(String args[])
{
MyThread mt=new MyThread();
mt.start();
}
}
Output:

61
49.Write a program to create our own Thread using Runnable interface
class mymethod implements Runnable
{
public void run()
{
System.out.println("implementation of thread using the runnable interface");
}
}
class MyThreadImplementsRunnable
{
public static void main(String args[])
{
Runnable r=new Mymethod();
Thread t=new Thread(r);
t.start();
}
}
Output:

62
50. Write a program to implement Thread methods using thread class

import java.lang.*;
class MyThread extends Thread
{
public void run()
{
for(int i=0;i<=5;i++)
{
try
{
Thread.sleep(1000);
}
catch(Exception e)
{
}
System.out.println(i);
}
}
}
class ThreadMethods
{
public static void main(String args[])
{
MyThread mt = new MyThread();
System.out.println("Thread name is:"+mt.getName());
mt.setName("Daniel");
System.out.println("Thread name after setting new name is:"+mt.getName());
System.out.println("thread priority is:"+mt.getPriority());
mt.setPriority(1);
System.out. println("After Changing Thread Priority is:"+mt.getPriority());
System.out.println("thread ID is:"+mt.getId());
}
}
Output:

63
JAVA FRAMES

64
1.Java program to create frame by frame class.
A.
import java.awt.*;
class Awt1
{
Awt1(String s)
{
Frame f=new Frame();
f.setTitle(s);
f.setSize(200,200);
f.show();
}
public static void main(String args[])
{
Awt1 a=new Awt1("Welcome to awt");
}
}

Output:

65
2.Create a frame by extending frame class.
A.
import java.awt.*;
class Awt2 extends Frame
{
Awt2(String s)
{
super(s);
setSize(200,200);
setVisible(true);
}
public static void main(String[] args)
{
Awt2 a=new Awt2("Welcome to awt");
}
}
Output:

66
3.Java program to create a button.
A.
import java.awt.*;
class Container extends Frame
{
Container(String s)
{
super(s);
setSize(200,200);
setVisible(true);
Button b=new Button("Vamsi");
add(b);
}
public static void main(String[] args)
{
Container b=new Container("Button");
}
}
Output:

67
4.Java program to create a BorderLayout.
A.
import java.awt.*;
class Borex extends Frame
{
Borex(String s)
{
super(s);
Button b1,b2,b3,b4,b5;
b1=new Button("First");
b2=new Button("Second");
b3=new Button("Third");
b4=new Button("Fourth");
b5=new Button("Fifth");
add(b1,"North");
add(b2,"South");
add(b3,"East");
add(b4,"West");
add(b5,"Center");
}
public static void main(String args[])
{
Borex b=new Borex("Button");
b.setSize(500,500);
b.setVisible(true);
}
}
Output:

68
5.Write a program to create a Flow layout.
A.
import java.awt.*;
class Flowex extends Frame
{
Flowex(String tit)
{
super(tit);
Button b1,b2,b3;
b1=new Button("1");
b2=new Button("2");
b3=new Button("3");
setLayout(new FlowLayout());
add(b1);
add(b2);
add(b3);
}
public static void main(String args[])
{
Flowex f1=new Flowex("Flow layout demo");
f1.setSize(400,400);
f1.setVisible(true);
}
}
Output:

69
6.Java program to create a Panel Layout.
A.
import java.awt.*;
class Panelex extends Frame
{
Panelex(String tit)
{
super(tit);
Button b1,b2,b3,b4,b5,b6;
b1=new Button("1");
b2=new Button("2");
b3=new Button("3");
b4=new Button("4");
b5=new Button("5");
b6=new Button("6");
Panel p1=new Panel();
p1.add(b1);
p1.add(b2);
p1.add(b3);
add(p1,BorderLayout.NORTH);
Panel p2=new Panel();
p2.add(b4);
p2.add(b5);
p2.add(b6);
add(p2,BorderLayout.SOUTH);
}
public static void main(String args[])
{
Panelex f1=new Panelex("Panel demo");
f1.setSize(400,400);
f1.setVisible(true);
}
}
Output:

70
71
7.Java program to create Texfield and Label.
A.
import java.awt.*;
class Panelex extends Frame
{
Panelex(String tit)
{
super(tit);
Button b1,b2,b3,b4,b5,b6;
b1=new Button("1");
b2=new Button("2");
b3=new Button("3");
b4=new Button("4");
b5=new Button("5");
b6=new Button("6");
Panel p1=new Panel();
p1.add(b1);
p1.add(b2);
p1.add(b3);
add(p1,BorderLayout.NORTH);
Panel p2=new Panel();
p2.add(b4);
p2.add(b5);
p2.add(b6);
add(p2,BorderLayout.SOUTH);
}
public static void main(String args[])
{
Panelex f1=new Panelex("Panel demo");
f1.setSize(400,400);
f1.setVisible(true);
}
}
Output:

72
8.Java program on Checkbox.
A.
import java.awt.*;
class CBGex extends Frame
{
Checkbox cbjava,cbejb,cbc,cbcpp;
CBGex(String tit)
{
super(tit);
cbjava=new Checkbox("Java");
cbejb=new Checkbox("Ejb");
Panel p1=new Panel();
p1.add(cbjava);
p1.add(cbejb);
add(p1,BorderLayout.NORTH);
CheckboxGroup cg=new CheckboxGroup();
cbc=new Checkbox("C",true,cg);
cbcpp=new Checkbox("C++",false,cg);
Panel p2=new Panel();
p2.add(cbc);
p2.add(cbcpp);
add(p2,BorderLayout.CENTER);
}
public static void main(String args[])
{
CBGex f1=new CBGex("Check box demo");
f1.setSize(400,400);
f1.setVisible(true);
}
}
Output:

73
9. Java program to create TextArea.
A.
import java.awt.*;
class TAex extends Frame
{
TAex(String title)
{
super(title);
Label L3=new Label("Enter Address");
TextArea ta=new TextArea(4,20);
Panel p1=new Panel();
p1.add(L3);
p1.add(ta);
add(p1,BorderLayout.CENTER);
}
public static void main(String args[])
{
TAex f1=new TAex("TextArea Demo");
f1.setSize(400,400);
f1.setVisible(true);
}
}
Output:

74
10. Java program to create Grid Layout.
A.
import java.awt.*;
class Gridex extends Frame
{
Gridex(String tit)
{
super(tit);
Button b1,b2,b3,b4;
TextField tf1,tf2,tf3,tf4;
b1=new Button("1");
b2=new Button("2");
b3=new Button("3");
b4=new Button("4");
tf1=new TextField("");
tf2=new TextField("");
tf3=new TextField("");
tf4=new TextField("");
setLayout(new GridLayout(2,4));
add(b1);
add(b2);
add(b3);
add(b4);
add(tf1);
add(tf2);
add(tf3);
add(tf4);
}
public static void main(String args[])
{
Gridex f1=new Gridex("Grid Layout Demo");
f1.setSize(400,400);
f1.setVisible(true);
}
}
Output:

75
11.Java program to create Event.
A.
import java.awt.*;
import java.awt.event.*;
class BEventEx extends Frame implements ActionListener
{
Button bshow,bclose;
BEventEx(String tit)
{
super(tit);
bshow=new Button("show");
bclose=new Button("close");
bshow.addActionListener(this);
bclose.addActionListener(this);
setLayout(new FlowLayout());
add(bshow);
add(bclose);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource().equals(bshow))
System.out.println("Show Button is clicked");
else if(ae.getSource().equals(bclose))
System.exit(0);
}
public static void main(String args[])
{
BEventEx b=new BEventEx("Event Demo");
b.setSize(300,400);
b.setVisible(true);
}
}
Output:

76
12.Java program to create Focus Layout.
A.
import java.awt.*;
import java.awt.event.*;
class Focusex extends Frame implements FocusListener
{
TextField tf1,tf2,tf3;
Label label1,label2;
Focusex(String tit)
{
super(tit);
tf1=new TextField(20);
tf2=new TextField(20);
tf3=new TextField(20);
label1=new Label("+");
label2=new Label("=");
tf3.addFocusListener(this);
setLayout(new FlowLayout());
add(tf1);
add(label1);
add(tf2);
add(label2);
add(tf3);
}
public void focusGained(FocusEvent fe)
{
int a=Integer.parseInt(tf1.getText());
int b=Integer.parseInt(tf2.getText());
tf3.setText(""+(a+b));
}
public void focusLost(FocusEvent fe)
{
}
public static void main(String args[])
{
Focusex fe=new Focusex("Focus Demo");
fe.setSize(500,600);
fe.setVisible(true);
}
}
Output:

77
78
13. Java program to create Menu Bar.
A.
import java.awt.*;
import java.awt.event.*;
class Menuex extends Frame implements ActionListener
{
MenuBar mb;
Menu mfile,medit;
MenuItem minew,miopen,miedit,miexit;
Menuex(String title)
{
super(title);
mb=new MenuBar();
mfile=new Menu("File");
medit=new Menu("Edit");
minew=new MenuItem("New");
miopen=new MenuItem("Open");
miexit=new MenuItem("Exit");
minew.addActionListener(this);
miopen.addActionListener(this);
miexit.addActionListener(this);
mfile.add(minew);
mfile.add(miopen);
mfile.addSeparator();
mfile.add(miexit);
mb.add(mfile);
mb.add(medit);
setMenuBar(mb);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource().equals(minew))
{
System.out.println("Selected new");
}
if(ae.getSource().equals(miopen))
{
System.out.println("Selected open");
}
if(ae.getSource().equals(miexit))
{
System.exit(0);
}

79
}
public static void main(String args[])
{
Menuex fe=new Menuex("Menu Demo");
fe.setSize(500,600);
fe.setVisible(true);
}
}
Output:

80
14.Java program to create a Scroll Bar.
A.
import java.awt.*;
import java.awt.event.*;
class Scrollex extends Frame implements AdjustmentListener
{
Scrollbar s1,s2,s3;
Color cl;
Scrollex(String tit)
{
super(tit);
s1=new Scrollbar(Scrollbar.VERTICAL,0,5,0,225);
s2=new Scrollbar(Scrollbar.HORIZONTAL,0,5,0,225);
s3=new Scrollbar(Scrollbar.VERTICAL,0,5,0,255);
s1.addAdjustmentListener(this);
s2.addAdjustmentListener(this);
s3.addAdjustmentListener(this);
add(s1,BorderLayout.EAST);
add(s2,BorderLayout.SOUTH);
add(s3,BorderLayout.WEST);
}
public void adjustmentValueChanged(AdjustmentEvent ae)
{
repaint();
}
public void paint(Graphics g)
{
cl=new Color(s1.getValue(),s2.getValue(),s3.getValue());
setBackground(cl);
}
public static void main (String args[])
{
Scrollex fe=new Scrollex("Scrollbar Demo");
fe.setSize(500,600);
fe.setVisible(true);
}
}
Output:

81
82
15.Java programs to create a Key Event.
A.
import java.awt.*;
import java.awt.event.*;
class Keyex extends Frame implements KeyListener
{
String k1;
Keyex(String tit)
{
super(tit);
k1="";
addKeyListener(this);
}
public void keyPressed(KeyEvent ke)
{
k1="You Pressed:"+ke.getKeyCode();
repaint();
}
public void keyTyped(KeyEvent ke)
{
k1="You Pressed:"+ke.getKeyChar();
repaint();
}
public void keyReleased(KeyEvent ae)
{
repaint();
}
public void paint(Graphics g)
{
Font f=new Font("Courier",Font.BOLD+Font.ITALIC,30);
g.setFont(f);
g.drawString(k1,50,100);
}
public static void main(String args[])
{
Keyex fe=new Keyex("Key Demo");
fe.setSize(500,600);
fe.setVisible(true);
}
}
Output:

83
84
MINI PROJECT

85
SOFTWARE INSTALLATION:

Double click on netbeans downloaded software. We will get the below shown
picture.

Make sure it should be completed 100%


Then we will get the below shown screenshot

86
Then click on customize button.

Then select checkbox Apache Tomcat Server and then click on ok button.

87
88
89
90
91
Procedure to install my sqlSetup file

92
93
94
95
96
97
98
99
Enter password root Retype password root

100
Gui tool installation

101
102
103
104
105
Mysql query browser

106
107
108
109
Open MYSQL administrator

110
NetBeans Project Creation:
Creating a New Project:

111
Give a name to your Project (Project name): Registration (Give your
Respective Project Name)

112
113
Remove the default code and enter the code shared with you as shown below:
index.html

114
Creating jsp pages:
Right click on Web Pages -> New -> JSP as shown below

115
enter filename as “register” and hit Finish button.
Remove the default code and enter the code shared with you given in word
document for “register.jsp” as shown below:

116
Again, create another file with name “login.jsp” as shown below:

With file name as “login.jsp” as shown below:

117
Hit Finish button and enter the code for it as shown below:

Again, with file name as “error.jsp” as shown below:

118
Hit Finish button and enter the code as shown below:

119
Creating .java files(Servlets)

Before creating Servlets, make sure to create Folder name with “Controller”
asdisplayed below:

120
Hit Finish button finally.

Now to create Servlets page:

121
File name with “register” as shown below:

122
Add checkbox and Hit Finish and enter the code by removing the default code
from it as shown below:

Again, create another file name with “login” as shown below:

123
Hit next and

124
Mark the checkbox “Add Information(web.xml)” and hit Finish button and
enter the code for it by removing the default code as shown below:

125
How to add Jars (Supported files):

------ > Download Jar files on your System using the below links:

Links to Download Jars:


1. https://www.mediafire.com/file/q0ojw169wlmfbby/mysql-connector- java-
5.1.23-bin.jar/file
2. https://www.mediafire.com/file/f3l49kv9xczcpco/cos-multipart.jar/file
3. https://www.mediafire.com/file/kynp64sxy40vlvh/gson-2.2.2.jar/file
4. https://www.mediafire.com/file/rah5o9dh7yqces6/java-mail- 1.4.4.jar/file

Copy each link and paste in browser as shown below:

126
This will redirect you to media fire website, there you will find Download
button, just hit Download button to download the respective jar files as shown
below:

The respective files will be downloaded for you as soon as you click on
Download button.
Hence, Repeat the same process for downloading the other 3 jar files.
After downloaded these 4 files, you have to upload these files to our NetBeans
Project that we have created so far as shown below:

For Uploading jars, follow the below process:


Select Libraries Folder -> Right Click -> Choose option (Add JAR/Folder)
asshown below:

127
After clicking on Add JAR/Folder option, the following dialogue box will
appear,
you have to navigate to the location where you had downloaded the jar files,
which enables us to upload jar files as displayed in the screenshot below:

128
Select all 4 necessary downloaded files and click on Open button to upload.
Hence, you will see jar files being added to Libraries Folder, as soon as you
click on Open button as displayed below:

In this way, you can add Jar Files to your NetBeans Project.

129
Source Code:
HTML Files:
index.html:
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates and open the template in
the editor.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.container
{
width: 100%; height: 50px;
background: darkgray;
}
li
{
float: left;
text-decoration: none; list-style: none;
padding: 10px 10px 10px;
}
li a{
color: white;
text-decoration: none;
}
</style>
</head>
<body>
<div class = "container">
<nav>
<ul>
<li><a href = "index.html" >HOME</a></li>

130
<li><a href = "index.html" >ABOUT</a></li>
<li><a href = "index.html" >CONTACT</a></li>
<li style="float: right;"><a href = "register.jsp" >REGISTER</a></li>
<li style="float: right;"><a href = "login.jsp" >LOGIN</a></li>
<li><a href = "index.html" >OUR SERVICES</a></li>
</ul>
</nav>
</div>
</body>
</html>

JSP Files:
register.jsp:
<%--
Document: register
Created on: 15 Nov, 2023, 6:15:40 PMAuthor: Daniel
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<style>
.registerconatiner
{
width: 100%; height: auto;
text-align: center;
}
</style>
</head>
<body>
<div class = "registerconatiner">
<form method="post" action="register">
<label>Full Name:</label><br/>
<input type="text" placeholder="ENTER YOUR NAME"
name="fname" required=""><br/>

131
<label>User Name:</label><br/>
<input type="text" placeholder="ENTER USER NAME"
name="uname" required=""><br/>
<label>Email:</label><br/>
<input type="email" placeholder="ENTER YOUR EMAIL"
name="email" required=""><br/>
<label>Password:</label><br/>
<input type="password" placeholder="ENTER YOUR
PASSWORD" name="pswd" required=""><br/>
<span style="display: none">Enter Minimum 8 characters</span>
<label>Confirm Password:</label><br/>
<input type="password" placeholder=" RECONFIRM PASSWORD"
name="cfmpswd" required=""><br/>
<span style="display: none">Both the passwords should
match</span><br/>
<input type="submit" value="Register"><br/>
</form>
</div>
</body>
</html>

login.jsp:
<%--
Document: login
Created on: 16 Nov, 2023, 1:01:26 PMAuthor: Daniel
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body align="center">
<form method="post" action="login">
<label>User Name:</label><br/>
<input type="text" placeholder="ENTER USER NAME"
name="uname" required=""><br/>
<label>Password:</label><br/>

132
<input type="password" placeholder="ENTER YOUR PASSWORD"
name="pswd" required=""><br/><br/>
<input type="submit" value="Login"><br/>
</form>
</body>
</html>

error.jsp:
<%--
Document: error
Created on: 16 Nov, 2023, 1:32:41 PMAuthor: Daniel
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1 align="center">Invalid Login Credentials, </h1>
<h1 align="center"> try again with the Correct login credentials !!</h1>
<center> <a href="login.jsp"><button>Login</button></a> </center>
</body>
</html>

SERVLETS (. Java Files): register.java:


package Controller;
import java.io.IOException; import java.io.PrintWriter; import
java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.SQLException;
import javax.servlet.RequestDispatcher; import
javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;import
javax.servlet.http.HttpServlet;

133
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "register", urlPatterns = {"/register"}) public class


register extends HttpServlet
{
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out =
response.getWriter()) {
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException { PrintWriter out =
response.getWriter();

String fullname = request.getParameter("fname"); String username =


request.getParameter("uname"); String email = request.getParameter("email");
String password = request.getParameter("pswd");
String confirmpassword = request.getParameter("cfmpswd");

try {
Connection con;
Class.forName("com.mysql.jdbc.Driver"); con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/registration",
"root", "root");
System.out.println("Connected to Database");
String sql = "INSERT INTO register (fullname, username, email,
password, confirmpassword) VALUES (?, ?, ?, ?, ?)";
PreparedStatement pst = con.prepareStatement(sql);

134
pst.setString(1, fullname); pst.setString(2, username); pst.setString(3, email);
pst.setString(4, password);
pst.setString(5, confirmpassword); pst.executeUpdate();
System.out.println("Regsitation Success");
RequestDispatcher rd = request.getRequestDispatcher("index.html");
rd.forward(request, response);
}
catch (Exception e)
{
System.out.println("Error :: " + e.getMessage());
}
}
@Override
public String getServletInfo()
{
return "Short description";
}
}

login.java:
package Controller;
import java.io.IOException; import java.io.PrintWriter; import
java.sql.Connection;
import java.sql.DriverManager; import java.sql.ResultSet;
import java.sql.PreparedStatement;
import javax.servlet.RequestDispatcher; import
javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;import
javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "login_1", urlPatterns = {"/login_1"}) public class login


extends HttpServlet
{

135
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out =
response.getWriter()) {
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {processRequest(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse


response)
throws ServletException, IOException { PrintWriter out =
response.getWriter();
String username = request.getParameter("uname"); String password =
request.getParameter("pswd");

try {
Connection con;
Class.forName("com.mysql.jdbc.Driver"); con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/registration",
"root", "root");
String sql = "SELECT * FROM register WHERE username = ? AND
password = ?";
PreparedStatement pst = con.prepareStatement(sql); pst.setString(1, username);
pst.setString(2, password);
ResultSet rs = pst.executeQuery(); if (rs.next())
{
System.out.println("Login Success"); RequestDispatcher rd =
request.getRequestDispatcher("index.html"); rd.forward(request, response);
}

136
e
l
s System.out.println("Login Failed"); RequestDispatcher rd =
e
{
request.getRequestDispatcher("error.jsp");
rd.forward(request, response);
}
}
catch (Exception e)
{
System.out.println("SQL Error: " + e.getMessage());
}
}
@Override
public String getServletInfo()
{
return "Login Servlet";
}
}

137
Database Querying:
Open MySQL Query Browser and enter the following login credentials to
logon to MySQL Query Browser:
Server Host: localhost
Username: root
Password: root

MySQL commands as follows:


1. To create Database, use the following command and hit execute button which
is visible on the right-hand side corner:
CREATE DATABASE registration;

138
After successfully executing this query, the SQL query will create Database
name with “registration” as shown below (if changes not reflected, just close
this query browser and open again)

139
2. To create “register” table in “registration” Database, use the following query:
CREATE TABLE `registration`.`Register` (
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`fullname` VARCHAR(45) NOT NULL DEFAULT '',
`username` VARCHAR(45) NOT NULL DEFAULT '',
`email` VARCHAR(45) NOT NULL DEFAULT '',
`password` VARCHAR(45) NOT NULL DEFAULT '',
`confirmpassword` VARCHAR(45) NOT NULL DEFAULT '',PRIMARY
KEY(`id`)
)ENGINE = InnoDB;

enter the query as specified above and hit execute button.

140
Upon successfully executing this query, we will see Database table created
with name “register” as shown below (if changes not reflected, just close this
query browser and open again)

141
3. To retrieve the data from the “register” table, use the below command:
SELECT * FROM `registration`.`register`;

4. To delete the rows(data) from the table “register”, use the following command:
delete FROM `registration`.`register`;
5. To start a new record with serial number “1” after performing deleteoperation,
use the following command:
alter table `registration`.`register` auto_increment = 1;

142
OUTPUTS:
1. Landing Page consists of Navigation bar containing components like HOME,
ABOUT, CONTACT, OUR SERVICES, LOGIN AND REGSITER
buttons as shown below:

2. User has to be registered at first, if he/she wanted to login as shown below:

143
3. Upon successful registration, the User can login into his/her account with
registered Username and Password as shown below:

4. If User not yet created account, trying to login and authenticate into his/her
account, the user gets an error as shown below:

144
Conclusion:
In conclusion, the Core Java project successfully leverages
the robust features of the language to deliver a scalable and
efficient solution. The use of object-oriented principles,
coupled with multi-threading and exception handling,
enhances the project's reliability and maintainability. The
modular design ensures flexibility and ease of future
expansions. Overall, the short term internship demonstrates a
proficient application of Core Java concepts, resulting in a
well-structured and high-performing software system.

145

You might also like