NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

(program-1):


import java.io.*;
import java.util.Scanner;
public class Lab1
{
public static void main(String args[])
{
String str,substr;
int idx1,idx2;
Scanner in=new Scanner(System.in);
System.out.println("Enter the String:");
str=in.next();
System.out.println("Enter the index1:");
idx1=in.nextInt();
System.out.println("Enter the index2:");
idx2=in.nextInt();
substr=str.substring(idx1,idx2);
System.out.println("The Substring is:"+substr);
}
}

-------------------------------------------------------------------------------------------------------------------------

(program-2):(d)

import java.util.*;
class Student
{
String name;
int rollno;
float mark1,mark2;
void getdata()
{
Scanner in=new Scanner(System.in);
System.out.println("Enter the Name:");
name=in.next();
System.out.println("Enter the Rollno:");
rollno=in.nextInt();
System.out.println("Enter the Mark1:");
mark1=in.nextFloat();
System.out.println("Enter the Mark2:");
mark2=in.nextFloat();
}
void display()
{
System.out.println("Name of Student:"+name);
System.out.println("Rollno of Student:"+rollno);
System.out.println("Marks of Subject1:"+mark1);
System.out.println("Marks of Subject2:"+mark2);
}
}
interface Exam
{
void percentage();
}

class Result extends Student implements Exam
{
float tot;
public void percentage()
{
tot=mark1+mark2;
float percent=(tot/200)*100;
System.out.println("Total:"+tot);
System.out.println("Percentage:"+percent+"%");

}
}
class Lab2
{
public static void main(String args[])
{
Result R=new Result();
R.getdata();
R.display();
R.percentage();
}
}

-------------------------------------------------------------------------------------------------------------------------

(program-3):

import java.io.*;
import java.util.Scanner;
class P3
{
public static void main(String args[])
{
int payamt;
Scanner in =new Scanner(System.in);
System.out.println("nn pay out of bound exception");
System.out.println("*******");
System.out.println("n Enter a basic pay amount");
payamt=in.nextInt();
try
{
if(payamt>1000)
throw new payoutofBoundException("Basic pay is out of bound");
else
System.out.println("n given basic pay is:"+payamt);
}
catch(Exception e)
{
System.out.println("caught:"+e);
}
}
}
class payoutofBoundException extends IOException
{
payoutofBoundException(String message)
{
System.out.println(message);
}
}


-------------------------------------------------------------------------------------------------------------------------

(program-4):

import java.io.*;
class Table5 extends Thread
{
public void run()
{
for(int i=1;i<=5;i++)
{
System.out.println(i+"*5="+(i*5));
if(i==3)stop();
}
System.out.println("EXIT FIVE");
}
}
class Table7 extends Thread
{
public void run()
{
for(int j=1;j<=5;j++)
{
System.out.println(j+"*7="+(j*7));
try
{
sleep(1000);
}
catch(Exception e){}
}
System.out.println("EXIT SEVEN");
}
}
class Table13 extends Thread
{
public void run()
{
for(int k=1;k<=5;k++)
{
System.out.println(k+"*13="+(k*13));
}
System.out.println("EXIT THIRTEEN");
}
}
class lab4
{
public static void main(String args[])
{
Table5 t5=new Table5();
Table7 t7=new Table7();
Table13 t13=new Table13();
t5.setPriority(1);
t7.setPriority(5);
t13.setPriority(10);
System.out.println("MULTI THREADED USING PRIORITY");
t5.start();
t7.start();
t13.start();
}
}

-------------------------------------------------------------------------------------------------------------------------

(program-5):

import java.awt.*;
import java.applet.*;
/*
<applet code="shapes" width=400 height=400>
</applet>
*/
public class shapes extends Applet
{
public void paint(Graphics g)
{
g.drawLine(10,10,50,50);
g.drawRect(10,60,40,30);
g.fillRect(60,10,30,80);
g.drawRoundRect(10,100,80,50,10,10);
g.fillRoundRect(20,110,60,30,5,5);
g.setColor(Color.green);
g.drawOval(100,10,200,150);
g.setColor(Color.red);
g.fillOval(115,25,100,100);
g.drawString("Shapes Demo",120,200);
}
}

-------------------------------------------------------------------------------------------------------------------------


(program-6):

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Lab06 extends Frame implements ActionListener
{
TextField tname,tstreet,tcity,tpin;
Label lname,lstreet,lcity,lpin;
Button b1;
public Lab06()
{
setBackground(Color.gray);
setForeground(Color.red);
FlowLayout f=new FlowLayout();
setLayout(f);
lname=new Label("NAME");
lstreet=new Label("STREET");
lcity=new Label("CITY");
lpin=new Label("PINCODE");
tname=new TextField(35);
tstreet=new TextField(35);
tcity=new TextField(35);
tpin=new TextField(35);
b1=new Button("click me");
add(lname);
add(tname);
add(lstreet);
add(tstreet);
add(lcity);
add(tcity);
add(lpin);
add(tpin);

add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
tname.setText("SURYA");
tstreet.setText("22,RAMNAGAR");
tcity.setText("COIMBATORE");
tpin.setText("641009");
}
}
public boolean handleEvent(Event e)
{
if(e.id==Event.WINDOW_DESTROY)
System.exit(0);
return(super.handleEvent(e));
}
public static void main(String args[])
{
Lab06 a=new Lab06();
a.resize(380,300);
a.show();
}
}

-------------------------------------------------------------------------------------------------------------------------

7))

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Prac7 extends Applet implements
ActionListener
{
List list1;
TextField Text1;
Button butt;
public void init()
{
Text1=new TextField(40);
add(Text1);
list1=new List(0,true);
list1.add("C");
list1.add("COBOL");
list1.add("C++");
list1.add("JAVA");
list1.add("Oracle");
list1.add("Visual Basic");
list1.add("Visual C++");
list1.add("Adobe");
add(list1);
butt=new Button("Show Selection");
butt.addActionListener(this);
add(butt);
}
String Selections[];
public void actionPerformed(ActionEvent e)
{
String outstring=new String("youselected");
if(e.getSource()==butt)
{
Text1.setText("");
Selections=list1.getSelectedItems();
for(int loopIndex=0;loopIndex<Selections.length;loopIndex++)
{
outstring+=""+Selections[loopIndex];
}
Text1.setText(outstring);
}
}
}
/*<applet code=Prac7.class width=400 height=400>
</applet>*/


-------------------------------------------------------------------------------------------------------------------------



8))

import java.awt.event.*;
import java.awt.*;
public class Prac08 extends Frame implements ActionListener
{
TextField t1,t2,t3,t4;
TextArea txt;
Label l1,l2,l3,l4;
Button b1;
public Prac08()
{
FlowLayout F=new FlowLayout();
setLayout(F);
l1=new Label("NAME:");
add(l1);
t1=new TextField(10);
add(t1);
l2=new Label("AGE:");
add(l2);
t2=new TextField(2);
add(t2);
l3=new Label("QUALIFICATION:");
add(l3);
t3=new TextField(10);
add(t3);
l4=new Label("ADDRESS:");
add(l4);
txt=new TextArea(" ",10,20);
add(txt);
b1=new Button("clear");
b1.setBackground(Color.red);
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
try
{
if(e.getSource()==b1)
{
t1.setText(" ");
t2.setText(" ");
t3.setText(" ");
txt.setText(" ");
}
}
catch(Exception ex){}
}
public boolean handleEvent(Event e)
{
if(e.id==Event.WINDOW_DESTROY)
System.exit(0);
return(super.handleEvent(e));
}
public static void main(String args[])
{
Prac08 a=new Prac08();
a.setVisible(true);
a.setSize(300,200);
}
}


-------------------------------------------------------------------------------------------------------------------------


9))

import java.awt.*;
public class MenuDemo extends Frame
{
MenuBar my=new MenuBar();
public MenuDemo()
{
setTitle("MenuBar");
FlowLayout F=new FlowLayout();
setLayout(F);
setMenuBar(my);
Menu fm=new Menu("File");
my.add(fm);
fm.add(new MenuItem("new"));
fm.add(new MenuItem("open"));
fm.add(new MenuItem("save"));
fm.add(new MenuItem("save as"));
fm.add(new MenuItem("Exit"));
Menu em=new Menu("Edit");
my.add(em);
em.add(new MenuItem("undo"));
em.add(new MenuItem("redo"));
em.add(new MenuItem("cut"));
em.add(new MenuItem("copy"));
em.add(new MenuItem("paste"));
em.add(new MenuItem("delete"));
em.add(new MenuItem("select"));
em.add(new MenuItem("select all"));
}
public boolean handleEvent(Event e)
{
if(e.id==Event.WINDOW_DESTROY)
System.exit(0);
return(super.handleEvent(e));
}
public static void main(String args[])
{
MenuDemo m=new MenuDemo();
m.resize(500,500);
}
}


-------------------------------------------------------------------------------------------------------------------------



(program-10):

import java.awt.*;
import java.awt.event.*;
public class MouseExample extends Frame implements MouseListener
{
int x=0,y=0;
String strEvent="";
MouseExample(String title)
{
super(title);
addWindowListener(new MyWindowAdapter(this));
addMouseListener(this);
setSize(300,300);
setVisible(true);
}
public void mouseClicked(MouseEvent e)
{
strEvent="MouseClicked";
x=e.getX();
y=e.getY();
repaint();
}
public void mousePressed(MouseEvent e)
{
strEvent="MousePressed";
x=e.getX();
y=e.getY();
repaint();
}
public void mouseReleased(MouseEvent e)
{
strEvent="MouseReleased";
x=e.getX();
y=e.getY();
repaint();
}
public void mouseEntered(MouseEvent e)
{
strEvent="MouseEntered";
x=e.getX();
y=e.getY();
repaint();
}
public void mouseExited(MouseEvent e)
{
strEvent="MouseExited";
x=e.getX();
y=e.getY();
repaint();
}
public void paint(Graphics g)
{
g.drawString(strEvent+" at"+x+","+y,50,50);
}
public static void main(String args[])
{
MouseExample myWindow=new MouseExample("Window With Mouse Events Example");
}
}
class MyWindowAdapter extends WindowAdapter
{
MouseExample myWindow=null;
MyWindowAdapter(MouseExample myWindow)
{
this.myWindow=myWindow;
}
public void windowClosing(WindowEvent we)
{
myWindow.setVisible(false);
}
}


-------------------------------------------------------------------------------------------------------------------------



(program-11):

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class DrawShapes extends Applet implements MouseListener
{
int x,y,ch;
public void init()
{
addMouseListener(this);
ch=1;
}
public void paint(Graphics g)
{
switch(ch)
{
case 1:
g.drawOval(x,y,50,50);
break;
case 2:
g.drawRect(x,y,60,50);
break;
case 3:
g.drawOval(x,y,140,100);
}
ch++;
if(ch==4)
{
ch=1;
}
showStatus(x+","+y);
}
public void mouseClicked(MouseEvent me)
{
x=me.getX();
y=me.getY();
repaint();
}
public void mouseEntered(MouseEvent me)
{
x=me.getX();
y=me.getY();
repaint();
}
public void mouseExited(MouseEvent me){}
public void mousePressed(MouseEvent me){}
public void mouseReleased(MouseEvent me){}}
/*<applet code="Drawshapes.class" width=350 height=350>
</applet>*/



-------------------------------------------------------------------------------------------------------------------------



(program-12):

import java.io.*;
import java.util.Scanner;
class AppFile
{
public static void main(String args[])
{
try
{
Scanner sc=new Scanner(System.in);
String s;
RandomAccessFile f=new RandomAccessFile("new.txt","rw");
f.seek(f.length());
System.out.println("Enter a string to append into the file");
s=sc.next();
f.writeBytes(s);
f.close();
}
catch(IOException ioe)
{
System.out.println(ioe);
}
}
}


-------------------------------------------------------------------------------------------------------------------------
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.