Author: BIM Notes
Advance java old paper solution || 2022
Group B Q.no 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
import java.awt.event.*; import java.awt.*; import javax.swing.*; public class Calculator extends JFrame implements ActionListener { JButton b10,b11,b12,b13,b14,b15; JButton b[]=new JButton[10]; int i,r,n1,n2; JTextField res; char op; public Calculator() { super("Calulator"); setLayout(new BorderLayout()); JPanel p=new JPanel(); p.setLayout(new GridLayout(4,4)); for(int i=0;i<=9;i++) { b[i]=new JButton(i+""); p.add(b[i]); b[i].addActionListener(this); } b10=new JButton("+"); p.add(b10); b10.addActionListener(this); b11=new JButton("-"); p.add(b11); b11.addActionListener(this); b12=new JButton("*"); p.add(b12); b12.addActionListener(this); b13=new JButton("/"); p.add(b13); b13.addActionListener(this); b14=new JButton("="); p.add(b14); b14.addActionListener(this); b15=new JButton("C"); p.add(b15); b15.addActionListener(this); res=new JTextField(10); add(p,BorderLayout.CENTER); add(res,BorderLayout.NORTH); setVisible(true); setSize(200,200); } public void actionPerformed(ActionEvent ae) { JButton pb=(JButton)ae.getSource(); if(pb==b15) { r=n1=n2=0; res.setText(""); } else if(pb==b14) { n2=Integer.parseInt(res.getText()); eval(); res.setText(""+r); } else { boolean opf=false; if(pb==b10) { op='+'; opf=true; } if(pb==b11) { op='-';opf=true;} if(pb==b12) { op='*';opf=true;} if(pb==b13) { op='/';opf=true;} if(opf==false) { for(i=0;i<10;i++) { if(pb==b[i]) { String t=res.getText(); t+=i; res.setText(t); } } } else { n1=Integer.parseInt(res.getText()); res.setText(""); } } } int eval() { switch(op) { case '+': r=n1+n2; break; case '-': r=n1-n2; break; case '*': r=n1*n2; break; case '/': r=n1/n2; break; } return 0; } public static void main(String arg[]) { new Calculator(); } } |
Q.no 4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import java.sql.*; class Update { public static void main(String args[]) { try { Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/College_db","root",""); Statement stmt=con.createStatement(); String query="update employees set salary=20000 where employee_id=6"; int i=stmt.executeUpdate(query); System.out.println(i+" records updated"); con.close(); } catch(Exception e) { System.out.println(e); } } } |
Q.no 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class OddEven extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String n = request.getParameter("userName"); int num = Integer.parseInt(n); if (num % 2 == 0) { out.print("Even Number"); } else { out.print("Odd Number"); } out.close(); } } |
Q.no 6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class SmallLarge extends JFrame implements ActionListener { JLabel l1,l2,l3; JTextField t1,t2; JButton b1,b2; public SmallLarge() { setLayout(new FlowLayout()); l1=new JLabel("Enter First Number"); l2=new JLabel("Enter Second Number"); l3=new JLabel("Result"); t1=new JTextField(10); t2=new JTextField(10); b1=new JButton("Small"); b2=new JButton("Large"); add(l1); add(t1); add(l2); add(t2); add(b1); add(b2); add(l3); b1.addActionListener(this); b2.addActionListener(this); } public void actionPerformed(ActionEvent ae) { int a=Integer.parseInt(t1.getText()); int b=Integer.parseInt(t2.getText()); if(ae.getSource()==b1) { if(a<b) { l3.setText("Smaller Number is "+a); } else { l3.setText("Smaller Number is "+b); } } else { if(a>b) { l3.setText("Larger Number is "+a); } else { l3.setText("Larger Number is "+b); } } } public static void main(String args[]) { SmallLarge sl=new SmallLarge(); sl.setSize(300,300); sl.setVisible(true); sl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } |
Q.no 7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class KeyEventDemo extends JFrame implements KeyListener { JLabel l; int x = 0, y = 0; public KeyEventDemo() { setTitle("KeyEventDemo"); setSize(300, 300); setLayout(new FlowLayout()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); l = new JLabel("Press any key on the keyboard"); add(l); addKeyListener(this); setVisible(true); } public void keyPressed(KeyEvent ke) { l.setText("You pressed: " + ke.getKeyChar()); if (ke.getKeyCode() == KeyEvent.VK_RIGHT) { x += 10; l.setLocation(x, y); } else if (ke.getKeyCode() == KeyEvent.VK_LEFT) { x -= 10; l.setLocation(x, y); } else if (ke.getKeyCode() == KeyEvent.VK_UP) { y -= 10; l.setLocation(x, y); } else if (ke.getKeyCode() == KeyEvent.VK_DOWN) { y += 10; l.setLocation(x, y); } } public void keyReleased(KeyEvent ke) { l.setText("You released: " + ke.getKeyChar()); } public void keyTyped(KeyEvent ke) { l.setText("You typed: " + ke.getKeyChar()); } public static void main(String[] args) { new KeyEventDemo(); } } |
Q.no 8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
*/ import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; public class SimpleInterest extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String title = "Simple Interest"; String docType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " + "Transitional//EN\">\n"; out.println(docType + "<HTML>\n" + "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" + "<BODY BGCOLOR=\"#FDF5E6\">\n" + "<H1 ALIGN=\"CENTER\">" + title + "</H1>\n" + "<UL>\n" + " <LI><B>Principal</B>: " + request.getParameter("principal") + "\n" + " <LI><B>Time</B>: " + request.getParameter("time") + "\n" + " <LI><B>Rate</B>: " + request.getParameter("rate") + "\n" + "</UL>\n" + "</BODY></HTML>"); } } |
Continue Reading
Java Old Paper solution || 2019
Group B
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
*/ import java.awt.*; import java.awt.event.*; class ButtonDemo extends Frame implements ActionListener { Button b1,b2,b3; Label l; ButtonDemo() { setLayout(new FlowLayout()); b1=new Button("RED"); b2=new Button("BLUE"); b3=new Button("GREEN"); l=new Label(""); add(b1); add(b2); add(b3); add(l); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); } public void actionPerformed(ActionEvent e) { if(e.getSource()==b1) { l.setText("RED"); } else if(e.getSource()==b2) { l.setText("BLUE"); } else if(e.getSource()==b3) { l.setText("GREEN"); } } public static void main(String args[]) { ButtonDemo b=new ButtonDemo(); b.setSize(400,400); b.setVisible(true); } } |
Q.no 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import java.sql.*; public class Marvel { public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Marvel", "root", "root"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select * from Movie where genre='action'"); while (rs.next()) System.out.println(rs.getInt(1) + " " + rs.getString(2) + " " + rs.getString(3)); con.close(); } catch (Exception e) { System.out.println(e); } } } </code> |
Q.no 6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
import java.awt.*; import java.awt.event.*; import java.applet.*; /* <applet code="MouseListenerDemo" width=300 height=100> </applet> */ public class MouseListenerDemo extends Applet implements MouseListener { String msg=""; int mouseX=0,mouseY=0; public void init() { addMouseListener(this); } public void mouseClicked(MouseEvent me) { mouseX=0; mouseY=10; msg="Mouse Clicked"; repaint(); } public void mouseEntered(MouseEvent me) { mouseX=0; mouseY=10; msg="Mouse Entered"; repaint(); } public void mouseExited(MouseEvent me) { mouseX=0; mouseY=10; msg="Mouse Exited"; repaint(); } public void mousePressed(MouseEvent me) { mouseX=me.getX(); mouseY=me.getY(); msg="Down"; repaint(); } public void mouseReleased(MouseEvent me) { mouseX=me.getX(); mouseY=me.getY(); msg="Up"; repaint(); } public void paint(Graphics g) { g.drawString(msg,mouseX,mouseY); } } |
How is servlet depoyed ? Explain. Servlets are usually deployed in web containers, such as Apache Tomcat. The web container provides an environment for servlets to run in, managing threading, connection pooling, security, and other services. When a web server receives a request for a […]
Continue ReadingManagement Information System
“After completing the 7th semester, Interested in pursuing an internship, but unsure about which field to choose. Don’t worry, we have courses available that can enhance your skills and help you find the right internship.”SEO Course :- Rs. 1999 onlyQA Course :- Rs. 3999 Only Question paper Syllabus Pre- board Paper unit 1 unit 2 […]
Continue ReadingAi Refernce Notes
Question paper Solution Syllabus Pre- board Paper SYLLABUS YEAR2014-2025 Syllabus Here Course Objectives This module aims to provide the students with the basic foundation on concepts of searching and knowledge epresentation in AI systems. The key objective is to make students more pragmatic in knowledge of AI by giving its applications like designing and training […]
Continue Readingorganizational behavior
Question paper Syllabus Pre- board Paper
Continue Reading