Posts

Showing posts from June, 2016

how to create File and write into file in Java

How to create File and write into that using java IO package is used to perform Input/Output operation or file operation .       package Name:--> import java.io FileWriter is used to check file is there or not if not it will throw "File not found Exception ". but we can overcome this problem using        FileWriter fw = new FileWriter(file.getAbsoluteFile());        if(!file.exists()){        file.createNewFile();//Force to create File with Empty content        } File operation will force to progammer to put File operation code inside try catch else throw IO Exception because JVM don't know run time wheather file is avilable on directroy or not .or any other reason that is handle by IO Exception  Example :- import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; public class FileOperation {...

Genric Data Type in Java

Java Generic Type will  enable programmers to specify, specific Data type in Java .we can use Generic for class,Method,Collection. *   Suppose if we take example of Hashset normally when we create Object of set it will allow all data type in reference . so while retrieving value we need to perform type casting because we don't know which type of Data it is . * So to overcome typecasting problem and enable to add only one type on data in reference   of set we use generic in Java  --> How to create Generic type in Java    Set<String> hashset=new HashSet<String>();//it will allow to add only String type and while retrieving  no need to perform typecasting . *   if we try to add other then String type then it will compile time error like "The method add(String) in the type Set<String> is not applicable for the arguments (int)" ==============Code of Generic in Collection ================ import java.util.*; publ...