I O - Java

Output

  • System.out.print(val) => To print in console without new line
  • System.out.println(val) => To print in console with new line

Input

  • System.GC() => Garbage Collector
  • Using Scanner
    • Scanner var = new Scanner(System.in) => Declaring a Scanner class, Buffer size of 1 KB
    • var.close() => Closing the Scanner after use
    • var1 = var.nextInt() => Taking integer Input
      • var.hasNextInt() => Checks if the input is an Integer
    • var1 = var.nextByte()
    • var1 = var.nextShort()
    • var1 = var.nextLong()
    • var1 = var.nextFloat()
    • var1 = var.nextDouble()
    • var1 = var.nextBoolean()
    • String var1 = var.next() => Taking string Input of a single word
    • String var1 = var.nextLine() => Taking string Input of an entire line
  • Buffered Reader
    • Declaring a Buffered Reader Class, Buffer size of 8 KB, Faster than Scanner method, Supports threading
        BufferedReader var = new BufferedReader(new InputStreamReader(System.in));
      
    • String var = input.readLine(); => Take String input
  • Console
    • Console var = System.console();
    • String var = input.readLine(); => Take String input, Does not keeps a Buffer to store for taking Input
    • char[] var = input.readPassword(); => Takes input as Character array, Does not shows the value typed in console while typing
Share: