Posts

Showing posts from June, 2021

String Handling

  String - It is a collection of characters.  Program-  public class str { public static void main(String args[])  { String data; data = "Mynameiskhan"; System.out.println(data);  } }    Functions used in String handling- -> used for output 1. charAt(index) - it is used to display a character in the string, by giving the appropriate index.   ex- String data1 = "Chitransh";  data1.charAt(2); -> i 2. codePointAt(index) - it is used to display the ascii value of given character. ex- String data1 = "Chitransh";  data1.codePointAt(3);  -> 116(ascii code of t) 3. codePointBefore(index) - giving the ascii code of the character before the given index of the character. ex- String data1= "Chitransh";  data1.codePointBefore(3); -> 105(ascii code of i) // index is given 3 but displays the output for index position 2.  4. compareTo() - it returns the values in the form of 0(if true) or non zero(if false). ex-String...

File Handling

  File-  file is a location in a computer system where the information is stored. Types of file- 1. System file - exe files(run by the system) 2. User file - txt,.java,.c (all user defined files)  File handling- manipulation with the file like creation, updation, deletion or etc. Two properties of file- 1. Name 2. Extension Works on two methods-  1. file will be created. 2. it is already existed. How to create a file-  step 1: we have to include a package to create a file. import java.io.File; step 2: Create an object of File. File f1 = new File(); step 3: pass the name of file in the parameter. File f1 = new File("Hi.txt"); step 4: check wheather the file will be created or already existed using createNewFile(). step 5: Put the whole program inside try catch block. Inorder to catch the Exception we have to include -  import java.io.*; (*- symbolises all utilities) Program - import java.io.File; import java.io.*; public class app {  public static void ...