0% found this document useful (0 votes)
17 views

java question

java question
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
17 views

java question

java question
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 52
Automation Proficient =e yYougmrTrT 100 Java Programs Designed 8y: Sandeep Tiwari Contents Java Programs. 1 10. 1 2 13, 14 18 16 1” 18 19 20. a 22 23, 24, 25, 26, 2, 2, 29, ‘Simple Java Program. Print Integer in java, Command Line Argument. How to get Using input using Scanner Program in java How to convert Fahrenheit to Celsius Program in java How to swap 2 no using 3" variable Program in java How to swap 2 no without using 3" variable Program in java How to add two number Program in java, Find Largest no in java Program. IfElse clause in java I Else clause in java- Program 2 Nosted If Else clause in java. How to check Odd and Even Number in java Find factorial for given no Program in Java How to complet 2 string in Java program. Simple For Loop Program in Java Print Star console using Loop Print Star console using Loop ‘While loop Program in java. Pri Reverse number in java program. While loop using break Program java ‘White loop using break and continue Program in java Print all alphabet using for loop Program in java Enhance loop in java Program Print Multiplication table Program in java Print prime no Program in java Check no is Armstrong or not in java Program. Print Floye's Triangle. in java Program Find All substring of string in java Program sion bomens Ql) 10 10 u 2 2 2B B u 14 15 15 16 16 ” 18 19 19 Automation Proficient 30. 31. 32. 33. 34, 38. 36. 37. 38. 39, 40 a 2 4s, 44, 45, 46, 47 4a 49 50, 51, 82. 53. 54, 55. 56. sr. 58, 59. 60. ot. 62. 63. 64, 65. 66. Print reverse string in java Program Check Given No is palindrome or Not in java Program How to add two matrix in java Program. How to multiply two matrix in java Program. How to get transpose of matrix in java Program. How to compare 2 string in java Program How to string width with specific char in java Program. How to use indesOf() in java Program How to replace string with another string in java Program How to split string in java Program How to remove space in string both end in java Program. How to convert all char in string lower case In java Program How to create method in java Program Find Length, Concatenate and Replace String in Java Program How Static block working in java Program. Difference between Static and Instance method working in java Program. How to create Multiple class in java Program. How to create constructor in java Program. How to create constructor overloading in java Program Exception Handling java Program. How to throw exception in java Program ‘Advantage of Finally in Exception Handling java Program How to create Interface in java Program How to print date and time in java Program How to SQL Date in java Program. How to Date format in java Program How to Generat fandom number in java Program How perform garbage collection in java Program How to get own IP Address in java Program How to open notepad in java Program. Le rch Program in java Binary search Program in java. Bubble sort Program in java How to connect Database using java Program. How to insert data in table using JDBC in java Program. How to insert image using JDBC in java Program. How to execute Procedure in JDBC in java Program. sitonsci seomesis Gl) 20 2 2 23 2 25 25 25 26 26 26 26 ” ” 28 28 29 29 30 30 a1 31 32 3 3 33 34 34 34 38 36 37 a7 38 38 39 Automation Proficient o7. 63. 69, 70. nm n 1. 7, 75. 7. 7. 7. 7. 80, at 82. 83. 88, 85. 86. a7. 88, 8, 90. a4 92. 93. 94, 95. 96. 97. 98. 99. 100. How to check Regular expression in java Program How to create Multithreading program in java. How to join thread in java program How to write data in text file using java program, How to read data from text fle using java program How to got URL of site using java Programs How to got IP address from si URL using java program How to create AWT program in java How to add lable in AWT program in java. How to add text area program in java How to dropdow ‘AWT program in java. How to create Swing program in java How to add checkbox ‘Swing program in java How to convert string to integer in java program How to convert integer to string in java program How to convert string to long in java How to convert string to float in java How to convert string to doubl in java program How to convert string to date in java program Croato ArrayList program in java. How to create LinkedList program in java How to ArrayList using list interface program in java How to create Hashset program in java, How to create LinkedHashSet program in java How to create TreeSet program in java How to create PriorityQueue program in java, How to create HashMap using map interface program inj How to create LinkedHashMap program in java How to create TreeMap program in java How to create Hashtable program in java How to create Array program in java How to create Multidimensional array program in java How to ereate Find Factorial No using Recursion Program in java How to create Method Overriding program in java. sitonsci seomesis Gl) 39 33 40 40 a1 a a 2 2 a7 9 49 “9 50 ‘Automation Proficient |ma = ier_lll You 1.Simple Java Program class Helloworla ( public static void main © World by Technolamror") ; 2.Print mnteger | in java SIpublic static void main (string{) arguments) ( int el 3.Command Line Argument in java 4 n(String[] args) i nit): sion bones Gl) Automation Proficient =e wou @iTETS) 4.How to get Using input using Scanner Program in java import java.s class Get Tn i public static void main(String ar 1 romlser printin("You entered float “ 5.How to convert Fahrenheit to Celsius Program in java import java.util.'; emperatue in Fahrenheit"); 2)#5) 195 ratue in Celsius =" + temperatue); sion bones Gl) Automation Proficient | = ial You 6.How to swap 2 no using 3" variable Program in java import Savarusil.Scanners class SwapNunbers ‘ Public static void main(st nt x, x = in.nextInt (); y = insnextInt (); printin ("Before Swapping\nx = "+x+"\ny = "+y); temp xy; y = temp; ut-printia ("after Swapping\mx = "+x+"\ay = "ty)s 7.How to swap 2 no without using 3" variable Program in java import java.util.Scanner; class SwapNunbers fi public static void main { int x,y Enter x and y"); ner (System.in) ; x = in.nextInt (); y = insnextInt (); s ntln ("Before Swapping\nx = "+x+"\ny = "+y); sion bones Gl) Automation Proficient [=x alll You @iiTs yox-y; x= x > yr System.out-printin ("After Swapping\nx 8.How to add two number Program in java import java.util.Scanner; class AdaNumb i public static void main(String args()) { int x,y) 2 System.out.printin("Enter two integers to calculate their sum " Scanner in — new Scanner (System.in) ; x = insnextInt (); y > insnextint (); system.out.printin("Sum of entered integers ) ' //Fox Large Number import java.util.Scanner; import java.nath.Biginteger; class AddingLargeNumbers ( public static void main(String|) args) ( String numberl, numbe: Scanner in = new Scanner (System. in); system.out.printin("Enter first large number") numberi = in.nexthine(); System.out-printin("Enter second lage number"); umber? = in.nextLine(); Bigiateger BigInteger second BigInteger sum; new BigInteger (number?) ; new BigInteger (number?) ; t.add (second) ; m.out.printin("Result of addition =" ~ sum); g sitonsci seomesis Gl) You@mrTD 9.Find Largest no in java Program import java class LargestofThreevumbers fi public static void main(s { x = insnextint(); y = inwnextInt(); 2 = insnextInt (17 if (x>y be x>2) System.out.printla ("First number is else if (y>x ss y>2) System, out-printIn ("Second number is else if (2 > x Gs 2 >) System.out.print1n ("Third number is largest."); else tem.out.printIn ("Entered numbers are not distinet."); 10. If Else clause in java class Cond: on { public static void main(String(] args) { boolean learning = true; if (learning) ( System.out.println ("Java programmer"); } else { System.out.printin("What are you doing here? } Automation Proficient —_s a You @gtitss| 11. If Else clause in java- Program 2 import java class Tflse | Public static void m passingMarks = Scanner input — new Scanner (System.in); tin("Input marks scored by you"); marksObtained = input-nextInt (); rksObtained >- passingM -printia("Yeu pas. £ d the exam.) ; s the exam."); import java class WestedtsElse ( Public static void m passingMarks = 0; prin ained = input-nextInt (); if (marksObtained >= passingMarks) ( if (marksobtained > 90) grade sion bones Gl) Automation Proficient |ma2je all You Girt else if (marksObtained > 75) grade - 'E "4 grade); System.out-printin("You passed the exam and your grade ntin("You failed and your grade is " + 13. How to check Odd and Even Number in java. import java.s canner class od i public static void main(String args[)) int x; sprint: to check if it is odd or even "}; nextIn an even number. import java.util class Factorial i public static void main(String args()) Automation Proficient |ma- =i all You @itirTs| ig (aco) System. out.println ("Number should be non-negative."); else for (c= 1; ean; ct) fact = factte; system. out .printl 5 = "tEact); , //Calculate factorial for large No import java import java.nat! 1. Scanne: Biginteger; class BigFactorial fi public static void main(String args{ |) fl int a,c BigInteger in Bigtnteger fact = > new Bigint Tnteg: Seanner input ~ mew Scanner (System.in): for (c= 1; c scan [Jeve Application] C\Program Files\lavaljrel 8.0_¢1\bin\javaw.eve (lan & 2017, 235446 PM) Input an integer 2 You entered 2 Input an integer You entered 1 Input an integer You entered 6 Input an integer a You entered 1 Input an integer e ut of loop 18. Print Star console using Loop class stars public static void main(String) args) ( int row, numberofstars; for (row = 1; row <= 10; rowt+) { for (nunbeross “P. ars = 1) numberofStars <= row; numberosStars++) meinen) printin(); 19. While loop Program in java import java.uril.Scannery class WhileL public static void main(String[) args) int a; Lin("input an intege: Automation Proficient |ma"Jeaall You , 20. Print Reverse number in java program import java.u class ReverseNunber ( public static void main(str. ( int a, reverse = 0; to reverse"); while( n= 0) System.out.printin ("Reverse of entered nunber is “treverse); 21. While loop using break Program in java import java.ucil.Scanner; class Bre public int i atic void main(String[] args) input = new Scanner (System. in}; while (true) | if (a == 0) break; out printin("You entered " + n); sion bones Gl) ee You@trs Automation Proficient 22. While loop using break and continue Program in java import java.util.Scanner; a(String[] args) 23. Print all alphabet using for loop Program in java class Alphabets fi public static void main(string args|!) { char ch; for( ch = tat; ch <= tz"; chtt ) System. out.printla (eh) ; sion bones Gl) Automation Proficient {ma =i ll You @itirTs| 24. Enhance loop in java Program system , , //For String class EnhancedfozLoop Public static void main (s String languages {1 = { ring[] args) 25. Print Multiplication table Program in java import java.util.Scann class Mult fl plicationTable public static void main(st ‘ printin ("Enter an integer 3 system. ou //Fox Any Nunber import java.util.Scanner; class 7s! fi public static void main(String args{]) c int a,b, ¢, d; sitonsci seomesis Gl) Automation Proficient |mx =i ill You System.out-printIn ("Enter range of numbers to print their multiplication table"); new Scanner (System.in); snextInt snextInt 0; for (c = a; © pins eturn p; sion bones Gl) Automation Proficient [maxi alll You@mrTD ) , 28. Print Floyd’s Triangle in java Program import java.util.Seanner; class Floydtriangle ( public static void main { system.in); he number of rows of fleyd's triangle you AenextInt (7 system for (c= 1 pen; ct) system.out.printla()7 29. Find All substring of string in java Program import java.util.Scanner; class Substrin fl public static void main(st ring string, sub; int i, c, length; Automation Proficient | ma"ie_illl You System.out-printin("Substrings of \""+stringh™\" are ="); for( c= 0; © < length ; c++) i for(i = 1; i <= length - cj i++) { sub = string.substring(c, e#i); system.out.printin (sub) ; 30. Print reverse string in java Program import java.util.'; class Reversestring i ‘ System.out-printin("Enter a string to reverse"); original ~ in.nextLine(); int length ~ origin 2edengta (7 i-- ALi); for ( int i = length - 1; i >= nal. system.out-printin("Reverse of entered string is: “+reverse); ) ' / {Using Internal java Methog class invertString ( public static void main(String args!) { StringBuffer a = new StringBuffer("Java programming is fun"); System. out .printin/(a.reverse() sitonsci seomesis Gl) Automation Proficient |e You 31. Check Given No is palindrome or Not in java Program import java.util.+; i public static void maia(stzing azgs[!) { String original, rever Scanner in = new Scanner (System. in); Systen.out.printin("Enter a string to check if it is a palindrome"); original = in.nextuine(); int length = original.length(); for ( int i= length - 1; i >= 0; i-- ) reverse = reverse + original.chazAt (i); if (original equals (reverse) ) System. out.printIn ("Entered string is a palindrome. else System.out.println ("Entered string is not a palindrome."); ) ' //another Method import java.util.*; class Paling i public static void main String inputstring; ring args{]) Sea (system.in); System.out-printin("Input a string"); inputString = in.nextLine(); inputstring.lengzh()+ end, middle; = length - 2; middle = (begin + end) /2; for (i = begin; i <= middle; i++) { if (inputString.charat (begin) nputString.charAt (end) ) { } else ( break; ' sion bones Gl) ‘Automation Proficient |=" You if (i w= middle + 1) ( system. out.printin("Palindrome") ; } else ( System.out-printin("Not a palindrome"); ' , 32. How to add two matrix in java Program import java.util.Scanner; class AddTwoMatrix ( public static void main(String azgs|!) ( int m,n, nner (System. in); System.out-printin("Enter the number of rows and columns of matrix"); m= insnextIne (17 no = in.nextint 0; int first[)[] = mew int{m] [x]; int secord(|{] = new int im] (n); int sun[][] = new int(m) in]; system.out.printin("Enter the elements of first matrix"); for ( c= 0; e¢ eateh (Exception ©) -printin(e); finally System.out.printin("finally block will execute always."); sitonsci seomesis Gl) Automation Proficient [ma =e You @itirTs| 52. How to create Interface in java Program interface Info { static final s public void di: ' class Simple implements Info ( public static void main(String [Jarus! bj ~ new Simple (): ey: public void display() System, out.printin(langua 53. How to print date and time in java Program public class SQLDateExample { public static void nain(string{] args) { Yong millis-System.currentTimemillis(); java.sql.Date date=new java.sql.Date(millis); System-out.printin(date); + 3 7/1 Another Way import javarctil.*; class GetCurren c eAndTine public static void main( month, ye ad, minute, hour nCalendar date = new regorianCalendar () ; ient |e al You System.out-printin("Current date is "sday+"/"+(month+1) System.out.printin("Current time is "shour+" : "+minute+" : "+second) ; Automation Profi 54. How to SQL Date in java Program inport java. sql.bate; public class stringTosqLoatecxanple ( public static void main(String[] args) { "2015-03-31"; ate.valueOf(str);//converting string into sql date System.out.printin(date); 55. How to Date format in java Program import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class SimpleDateFornatéxarple? ( public static void main(String(] args) ( Date date lew Date(); system.out.printIn(“Date formate chnage by Technolanror "); SinpledateFormat fornatter = new SimpleDateFormat("M/dd/yyyy")3 String strDate = formatter. format(date); System.out.printIn("Date Format with "M/dd/yyyy : “+stroate); formatter = new SimpleDateFormat("dd-M-yyyy hh:mm:ss"); strbate = formatter. format(date); System.out.println("Date Format with dd-M-yyyy hhiam:ss : “#strDate) formatter = new SimpleDateFormat("dd MMM yyy"); strbate = formatter. format(date); System.out.printin("Date Format with dd MMMM yyy : “+strDate); formatter = new SimpleDateFormat("dd M™YM yyyy z222")5 strOate = formatter. format(date); system.out.println("Date Format with dd MMMM yyy 2222 : “#strDate); formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss 2"); strbate = formatter. format(date) ; System.out.printIn("Date Format with E, dd Mmmm yyy HH:mm:ss z : “+strDate); sion bones Gl) Automation Proficient [ma 3a You @itirTs| 56. How to Generate random number in java Program import java.vtil.*; class 22 mvumbers public static void main(String) args) int c; Random t = new Random (); pe < 10; em) { out.printia(t.nextrnt ( 57. How perform garbage collection in java Program import java.ctil.*y class GarbageCollection i public static void main(String s{]) throws Exception Runtime .getRu ntia ("E in JVM before Garbage Collection = ye Collection = 58. How to get own IP Address in java Program import java.net. Inotaddze class ( public static void main { Address System. out.println (InetAd ) ' sion bones Gl) Automation Proficient m= ier You@ityrs 59. How to open notepad in java Program import java.util import jav clase Ww public static void main(String[) args) Runtime Runtime. getRuntime () try | Ts.exec ("notepad") ; catch (TOFxception e) 60. Leaner search Program in java import java.util.Scanner; class Lin i ch public static void main(String args{]) c int c, n, search, array new int[n]; eintln ("Enter " +n +" integers’ een et) nenextine ()7 © value to find"); if (arrayle] == search) ys om.out.peintla (search + break; sion bones Gl) Automa' n Proficient (=~ i aad You ) if (c= 0) /* Si system. out .printin (searc present in array. 61. Binary search Program in java import java.util Scanner; class BinarySearch public static void main(String args(]) int c, rst, last, middle, n, search, array[); Scanner in ~ new Scanner (System.in): system.out.printIn("Enter number of elements"); = insnextInt ()7 ay = new int| system.out.printin ("Enter "+n + " integers’ ort) nextint (); system.out-printIn ("Enter value to find"); search = in.nextInt (7 first middle + last) /2; while( first ast) ( if ( arrayin < search } fizst = middle + 1; else if ( array(middie} == search ) i system.out.printin(search +" found at location " + (middle + break; » else last = middle ~ 1; middle = (first + last) /2; ) if ( first > last ) system.out.printin(search +" is not present in the List.\n"); sitonsci seomesis Gl) Automation Proficient |= =a You 62. Bubble sort Program in java import java.ctil.scanners -printin("Serted list of nunbe -printin(array(el}; ot) 63. How to connect Database using java Program import java.sql.*5 class OracleCon{ public static void main(String args[]){ try //step1 load the driver class Class. forName(“oracle. jdbc.driver.OracleDriver™); //step2 create the connection object sion bones Gl) Automation Proficient |= ial You Connection con=DriverManager. getConnection("jdbe: e") //step3 create the statement object Statement stnt=con.createStatenent(); J/step4 execute query ResultSet rs=stmt.executequery("select * from emp"); while(rs.next()) System. out. println(rs.getInt(1)+" //stepS close the connection object con.close(); }eatch(Exception e){ System.out.printin(e);} 3 } racle:thiny »"systen","oracl +rs.getString(2)+" "“+rs.getString(3))s 64. How to insert data in table using JDBC in java Program Anport java.sql.*; Class InsertPrepared( public static void main(String args{ }){ try Class. forNane( “oracle. jdbe.driver.Oraclebriver"); Connection ©"); PreparedStatement stmt=con.preparestatenent("insert into Emp values(?,?)")s stmt.setint(1,101);//1 specifies the first parameter in the query stint setstring(2, "Ratan”); int i-stmt.executeupdate(); System.out.printIn(i+” records inserted"); con.close(); }eatch(Exception e){ Systen.out.printIn(e)5} DriverManager. getConnection(""jdbc: oracle: thin:@localhost:1521:xe" "system" ,"oracl } + 65. How to insert image using JDBC in java Program import java.sql.*; import java. io.*; public class InsertImage { public static void main(stringl] ares) ( try Class. forWane( "oracle. jdbc.driverOracleDriver"); Connection con=DriverManager.getConnection( "jdbc: oracle: thin:@localhost:1521:xe", "syste PreparedStatement ps=con.prepareStatement(" s"oracle"); nsert into imgtable values(?,?)"); sitonsci seomesis Gl) ‘Automation Proficient [=a teal You @trT) ps.setString(1,"Technolanror”); FileInputstrean finsnew FileInputstream("d:\\g.Jps")5 ps.setBinaryStream(2, fin, fin.available()); int isps.executeUpdate(); Systen.out.println(i+" records affected"); con.close(); yeatch (Exception e) (e.printstackTrace();} 3 + 66. How to execute Procedure in JDBC in java Program import java.sql.*5 Public class Proc { public static void main(Stringl] args) throws Exception{ Class. forWame("oracle.jdbc.driver .OracleDriver"); Connection con=DriverManager. getConnection(" jdbc:oracle:thin:@localhost :1521:xe","systen", "oracl e") CallableStatenent stmt=con.preparecall("(call insertR(?,?)}")3 stmt.setInt(1,1011) stmt setString(2,"Anit"); stmt execute(); Systen.out.printin("success") } } 67. How to check Regular expression i Program import java.util.regex.*; Public class Regexexanplel{ public static void main(String args{]){ java //ist way Pattern p = Pattern.compile(".s")3//. represents single character Matcher m = p.matcher("as"); boolean b = m.matches(); 1/2nd way boolean b2=Pattern.compile(".s").matcher("as").matches(); 13rd way boolean b3 = Pattern.matches(" Systen.out.println(b+" "+b2+ Y 68. How to create Multithreading program in java Glass Multi extends Thread{ public void run(){ System.out.printin("thread is running. 3 sitonsci seomesis Gl) Automation Proficient | mx You public static void main(String arest]){ Multi ti-new Multi(); tistart(); } 3 69. How to join thread in java program class TestJoinMethod] extends Thread{ public void run(){ for(int i=1;ic=S3it+){ tryt ‘Thread. sLeep(S00); }eatch(Exception e){System.out.println(e);} System.out.printIn(i); , } public static void main(string erest]){ TestJoinNethodi ti=new TestJoinMethodi(); TestJoinMethod1 ew TestJoinMethod1() ; TestJoinMethodi t3=new TestJoinMethod1(); tistart()3 try t1.Join()s }eatch(Exception e){Systen.out.printIn(e) 5} t2.start(); t3.start(); } ? 70. How to write data in text file using java program Amport java.io.Fileoutputstream; public class FileoutputStreamExample { public static void main(String argst]){ tryf Fileoutputstrean fout=new FiledutputStrean("D:\\testout. txt") fout.write(65); fout.close(); system.outprintin("success.. by Technolanror."); }eatch(Exception e){Systen.out.printIn(e);} 71. How to read data from text file using java program Anport java.io.FileInputstrean; public class OataStreanExanple { sitonsci seomesis Gl) Automation Proficient |= ial You public static void main(String args{]){ ‘try Filetnputstream fin-new FileInputStream("D:\\Technolanror. txt"); int isfin.read(); System.out.print ((char)i); Fin.elose(); }eatch(Exception c){Systen.out.printIn(e);} y 72. How to get URL of site using java Programs Inport Javacnet. ts public class URiDemo( public static void main(String[] args){ try{ URL urlenew URL(*http: //mav. technolanror.con/ java")s system. out. BRIREIN( "Protocol: "+url.getProtocol())5 System.out.printin("Host Name: "surl.getHost()); System.out.printin("Port Number: "+url.getPort(})5 System.out.printin("File Name: "+url.getFile()); }eatch(Exception e){System.out.printIn(e);} y 3 73. How to get IP address from site URL using java program Anport java. io.*; Inport java.net.*; public class InetDeno( public static void nain(string[] args){ try InetAddress ip=InetAddress.getByName(“www.Technolamror.com") 5 System.out.println("Host Nam getHostName()); System.out.printIn("IP Address: "+ip.getHostaddress()); yeatch(Exception e){System.out.printin(e);} } } 74. How to create AWT program in java import java.awt.*; Class First extends Frane( First Button benew Button("click me"); b. setBounds (30, 100,80,3@);// setting button position sitonsci seomesis Gl) Automation Proficient [ma =i all You add(b);//adding button into rane setSize(300, 380) ;//frane size 3@@ width and 360 height setLayout(nul1);//no layout manager setVisible(true) ;//now frame will be visible, by default not visible + Public static void main(String args[]){ First fnew First(); 2 75. How to add lable in AWT program in java Amport java.awt.*; class Labelexanple{ public static void main(String args[]){ Frame f= new Frame("Label Example by Technolanror"); Label 11,125 Lisnew Label("First Label."); 11, setBounds (58,100, 100, 3@); 12snew Label("Second Label. 12.setBounds(5@,15@, 100,30); .add(11); f.add(12) 5 +. setSize (400,400) ; #,setLayout (null) ; #.setVisible(true); 76. How to add text area program in java import java.awt.*; public class TextAreaExample t Textareatxample(){ Frane f= new Frane(); TextArea areasnew TextArea("Welcone to Technolanror"); area.setBounds(10,38, 300,380); £-add(area) ; F.setSize (480,490); #.setLayout (null); £.setVisible(true) ; } public static void main(String args{]) { new TextAreatxanple(); , } 77. How to dropdown in AWT program in java import java.awt.*3 public class ChoiceExample { ChoiceExanple(){ sitonsci seomesis Gl) Automation Proficient {max =i ll You @itirTs| Frame f= new Frane(); Choice cenew Choice(); c.setBounds(1@,100, 75,75); c.add("Item 1 by Rajendra"); c.add("Item 2 by Lanror"); c.add("Item 3 by Technolamror"); cradd("Ttem 4"); c.add("Item 5")3 fadd(c); F.setSize(400, 400) ; f.setLayout(null) ; F.setVisible(true); y public static void main(String args{]) t 3 } new ChoiceExample(); 78. How to create Swing program in java import javax.swing.*; Public class FirstSwingéxample { public static void main(String[] args) ( 3Frame fenew JFrame();//creating instance of 3Frane 3Button b=new IButton("click");//creating instance of 3Button -setBounds (138,188,108, 40); //x axis, y axis, width, height sadd(b);//adding button in 3Frane +setSize(490,508);//400 width and 500 height setLayout(nul1);//using no layout managers. ssetVisible(true);//making the frane visible 79. How to add checkbox in Swing program in java Amport javax.swing.*; public class CheckBoxExample { CheckBoxtxample(){ BFrane f= new JFrane("CheckBox Example by Technolanror"); 3checkBox checkBox1 = new Iheckdox("C++"); checkBox1. setBounds (100,108, 50,58); 3checkBox checkBox2 = new ICheckBox("Java' checkBox2.setBounds (100,150, 50,58); f.add(checkBox1); #1add(checkBox2); ¥.setSize(400, 400) ; #!setLayout (null); flsetVisible(true); » true); t public static void main(String args{]) sion bones Gl) Automation Proficient [=a ie You@ityrs new CheckBoxExample() ; a 80. How to convert string to integer in java program public class StringToIntexanple( public static void main(String arest]){ String s="200"; int i=Integer.parseInt(s); System. out. print1n(s+10@) ;//200100 because + is string concatenation operator System. out. printin(i+1@@) ;//300 because + is binary plus operator 81. How to convert integer to string in java program public class IntToStringexanple1( public static void main(String args[]){ int i=209; String s#String.valueof(i); System.out. print1n(i+1@@) ;//300 because = is binary plus operator System. out. printIn(s+1@@) ;//200100 because + is string concatenation operator nD 82. How to convert string to long in java public class StringToLongéxanple( public static void main(String args[]){ String s="9990449935" ; long 1=Long.parseLong(s) ; system. out.print1n(1); oe 83. How to convert string to float in java public class StringToFloatéxanple( public static void main(string ares[]){ String 5="23.6"j float oat. parseFLoat ("23.6"); System.out.printin(#)s 84. How to convert string to double in java program public class StringToDoubleExample{ public static void main(String arest]){ sitonsci seomesis Gl) Automation Proficient |x ie alll string s=' double d= systen.ou Y You@mrTD 3.6"5 Double. parseDouble("23.6 (t.println(d) ; 85. How to convert string to date in java pro: import ja import Ja public ei public st strin strin strin Strin strin strin Sinpl Simpl sinpl Simpl Sinpl sinpl Date Date bate Date Date bate syste syste syste syste syste! syste syste gram va. text .SinpleDateFormat; va-util Dates ass StringToDateExamplel { atic void main(String{] args)throws Exception ( iB sDatel="31/12/1998"; i sDate2 = "31-Dec-1998"; sDate3 = "12 31, 1998"; sbates = "Thu, Dec 31 1998"; g sDates = "Thu, Dec 31 1998 23:37:50) i sDates = “31-Dec-1998 23:37:50"; ebateFormat fornatteri=new SimplebateFormat eDateFormat fornatter2=new SimplebateFormat eDateFormat fornatter3=new SimpleDateFormat eDateFormat fornatterd=new SimpleDateFormat edateFormat fornatterS=new SinplebateFormat eDateFormat formatter datei=formattert.parse(sbatel); date2=formatter2.parse(sbate2); date3=fornat ter3.parse( sbate3); datea=formatter4.parse( sbate4); dateS=format ters parse(sbateS); dates=fornatters.parse( sbates); dd/m/yyyy ‘dd-mnt-yyyy) "MM dd, yyy E, MMM dd yyy"); E, MMM dd yyyy HH:mm:s: 1ew SimpleDateFormat ("dd-MiM-yyyy HH: mm: 3 v3 m.out printin("String to Date converter by technolanror"); m.out .print1n(sDatel+"\t"+datel) ; n.out .printin(sDate2+"\t"+date2) ; m.out .printIn(sDate3+"\t"+date3) ; m.out .print1n(sDated+ m.out .printIn(sbates+ m.out .print1n(sDates+ \t"edates) 5 86. Create ArrayList program in java import ja va.util.*; Class Arrylist_Technolanror{ public static void main(String argst])( ArvayList Listsnew ArrayList(); //Creating acraylist list.ad list.ad List.ad List.ad id("Rajendra");//Adding object in arraylist id( "Mahendra" ); id("Raja")5 Id("Technolanror" ); surobunon Proneit Automation Proficient ma Sie lll You @itirTs| //Traversing list through Iterator Iterator itr=list.iterator(); while(itr hasNext()){ System.out.printIn(itr.next()); + 87. How to create LinkedList program in java import java.util.*; public class LinkedList technolanror( public static void main(string args[]){ Linkedal al=new Linkedal(); al.add( "Rajendra al .add( "Mahendra al.add("Raja")5 al.add("Technolanror”); 3//Adding object in LinkedList Iterator itr=al.iterator(); while(itr.hasNext()){ System. out. printIn(itr.next()); 3 88. How to ArrayList using list interface program in java Amport java.util.*; class Book { int id; String name, author ,publisher; int quantity; public Book(int id, String name, String author, String publisher, int quantity) { this.id = 4d; this.nane = nane; this. authors this publisher = publisher; this-quantity = quantity; ? ? public class ListIteratorexample { public static void main(String[] args) { //Creating list of Books ListeBook> list=new ArrayList(); //Creating Books Book bi=new Book(1@1,"Let us ¢","Yashwant Kanetkai Book b2=new Book(102,"Java Program Questatior Book b3=new Book(1@3, "Operating System", "Galvi //dding Books to list 4 "BPB",8); "Rajendra", "Technolanror" ,4) 5 iiley" 6); sitonsci seomesis Gl) Automation Proficient [m= You @trT) Listadd(b1)5 List.add(02)3 Listadd(o3)} Systen.out .printIn(“Original content of list is: *); [Traversing list for(Book b:list){ System.out .printn(b. ide + Listrterator itreList.listIterator(); System.out .printin("Modified content of list in backward is: "); while (itr hasNext ()){ '4b.name+" "+b.author+" "+b.publisher+” "+b.quantity); Book st=(Book) itr-next(); Systen.out.printIn(st.quantity+” "+st.publisher+" “+st.author+" “4st.name+" “est.id)s } y 3 89. How to create Hashset program in java import java.util.*; class TestCollection9{ public static void main(String args[]){ //Creating HashSet and adding elenents HashSet set=new HashSet()3 set.add("Rajendra"); set.add( "Raja set.add ("Ravi set.add("Technolanror”); // Traversing elements Iterator itr=set.iterator(); while(itr.hasNext()){ System. out.println(itr.next())3 y y y 90. How to create LinkedHashSet program in java Amport Java.util.*; class LinkedHashSet_Technolanror( public static void main(String argst]){ LinkedHashSet al=new LinkedHashset(); al.add("Rajendra"); al.add("Raja"); al.add("Ravi"); al.add("Technolasror*); Iterator itr=al.iterator(); while(itr.hasNext()){ out itr sitonsci seomesis Gl) Automation Proficient [ma =i all You 91. How to create TreeSet program in java import java.util.*; class Treeset_Technolanror{ Public static void main(String argst]){ [Creating and adding elenents TreeSet al=new TreeSet(); al.add(*Rajendra”); al-add("Raja"); al-add("Ravi")} al.add("Technolanror"); ments Iterator itr=ai.iterator(); while(itr.hasNext()){ systen.out.printIn(itr.next())5 y y y 92. How to create PriorityQueue program in java import java.util.*; class PriorityQueue_Technolamror{ public static void main(string ares[])( PriorityQueue queue=new PriorityQueue(); queue.add("Rajendra"); queue add(*Nahendra queue.add("Raja"); queue. add("Technolamror") ; queve-add(*Rahul"); System. out.print1n("! :"+queue.element()); System. out.printin("head:"+queue.peek()); System.out.printin("iterating the queue elenents:")s Iterator itr=queve.iterator(); while(itr.hasNext()){ Systen.out.printin(itr.next()); } queue. remove(); queue.poll(); System.out.printIn("after removing two elements Iterator itr2=queue.iterator(); whie(tr2.hasNext())< System.out.print1n(itr2.next()); } } 3 sitonsci seomesis Gl) Automation Proficient | maa You 93. How to create HashMap using map interface program in java import java.util.*; Class MapinterfaceExample{ public static void main(String args[]){ MapcInteger, String> map=new HashMap(); mmap.put (10, "Rajendra”); map. put(101, "Lanror”); mmap.put (182, "Technolanror"); for(Map.Entry m:ap.entryset()){ _Svstet-out.printin(n-getkey()+" “om getva]46()); ¥ } 94. How to create LinkedHashMap program in java Amport java.util.*; class LinkedHashMap_Technolnaror{ public static void main(String args{]){ LinkedHashMapcInteger, String> hn=new LinkedHashMap() hm. put (102, Rajendra"); hm. put (101, "Vijay"); hn. put (102, "Technolamror"); for(Map.Entry m:hn.entrySet()){ System. out. print1n(m.getkey(): 95. How to create TreeMap program in java import java.util.*; Class TreeMap_Technolanror{ Public static void main(String args[1){ TreeMapcinteger, String> hn=new TreeMap(); hn. put (2100, " hin. put (2102, " hm. put (103, " hm.put (103, "Technolanror”); for(Map.Entry mzhn.entryset()){ _Systenout-printin(n-getkey()#" “en.getvalu6()); ¥ y sitonsci seomesis Gl) ‘Automation Proficient |ma = i_all You 96. How to create Hashtable program in java eine tasheable-Technolanror( public static void main(String args[]){ Mashtablecinteger,string> hrenew HashtablecInteger,String>(); him. put (100, Rajendra"); hin. put 102," hm. put (101, "Bi hm. put (23, " for(Map.Entry m:hn.entryset()){ System.out.printin(n.getkey()+" "+n.getValue()); 3 y y 97. How to create Array program in java glass ARPay_Technolanror{ Public static void main(String argst]){ int a[]=new int[5];//declaration and instantiation a[@]=105//initialization a[a]=203 a[2]=703 [3 ]=405 a[4]=503 //printing array for(int i=O;ica.lengthsit+)//length is the property of array System.out.printIn(a[i]); » 98. How to create Multidimensional array program in java class Multi JApray{ public static void main(String args{]){ //declaring and initializing 20 array int arr[][]=({1,2,3},(2,4,5},(4,4,5}}5 [/printing 20 array for(int $=05¢35i+4){ for(int j=035<3; j++) 5 Syseenout-wrbne(are(a]E316" Systen.out. printIn()3 3 sitonsci seomesis Gl) Automation Proficient | ma all You » 99. How to create Find Factorial No using Recursion Program in java public class Recursit olamror { static int factorial (int n){ if (n == 1) return 1; else return(n * factorial (n-1)); y public static void main(string[] ares) { System.out.printIn("Factorial of 5 is: "sfactorial(5)); } > 100. How to create Method Overriding program in java class Bank{ int getRateofinterest(){return 03} 3 class SBI extends Bank( int getRateofInterest(){return 83) } class ICICI extends Bank{ int getRateofinterest(){return 73} ? class AXIS extends Bank( int getRateofinterest(){return 93} ? class Test2{ public static void main(String args[1){ SBI s: ICICI AXIS. system. out. print1n(" : System.out.printin("ICICI Rate of Interest System.out.printin("AXIS Rate of Interest: s.getRateofinterest()); I. getRateofinterest()); +2. getRatedfinterest())3 sitonsci seomesis Gl) Thank You Friends For Reading Sandeep Tiwari as YougmrT) Sandeep Tiwari situa eons Ql

You might also like