How To Scan Input In Java

The best way to scan input in java includes the use of BufferedReader class, another method uses Scanner class but is slower, so here we will prefer BufferedReader. The following code demonstrate the use of BufferedReader for scanning input of different type. // file ScanInput.java import java.io.*; public class ScanInput{ public static void main(String args[]) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter a String: "); String msg=br.readLine(); System.out.print("Enter a Integer: "); int integer=Integer....

February 3, 2015 · 1 min · Zeeshan Khan

How To Run a Java Program

To run a java program you must have one, so lets have a sample code which prints “Hello world!!” to console. Source Code If you have source code ready then ignore else create a new file Hello.java and copy the below code in it and save it. Source code // file Hello.java import java.io.*; class Hello{ public static void main(String args[]){ System.out.println("Hello World!!"); } } now you have your source code ready,...

January 24, 2015 · 1 min · Zeeshan Khan

Client Server in Java

The following program demonstrate how we can implement simple client server architecture in java Start Server.java in a terminal/command prompt then open another command prompt/terminal and start Client.java in it Server can handle new Clients on disconnection of previous one. ...

January 21, 2015 · 2 min · Zeeshan Khan

ArrayList in java

ArrayList is a collection of data items that grows and shrinks depending on the number of data items present in it, you can think it as a dynamic array or a link lists in C, whose size increases when we insert a data and decreases as delete some data from it. To insert a data item we use add() method and to delete we use remove() method as demonstrated below in line 13 and 20 respectively....

January 8, 2015 · 2 min · Zeeshan Khan

Add Two Integers in Java

Following program will add two Integer numbers for you. // file Addition.java import java.io.*; class Addition{ public static void main(String args[]) throws IOException{ int a,b; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter first integer"); a=Integer.parseInt(br.readLine()); System.out.println("Enter second integer"); b=Integer.parseInt(br.readLine()); System.out.println("Sum of two integers is: "+(a+b)); } } To run the above code navigate to the source code folder from cmd(Windows) or terminal(Linux) then type the following code to compile javac <filename>.java after sucessfully compiling, type java Addition to start the programe....

December 28, 2014 · 1 min · Zeeshan Khan