0% found this document useful (0 votes)
13 views13 pages

Java PREXM

Java practice qb

Uploaded by

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

Java PREXM

Java practice qb

Uploaded by

Reyan Dabre
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 13
Practical Exam Questions ; _- ‘Ti]Write a program to create cook import Javax.serviet.nttp."; WebServiet("/cookieDemo") public olass Cookie extends HttpServiet { protected void doGet(HttpServietRequest ri throws ServietException, [OException { | Set the content type response.setContentType("text/htm!” |; HttpServi Response resp) | Greate a cookie username”, "JohnDoe")s cookie.setMaxAge(60 * 60}; // Set cookie to expire in 1 hour response.addCookie(cockie); |! Add the cookie to the response i Write a response resp.getWriter().printin("" resp.getWriter().printin("“

Cookie Created!")j resp.getWriter()printin("Cookile Value: ~ + cookie.getValue() + ""); resp.getWriter()printin(""), ‘Scanned with CamScanner “orm namesYorm” method'ge actions "hitytecahost @80Deepiaprglh-> “h>slect Subjectemt> “robe clase owrak extends Hitpsorvtet ii void dowattipseritRequest req, HIlServetRenpone resp) throws Serdetexcept Spr ites ‘Scanned with CamScanner w File Edit View Search Document Project Tools Browser ZC Window Help é KDC | tos EL ie we = import jave.nal"; clase jebeDelete « public atatle vold main(Stringl] arga) thrown Exception Clans sorName("sun jibe ode JmeOumeDriver, Driverttanager-getConnection( jaie:oube:stuett aan" wtt=0) System.out.printin("w"ete"records are deleted”), System.out.printin("in ne any record is deleted"; ‘step 6: retrive the resuit ResultSet rmzetexecuteQuery("select * from students > Syeeumautpriiotrelt ne” name” pereemtons'W Seek ne ieee whitoacnes ni ‘Syatem.cut.printin(” »"*ra.getint(1}+" "4rs.getString(2}+" «"rs.getFleat(3)); d ‘atepT: close connection ef the atatement con.closet) st.closet; lle Le jdbeDeletejava | 2 meusendapjare —einetPregine - equelSjne ‘Scanned with CamScanner Import Javanet"1 Import Javacto."t erverd ServerSocket #88 new Serversocket{1234)1 Socket soctss.nccept()) ButferedResder br « new ButferedReader(new InputStreamReader(System.in)h BufferedReader in = new BufferedRenderinew InputStreamRender(soe.getinputStrenmi) PrintWeiter out = new PrintWrlter(new OutputStreamWriter(see.getOutputStrenm()} ‘string ate“ ‘String az=" a whitectrue) ‘ trequired messege from eliont s8In.rendLine(s Systeroutprint(-n trem ellent=+a4y . Msteequata(’ston")) ‘break tread trom keyboard System.outaprlnt(me Type here it s2abrroadLinet —<——— outprintin(s2h, ‘outsushoy Scanned with CamScanner #23. write a program to create three buttons with caption OK,RESET & CANCEL. import java.awt.*; Import Java.applet.*; r = aNonnuna 9 public class prg1 extends Applet 40 { 1 Button b1,b2,b3; 12 public void init 43 £ 44 bi=new Button("0K"); 45 b2=enew Button(” RESET"); 16 b3=new Button("CANCEL"); 47 add(b1); 48 add(b2); 19 add(b3); Scanned with CamScanner Taye fave program Import java “ pebllc clas pega extends Applet c Program to demost 2 Import Javax-swing.'s 2 Import Javax.swing.tree.*; © the wse of tree component In swing tree extends JFrame 40 _DetmulttutabletreeNede vegrede + new Defaulted 11 vepnode,ada(now DetaultMutabletreenode("Carot") 12 Yegnodecedd{new DefaullMutableTreeNede(-Tomnto") 43 ‘tadd(vegnode); ta is Maven via detateetao 200d 12 deaviate(ereyy aa ‘Scanned with CamScanner 22 public static void maln(String[] args) 2a ¢ 24 new tree(); 25} 26 } 27 ‘pik ds Bop ea ee roman Bove t lr de peor eh at i 0 20 peer hepa 50) ‘Bei 161 Se ate estat FRR alegre ho Se san, stat 1 eprint EH_ON. CLOSE, Concetntae il pata ae ge 200) 5 peat, ‘Scanned with CamScanner testo net tt sen patent i site stertnen estat) te vi eyressedtcySent he) Sntnarhe gta arenas > pers) cae eyoent vn Fi Series pes 2 yon. um Soentyiapeaaes ‘ee rayon nome ‘Scanned with CamScanner aytramon) 4 setoackground{Coler.bue}; setviemioterue), setsiza(400,200)) SetLayout(new FlowLayeutO); Inbarenew tenuBart ‘etttontarimbar Alomnew Manet ‘edits new Monut"odi Henew MonuttomCNow", tenew Menuiter(Ope0"h anew Menultom(s3¥2"% fie.naay, fie-naat2s fle-sdat3h ‘damindowtistener(now Winsownaapter() (indawwavant o) Scanned with CamScanner 1142. url program to find port ,host , protocol ,gotfilo. Import java.net.*; Public class URLConnectionExample { public static vold main(Stringf] args) { try URL url = new URL("httpil/oxample.com"}/f Change to the site you want to connect to URLConnection connection = url.openConnection(); connection.connect System.out.printin(“Protoc: ‘Syatem.out.printin(“Host: " + url.getHost() ‘System.out.printin(“Port: ~ + url.getPort()}s }om.out.printin(*Derault Port: " + url.gotDataultPort()); System.out.printin(“Filo: " + url.gotPilo() Systom.out.printin("External Form: ” + url.toExternalForm()}; } catch (Exception 0) { e.printstackTrace(); ? } ” + url. getProtocol()}; , Scanned with CamScanner 10 4“ 3 44 48 46 7 4n 49 20 a 128. wiite a prouram to creat Import java.awt Import javaappiet."; “applet code =prot width=400 height=400> applet ” Public clasa prot extends Applet 1 ution ©1,02,03; [pUBINE Wat sity basnew Butlon” RESET); bSenew Butlon(CANCEL"), exiel(t): cocel(b2); cacilth3}: ‘Three buttons with capdon OK RESET & CANCEL ~ Scanned with CamScanner [ine 28 VSS BT Tass 6 a7 ©7817 e147 sswordfleld to accent password from user Andi the length Is leas Than 6 charae aorward longth act bet charnetees” *! 143. Wile a program wslna JP should be divplayed Import javaapplet."} Import Javaawt.*; Import re mt.cvent. tt Import favax.swing. ight=an0> (pable clase Tutortalt extends JApplot inpplements ActionListener « Habe i432; “STeetrieta tt4,012; Password leld pase: Button Container 95 ord itt) engercontantpane(i: eoetLayaut(new Gridhayout(Sst)}s jenew JLabelf"Enter Usernane"h {Qanew Jtabal(-Entor Pavewort! ew JButten("Logln"k tener JTentFlelds sat TooMTIpTaxt{"Enter Username: unr Scanned with CamScanner sen Tot tres 70 Wid Hele x Pea AA teh ferment a 12 7 3 7 73 Wienew JTexthieli(; PA IA. setToolTipTent("Entor Username!) gr Uz=new JTextFlet(y 20 —_-passenew JPasswordField(; 29 oe Too!TIpT ext("Entor Passwort 30 waa a c.mda(ttt); | 32 cade (12); 33 eumddl(pasn)s 31 wade tF2)1 33 26 7} 38 public void actionPesformed(ActionEvent ae) 3 of 20 String papass.getTextl: 44 Mip.tengthq)<6) a 1 “3 H2.setText("Password must be gros aa , 45 sive a6 t a1 WD setText("Correct an 1 a} 20 } Je Scanned with CamScanner

You might also like