Tag: java 2 solution
java solution 2016 Batch pre board Answers
2016 Batch Asian 2.Write a program passing parameter in applet.Write complete HTML file to include applet.
1 2 3 4 5 6 7 8 |
import java.applet.Applet; import java.awt.Graphics; public class UseParam extends Applet{ public void paint(Graphics g){ String str=getParameter("msg"); g.drawString(str,50, 50); } } |
3.Explain two key swing features. Swing offers two key features: Swing components are lightweight and don’t rely on peers. Swing supports a pluggable look and feel. The three PLAFs available to all users are Metal (default), Windows, and Motif. 4.Write a swing program […]
Continue ReadingJava 2 old Papers Solution 2018 || BIM STUDY NOTES
year 2018 Create a HTML document that contains header information of a page and include this HTML as a header file in header.html
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Insert title here</title> </head> <body> <center> <h1>Orchid International College</h1> <h3>Gaushala, Kathmandu</h3> </center> </body> </html> |
include.jsp <html> <body> <%@include file = “header.html” %> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p></body> </html> 3. Create […]
Continue ReadingJava 2 old Papers Solution 2017 || BIM STUDY NOTES
Year 2017 Group B 2.Write a program to display records from the table “employee” that contains (id, name, post and salary) inside the database “testdb”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import java.sql.*; public class Ques2_2017 { public static void main(String[] args) { String url = "jdbc:mysql://localhost:3306/testdb"; String uname = "root"; String pwd = ""; try { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection(url, uname, pwd); String sql = "select * from employee"; Statement st = con.createStatement(); ResultSet rs = st.executeQuery(sql); while(rs.next()) { System.out.println(rs.getString("id")); System.out.println(rs.getString("name")); System.out.println(rs.getString("post")); System.out.println(rs.getString("salary")); } }catch(Exception ex) { System.out.println(ex); } } } |
Q.no 3 Create jsp page to display all odd numbers from 10 to 50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <title>Printing odd numbers from 10 to 50</title> </head> <body> <% out.print("<b> odd numbers from 10 to 50</><br>"); for( int i=10;i<=50;i++) { if(i%2!==0){ out.print("<br><b>"+i+"</b>"); } } %> </body> </html> |
Q.no 5 Write a servlet to find the reverse of a string.
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 |
import java.applet.*; import java.awt.event.*; import java.awt.*; public class T2017_5 extends Applet implements ActionListener{ Panel p1,p2; Label l1,l2,l3; TextField t1,t2,t3; Button b1,b2; public void init(){ p1=new Panel(); p2=new Panel(); p1.setLayout(new GridLayout(3,2)); p2.setLayout(new FlowLayout()); l1=new Label("Number 1"); l2=new Label("Number 2"); l3=new Label("Result"); t1=new TextField(); t2=new TextField(); t3=new TextField(); t3.setEditable(false); p1.add(l1); p1.add(t1); p1.add(l2); p1.add(t2); p1.add(l3); p1.add(t3); add(p1); add(p2); b1=new Button("+"); b2=new Button("-"); p2.add(b1); p2.add(b2); } public void start(){ b1.addActionListener(this); b2.addActionListener(this); } public void actionPerformed(ActionEvent e){ int a=Integer.parseInt(t1.getText()); int b=Integer.parseInt(t2.getText()); if(e.getSource()==b1){ int c=a+b; t3.setText(" "+c); } else if(e.getSource()==b2){ int c=a-b; t3.setText(" "+c); } } } |
Group […]
Continue ReadingJava old Papers Solution 2016 || BIM STUDY NOTES
Year 2016 Group B Q.no 2 Write a swing program to add two numbers given as input by user.
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 |
import java.awt.*; import javax.swing.*; import javax.swing.event.*; import java.awt.event.*; public class T2016_2 extends JFrame implements ActionListener{ JTextField t1,t2; JLabel sum; JButton b; public T2016_2(){ t1=new JTextField(); t2=new JTextField(); sum=new JLabel(""); b=new JButton("Add"); setLayout(new GridLayout(4,1)); add(t1); add(t2); add(b); add(sum); setSize(200,400); setVisible(true); b.addActionListener(this); } public void actionPerformed(ActionEvent e){ int n1=Integer.parseInt(t1.getText()); int n2=Integer.parseInt(t2.getText()); int s=n1+n2; sum.setText("Sum is: "+s); } public static void main(String[] args) { new T2016_2(); } } |
Q.no 3 Write an applet to check whether given word by user is of length 5 or not.
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 |
import java.applet.*; import java.awt.*; import java.awt.event.*; public class T2016_3 extends Applet implements KeyListener{ TextField t1; Label lab; public void init(){ t1=new TextField(); add(t1); lab=new Label(); add(lab); setSize(300,300); setLayout(new GridLayout(2,1)); } public void start(){ t1.addKeyListener(this); } public void keyTyped(KeyEvent e){} public void keyPressed(KeyEvent e){} public void keyReleased(KeyEvent e){ String a=t1.getText(); if(a.length()==5){ lab.setText(a+" is of length 5"); } else{ lab.setText(a+" is not of length 5"); } } } |
4. Write a JSP program to display ” Apache Tomcat” eight times.
1 2 3 4 5 6 7 8 9 10 11 |
<html> <head> </head> <body> <% for(int i = 1; i <= 8; i++) { out.println("Apache Tomcat <br />"); } %> </body> </html> |
5. Write a program […]
Continue Reading