0% found this document useful (0 votes)
22 views18 pages

Java User Registration and Login System

The document discusses a Java program to register and login users with validation of inputs like password and confirm password matching and unique emails. It also includes a question on creating two classes - Friend and Buddy where Buddy inherits from Friend and adds more data members and methods to display user details.

Uploaded by

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

Java User Registration and Login System

The document discusses a Java program to register and login users with validation of inputs like password and confirm password matching and unique emails. It also includes a question on creating two classes - Friend and Buddy where Buddy inherits from Friend and adds more data members and methods to display user details.

Uploaded by

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

Jethva Devang SUB : JAVA Programming

Q.1 : Write a code in java for input First name,Last Name, Gender, Email, Password,Confirm Password,
Country, State, City. Also provide following facilities given in Following menu.

Press [1] Register

Press [2] Login

-For Register following criteria should beconsidered.

- Password and Confirm Password must be the same.

- Email id must be unique for each user.

Ans:

import [Link].*; class

register

String Name,Gender,Email,Password,Confirm_Password,Country,State,City; public

register()

Name="";

Gender="";

Email="";

Password="";

Confirm_Password="";

Country="";

State="";

City="";

1|Page
Kakadiya Maulik V. SUB : JAVA Programming

public register(String Name1,String Gender1,String Email1,String Password1,String


Confirm_Password1,String country1,String State1,String City1)

Name=Name1;

Gender=Gender1;

Email=email1;

Password=Password1;

Confirm_Password=Confirm_Password1;

Country=Country1;

State=State1;

City=City1;

public void dis()

[Link](Name+"\t",Gender+"\t",Email+"\t",Password+"\t",Confirm_Passwor
d+"\t",Country+"\t",State+"\t",City);

};

class login

public static void main(String o[])throws IOException

2|Page
Kakadiya Maulik V. SUB : JAVA Programming

register[] b=false;

int ch=0,f=0;

int len; char[] temp=new

char[15];

BufferedReader j=new BufferedReader(new InputStreamReader([Link]));

String Name,Gender,Email,Password,Confirm_Password,Country,State,City;

do

[Link]("[Link]");

[Link]("[Link]");

[Link]("[Link]");

[Link]("\nEnter Your Choice");

ch=[Link]([Link]());

switch(ch)

case 1:

[Link]("Enter Mail");

Email=[Link]();

[Link]("Enter Name");

3|Page
Kakadiya Maulik V. SUB : JAVA Programming

Name=[Link]();

do

b=false;

[Link]("Enter Gender (M/F)"); Gender=[Link]();

if

[Link]("m") || [Link]("M") || [Link]("f") || [Link]("F")

b=true;

while(b!=true);

[Link]("Enter Password");

pass=[Link]();

do

b=false;

[Link]("Enter Confirem Password");

cpass=[Link]();

if

4|Page
Kakadiya Maulik V. SUB : JAVA Programming

[Link](pass)!=true

[Link]("Invalid Confirm Password");


b=true;

while(b==true);

[Link]("Enter Counter");

cnt=[Link]();

[Link]("Enter City");

City=[Link]();

[Link]("Enter State");

State=[Link]();

obj[f]=new
register(Name,Gender,Email,Password,Confirm_Password,Country,State,City);

f++;

break;

case 2:

[Link]("Enter Resister id");

5|Page
Kakadiya Maulik V. SUB : JAVA Programming

Email=[Link]();

b=false;

for(int k=0;k<f;k++)

if([Link](obj[k].Email)==true)

[Link]("Enter Password");
pass=[Link]();

if([Link](obj[k].pass)==true)

[Link]("Login
Succesfully");

[Link]("\n\nName\Gender\nEmail\nPassword\
nConfirm_Password,Country ,State,City");

obj[k].dis();

b=true;

while(b==false)

case 0:

[Link](0);

6|Page
Kakadiya Maulik V. SUB : JAVA Programming

while(ch!=3);

Q.7 : Create a two class one is Friend and another is Buddy, Friend class has data member like
name and email id, and Buddy class inherit the properties of Friend class and it has data member
like dob, mobile no and address and do the following operation.

a. Create three constructor for base and derived class.

b. Insert data throught derived class parameterized constructor.

c. Illustrate the use of this reference and super.

d. Display all the information through parent class reference variable.

Ans :

import [Link].*;

import [Link].*;

class friend

String name,email; public

friend()

7|Page
Kakadiya Maulik V. SUB : JAVA Programming

name=null;

email=null;

public friend(String fname,String femail)

name=fname;

email=femail;

public void dis_friend()

[Link]("\n\nname ="+name+"\n\nemail ="+email);

};

class Buddy extends friend

String dob,add,mno; public

buddy()

dob=null;

add=null; mno=null;

public buddy(String bdob,String bmno,String fname,String femail)

8|Page
Kakadiya Maulik V. SUB : JAVA Programming

super(fname,femail);

dob=bdob;

add=badd; mno=bmno;

public void dis_buddy()

super.dis_friend();

[Link]("\ndob ="+dob+"\n\naddress ="+add+"\nmno


="+mno+"\n\n\n");

};

class mainbuddy

public static void main(String o[])

buddy obj1=new buddy();

buddy obj2=new buddy ("04-06-


1999","surat","+911111111111","om","[Link]");

obj2.dis_buddy();

9|Page
Kakadiya Maulik V. SUB : JAVA Programming

24. Write a java applet program to draw Micky mouse.

import [Link].*; import [Link].*; import [Link].*;

import [Link].*; public class Mickymouse extends Applet

implements Runnable

Thread t; int a=1,h=1;

public void init()

setBackground([Link]);

public void start()

10 | P a g e
Kakadiya Maulik V. SUB : JAVA Programming

Thread t=new Thread(this);

[Link]();

public void run()

try {

while(true)

repaint();

[Link](100);

catch(Exception e)

public void paint(Graphics g)

[Link]([Link]);

11 | P a g e
Kakadiya Maulik V. SUB : JAVA Programming

[Link](380,95,150,150);

[Link](720,95,150,150);

[Link]([Link]);

[Link](440,159,80,80);

[Link](733,159,80,80);

[Link]([Link]);

[Link](400,160,450,450);

[Link]([Link]);

[Link](490,255,80,130);

[Link](665,255,80,130);

[Link]([Link]);

[Link](512,322,40,60);

[Link](688,322,40,60);

[Link](595,400,55,55);

[Link](550,430,140,120,0,-180);

try{

if(h==1)

[Link](500);

[Link]([Link]);

[Link](550,430,140,120,0,-180);

[Link](512,322,40,60);

[Link](688,322,40,60);

12 | P a g e
Kakadiya Maulik V. SUB : JAVA Programming

h--;

if(h==0)

[Link](200);

[Link]([Link]);

[Link](550,430,140,120,0,-180);

[Link](512,322,40,60);

[Link](688,322,40,60);

h++;

catch(Exception e)

try

if(a==1)

[Link](200);

[Link]([Link]);

13 | P a g e
Kakadiya Maulik V. SUB : JAVA Programming

[Link](550,430,140,120,0,-180);

a--;

if(a==0)

[Link](500);

[Link]([Link]);

[Link](550,430,140,120,0,180);

a++;

catch(Exception e)

<html>

<body>

<applet code="[Link]" width="600" height="550">

</applet>

</body>

</html>

14 | P a g e
Kakadiya Maulik V. SUB : JAVA Programming

[Link] a java applet program to draw digital wall clock which display real time.

import [Link]; import [Link];

import [Link].*; import [Link].*; import [Link].*;

import [Link].*; import [Link].*; public class

Digitalclock extends Applet implements Runnable

Thread t; int

h=0,m=0,s=0;

String timestring="";

public void init()

15 | P a g e
Kakadiya Maulik V. SUB : JAVA Programming

setBackground([Link]);

public void start()

t=new Thread(this);

[Link]();

public void run()

try

while(true)

Calendar cal=[Link]();

h=[Link](Calendar.HOUR_OF_DAY);

if(h>12)

h=h-12;

m=[Link]([Link]);

s=[Link]([Link]);

SimpleDateFormat sobj=new

SimpleDateFormat("hh:mm:ss"); Date dobj=[Link]();

timestring=[Link](dobj);

16 | P a g e
Kakadiya Maulik V. SUB : JAVA Programming

repaint();

[Link](1000);

catch(Exception e)

17 | P a g e
Kakadiya Maulik V. SUB : JAVA Programming

[Link] java applet pogram to draw image.

import [Link].*; import

[Link].*; public class imagerx

extends Applet

Image picture;

public void init()

picture = getImage(getDocumentBase(),"[Link]");

public void paint(Graphics g)

[Link](picture, 50,50,this);

18 | P a g e

Common questions

Powered by AI

Key criteria for a user registration system in Java include unique email validation for each user and ensuring that the password and confirm password fields match. These criteria are important to prevent duplicate accounts and ensure the integrity of the registration process .

Challenges include managing each required field accurately, handling IOException gracefully, ensuring thread safety, and strict validation rules to manage gender, password confirmation, and unique email entry. Effective exception handling and clear user prompts are vital for robust validation .

Best practices include using the 'paint' method for redrawing components, implementing 'Runnable' for multithreading to update graphics regularly, and managing colors, shapes, and sleep times effectively to create smooth animations. These techniques are demonstrated in creating the Mickey Mouse applet .

Overriding methods allow derived classes to provide specific implementations of methods declared in a parent class, affecting the derived class's behavior. This facilitates polymorphism, allowing a superclass reference to call subclass implementations, as seen with 'Buddy' class methods overriding those of 'Friend' .

Security considerations for password handling include ensuring passwords are not logged or stored improperly, enforcing strong password criteria, and matching password inputs for confirmation during registration. Java offers classes like 'SecureRandom' and 'MessageDigest' for secure password handling .

Displaying an image in a Java applet involves using the 'getImage' method to retrieve the image URL and the 'paint' method to display it on the applet. Limitations include dependency on the browser's Java support and the handling of image loading asynchronously, which may result in delayed display .

Recursion can be introduced in a thread by ensuring thread safety and preventing infinite recursive calls, which can be managed using termination conditions or a counter. However, in general, recursive methods are discouraged in threads due to stack overflow risk, and iterations are preferred .

'This' is used to reference the current class instance variables, making constructor parameters clearly disambiguated from fields. 'Super' calls the parent class's constructor, which is essential in initializing inherited fields properly, as seen in the 'Buddy' class's use of 'super' to initialize 'Friend' class fields .

The 'Buddy' class inherits properties from the 'Friend' class using 'extends' which is a fundamental concept of inheritance in Java. This allows 'Buddy' to access the data members and methods of 'Friend', while also introducing its own data members like dob, mobile no, and address .

The digital clock applet ensures real-time updates by using a separate thread to continuously retrieve and format the current time. The use of 'Calendar' to get the current time, and the periodic 'repaint()' calls ensure the display is updated every second .

You might also like