Computer Notes, Programming codes, Hardware and Networking Tip, Entertainment, Biography, Internet Tip, Tech News, Latest Technology, YouTube,
import java.util.Scanner; class Rectangle4{ int l, b; void getData(){ Scanner in = new Scanner(System.in); System.out.print("Enter length : "); l=in.nextInt(); System.out.print("Enter breadth : "); b=in.nextInt(); } void displayArea(){ int a; a = l*b; System.out.println("Area = "+a); } public static void main(String args[]){ Rectangle4 obj = new Rectangle4(); obj.getData(); obj.displayArea(); } }
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html" charset=UTF-8"> <title> A simple JSP program </title> </head> <body> <h1> Displaying "I love Programming 100 times !!" </h1> <table> <% for(int i=1; i<=100; i++){ %> <tr> <td> I Love Programming </td> </tr> <% } %> </table> </body> </html>
import javax.swing.*; import java.awt.*; import java.awt.event.*; class IFDemo extends JFrame { JDesktopPane dp; JInternalFrame iframe; JTextField tb; JLabel lb; IFDemo() { setSize(400,300); setDefaultLookAndFeelDecorated(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); dp=new JDesktopPane(); iframe=new JInternalFrame("Internal Frame",true,true,true,true); iframe.setSize(200,200); iframe.setLocation(50,50); dp.add(iframe); add(dp); lb=new JLabel("Email"); tb=new JTextField(10); iframe.setLayout(new FlowLayout(FlowLayout.CENTER)); iframe.add(lb); iframe.add(tb); iframe.setVisible(true); } public static void main(String args[]) { IFDemo frame=new IFDemo(); } }
import javax.swing.*; class Menu extends JFrame{ JMenuBar mb; JMenu file, edit, data, name; JMenuItem open, save, sas, cut, copy, paste; JCheckBoxMenuItem raju, indra; Menu(){ setTitle("Menu Demo"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mb=new JMenuBar(); file=new JMenu("File"); edit=new JMenu("Edit"); data=new JMenu("Data"); name=new JMenu("Name"); open=new JMenuItem("Open"); save=new JMenuItem("Save"); sas=new JMenuItem("Save As"); cut=new JMenuItem("Cut"); copy=new JMenuItem("Copy"); paste=new JMenuItem("Paste"); raju=new JCheckBoxMenuItem("Raju"); indra=new JCheckBoxMenuItem("Indra"); file.add(open); file.add(save); file.add(sas); edit.add(cut); edit.add(copy); edit.add(paste); data.add(name); name.add(raju); name.add(indra); mb.add(file); mb.add(edit); mb.add(data); setJMenuBar(mb); setSize(500, 500); setVisible(true); } public static void main(String args[]){ new Menu(); } }
public class Student{
int roll, marks;
String name;
Student(int r, String n, int m){
roll = r;
name = n;
marks = m;
}
Student(int r, int m, String n){
roll = r;
name = n;
marks = m;
}
void displaInfo(){
System.out.println(roll+"\t"+name+"\t"+marks);
}
public static void main(String args[]){
Student s1 = new Student(1, "Ram", 56);
Student s2 = new Student(2, 89, "Shyam");
System.out.println("Roll \t Name \t Marks");
s1.displaInfo();
s2.displaInfo();
}
}
import java.util.Scanner; class Employee{ int id, salary; String name; public void getData(){ Scanner in = new Scanner(System.in); System.out.println("\nEnter the Following Info of Employee"); System.out.print("Employee ID : "); id = in.nextInt(); System.out.print("Employee Name : "); name = in.next(); System.out.print("Employee Salary : "); salary = in.nextInt(); } public void displayData(){ System.out.println("\n***Employee Details***"); System.out.println("ID = "+id); System.out.println("Name = "+name); System.out.println("Salary = "+salary); } public static void main(String args[]){ Employee em1 = new Employee(); Employee em2 = new Employee(); em1.getData(); em1.displayData(); em2.getData(); em2.displayData(); } }
import java.awt.*; import javax.swing.*; import java.awt.event.*; class Calc extends JFrame implements ActionListener{ JLabel l1, l2, l3; JTextField t1, t2, t3; JButton b1, b2; Calc(){ super("Handling Action Event"); l1 = new JLabel("Enter First Number"); l2 = new JLabel("Enter Second Number"); l3 = new JLabel("Result"); t1 = new JTextField(10); t2 = new JTextField(10); t3 = new JTextField(10); b1 = new JButton("Add"); b2 = new JButton("Subtract"); setLayout(new FlowLayout(FlowLayout.LEFT,90,10)); add(l1); add(t1); add(l2); add(t2); add(l3); add(t3); add(b1); add(b2); b1.addActionListener(this); b2.addActionListener(this); setSize(300, 300); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent ae){ int x, y, z; x=Integer.parseInt(t1.getText()); y=Integer.parseInt(t2.getText()); if(ae.getSource() == b1){ z = x + y; }else{ z = x - y; } t3.setText(String.valueOf(z)); } public static void main(String args[]){ new Calc(); } }
public class TestFinally{ public static void main(String args[]){ try{ int x = 20/0; System.out.println("Quoitent = "+x); } catch(ArithmeticException e){ System.out.println("e.getMessage"); } finally{ System.out.println("Finally block is always executed"); } System.out.println("Rest of the Codes .... "); } }
import javax.swing.*; class MenuDemo extends JFrame{ JMenuBar mb; JMenu file, edit, format; JMenuItem open, save, save_as, exit, undo, redo; MenuDemo(){ setTitle("Menu Bar"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mb=new JMenuBar(); file=new JMenu("File"); edit=new JMenu("Edit"); format=new JMenu("Format"); open=new JMenuItem("Open"); save=new JMenuItem("Save"); save_as=new JMenuItem("Save As"); exit=new JMenuItem("Exit"); undo=new JMenuItem("Undo"); redo=new JMenuItem("Redo"); file.add(open); file.add(save); file.add(save_as); file.add(exit); edit.add(undo); edit.add(redo); mb.add(file); mb.add(edit); mb.add(format); setJMenuBar(mb); setSize(300, 200); setVisible(true); } public static void main(String args[]){ new MenuDemo(); } }