Showing posts with label java io. Show all posts
Showing posts with label java io. Show all posts

Spring Framework Set a File Writable in Java

An example on setting making a file write-able in Java using File class.


Example


import java.io.File;
class SetFileWritable
{
public static void main(String args[])
{

// Create a File object
File f=new File("SetFileWritable.java");

// It is write-able by default. So set it read-only
f.setReadOnly();

// Print whether it is write able
System.out.println("Is file writable (T/F)? "+f.canWrite());

// Make it writable.
f.setWritable(true);

// Print whether it is writable
System.out.println("Is file writable (T/F)? "+f.canWrite());

}
}

Output


Is file writable (T/F)? false
Is file writable (T/F)? true

Also see my previous post, Set a File Read only in Java 

Spring Hibernate Set a File Read only in Java

An example on setting a file as read-only in Java using File class.


Example


import java.io.File;
class SetReadOnly
{
public static void main(String args[])
{

// Create File object
File f=new File("SetReadOnly.java");

// Mark this file read only
f.setReadOnly();

// Alternate method
// f.setReadable(true);

// Set Read only for owner only (2nd argument). If true, read only sets to owner only and not for other users if false read only for all users
// f.setReadable(true,true);

// Check whether it is read-only
System.out.println("Is this file read only (T/F)? "+f.canRead());

}
}

Output


Is this file read only (T/F)? true

Note: To re modify the file, set it to writable. From command prompt, you can use attrib -r SetReadOnly.java 

Spring Hibernate Check if file can be read in Java

An example on checking whether a file can be read or not in Java using File class.


Example


import java.io.File;
class CheckRead
{
public static void main(String args[])
{

// Create a File object
File f=new File("CheckRead.java");

// Check can be Read
System.out.println("Can file be read (T/F)? "+f.canRead());

}
}

Output


Can file be read (T/F)? true

Spring Hibernate How to create folder in Java

2 ways of creating a folder in Java


A tiny and easy example to create a directories in Java with mkdir() and mkdirs() methods.


import java.io.File;
class CreateDirectory
{
public static void main(String args[])
{
// Create a java.io.File object, specify the name of the folder
File f=new File("mydir");

// Create directory with specified name, true is returned if created.
boolean flag=f.mkdir();

// Print whether true/false
System.out.println("Directory created (T/F)? "+flag);
}
}

------------------------------------
Output
------------------------------------
Directory created (T/F)? true

Creating directories & sub directories


For creating directories along with sub directories, you must use mkdirs() method because mkdir() has the capability to create only one dir which does not contain any sub directories. The following example gives you a better understand.

import java.io.File;
class CreateDirs
{
public static void main(String args[])
{
// Create a file object for the following path (all are dirs)
File f=new File("mydir\\subdir\\sub-sub dir");

// Create directories, mydir > subdir > sub-sub dir. True is returned when dirs are created.
boolean flag=f.mkdirs();

// Print true/false
System.out.println("Are dirs created (T/F)? "+flag);

}
}

-------------------------------
Output
-------------------------------
Are dirs created (T/F)? true

J2EE Spring Hibernate Chapter 34: File Navigation and I/O

I/O has had a strange history with the SCJP certification. It was included in all the versions of the exam up to and including 1.2, then removed from the 1.4 exam, and then re-introduced for Java 5 and extended for Java 6.

I/O is a huge topic in general, and the Java APIs that deal with I/O in one fashion or another are correspondingly huge. A general discussion of I/O could include topics such

Spring Framework transient Keyword in Java with Example

transient keyword in Java
transient keyword is a very useful and important keyword that you might have undergone in Serialization. transient keyword is placed in front of a member variable in a class stating that that member variable need not be stored when the object is being stored in a file. To better understand the transient keyword you must be knowledgeable about serialization concept in Java. Once you have completed reading the concept, let us talk about this keyword.

 Sometimes, there is a need that is mandatory to declare a member variable as transient because we know that not all objects can be serialized and only those which are of type Serializable can be i.e. the objects of the classes implementing the java.io.Serializable interface can be stored in a file.

For those members of the classes which cannot be serialized, their state cannot be stored in a file as it is i.e. they lack such capability and hence we might not need them to be stored. So, we'll make them transient.

Consider the following example which gives a better understand of what transient really does.


import java.io.*;
import java.util.*;
class Employee implements Serializable
{
int eno;
String ename;
transient Scanner s;  
    public Employee()
    {
    s=new Scanner(System.in);
    }

    public void read()
    {
    eno=s.nextInt();
    ename=s.next();
    }  

    public void print()
    {
    System.out.println(eno+"  "+ename);
    }
}
class TransientExample
{
    public static void main(String args[])throws Exception
    {

    Employee x=new Employee();
    x.read();

    // Writing part..
    FileOutputStream fout=new FileOutputStream("emp.dat");
    ObjectOutputStream out=new ObjectOutputStream(fout);
    out.writeObject(x);
   
    out.close();
    fout.close();

    // Reading code..  
    FileInputStream    fin=new FileInputStream("emp.dat");
    ObjectInputStream oin=new ObjectInputStream(fin);
    Employee e=(Employee)oin.readObject();

    // Call print()
    e.print();

    oin.close();
    fin.close();
   }
}

Sample Output



101
smith
101  smith

Explanation

java.util.Scanner class is not serializable i.e. it does not implement Serializable interface. So it's state cannot be stored as it is in a file. So it should be made transient so that it is not included while writing the object into a file.


What if the Scanner object is not made transient?

If the Scanner reference (here s) is not made transient, then you'll encounter the following exception.

Exception in thread "main" java.io.NotSerializableException: java.util.Scanner
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)

        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java
:1528)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:14
93)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.jav
a:1416)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)

        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
        at TransientExample.main(TransientExample.java:35)

So you'll need to mention that s is not stored in the file. That's it.

The remaining code is however common and easy to fathom if you are familiar with the serialization tutorial. Drop a comment if you have any doubts related to the keyword transient.

Spring Framework Get File Separator in Java

An example on getting file separator thereby detecting the OS approximately. Single statement.

File Separator Example



import java.io.*;

class GetFileSeparator

{

public static void main(String args[])

{

System.out.println("The file separator is "+File.separatorChar);

}

}

Sample Output



The file separator is \

Note: The file separator depends upon your OS. If windows the above is the output, for linux like OS / is the file separator.

Spring Hibernate Serialization in Java for Beginners

Process of storing the state of object as it is in Java is called Serialization. The java.io.Serializable interface achieves Serialization in Java. The following tutorial explains Serialization in easy way. Let's kickstart.

Understand Better

Storing objects as it is means, storing the values of data member variables (global variables) as it is. Consider,

A simple class.

class emp
{
public int eno;
}

emp e=new emp();
e.eno=101;

Now, the value in eno sets to 101 after the statement e.eno=101 is executed. Now storing the value 101 in a file can be done by making class emp serializable using Serializable interface. The following example achieves this.

Real Time

If you can observe, software save user's settings i.e. when you check or un check a check box, that will be saved . How this could be possible? They either store it in the Registry or in a local file which may be of name settings.dat or something of their wish. So, in order to achieve this, Serialization is used. In fact, in my product Booster+ too, i've used the same technique.

java.io.Serializable interface

public interface java.io.Serializable {
}

An Example on Serialization

1. Create Serializable class (should implement Serializable)

2. Create & store it's object.

import java.io.*;
class Employee implements Serializable
{
public int eno;
public String ename;
public double sal;
}
class WriteSObject
{
public static void main(String args[]) throws Exception
{
Employee e=new Employee();
e.eno=1;
e.ename="Gowtham Gutha";
e.sal=200000.95;

FileOutputStream fout=new FileOutputStream("out.dat");
ObjectOutputStream out=new ObjectOutputStream(fout);

out.writeObject(e);

out.close();
 fout.close();
}

}

Notes: 

1. FileOutputStream points out file where data has be written.

2. ObjectOutputStream points FileOutputStream.

Employee e=new Employee(): Create Employee class object.

e.eno=101;e.ename="Gowtham Gutha";e.sal=200000.95; 
Put values in data member variables of employee class.

out.writeObject(e): Write object 'e' in out.dat

out.close(): Close object output stream.

3. Now, read object & print using System.out.println().

import java.io.*;
class ReadSObject
{
public static void main(String args[]) throws Exception
{
FileInputStream fin=new FileInputStream("out.dat");
ObjectInputStream oin=new ObjectInputStream(fin);

Employee e=(Employee) oin.readObject();

System.out.println("Eno : "+e.eno);
System.out.println("Ename : "+e.ename);
System.out.println("Sal : "+e.sal);
}
}


Notes: 

1. FileInputStream points out.dat (was previously written using FileOutputStream & ObjectOutputStream. See above)

2. ObjectInputStream points FileInputStream.

Employee e= (Employee) oin.readObject(): Read object from out.dat & store in e

3. Print them.

More: All wrapper classes (String, Integer, Double etc) are serializable.

Spring Framework List all Local Drives in Java

An example on getting paths of all local drives in a computer in Java.

Get Local Drive Paths - Example



import java.io.File;

class GetLocalDrives

{

public static void main(String args[])

{

File[] f=File.listRoots();

for(File k:f)

System.out.println(k);

}

}


listRoots(): It is a static method of the java.io.File class and is used to get all the roots (local drives).


Sample Output



C:\

D:\

E:\

F:\

G:\

Spring Framework Search File in Java Recursively

An example recursive logic on searching file like windows search in Java. This logic is much similar to the logic used in deleting folder in Java

Search File in Java - Program



import java.io.*;

import java.util.*;

class JavaSearchFile

{

static Vector<File> v;



public static void main(String args[]) throws Exception

{



// Create a file pointing a folder

File f=new File(args[0]);



// Create a vector of found files

v=new Vector<File>();



// Print the search starting

System.out.println("\nStarting search....\n-------------------------\n");



// Go search args[1] (2nd arg) in dir f

search(f,args[1]);



// Print the found files

print();



}



public static void search(File file,String name)

{





// Print where the search is going on..

System.out.println("Searching in "+file.getAbsolutePath());



// Check if file is directory/folder

if(file.isDirectory())

{





if(file.getName().contains(name))

{



// Add the file to found files vector

v.addElement(file);



}



// Get all files in the folder

File[] files=file.listFiles();





for(int i=0;i<files.length;i++)

{

try

{



if(files[i].isDirectory())

{



// Go search for files if dir

search(files[i],name);



}



else

{



if(files[i].getName().toLowerCase().contains(name.toLowerCase()))

{



// Add the found file to vector

v.addElement(files[i]);



}



}



}catch(Exception e){}



}



}



}



public static void print()

{



// Create a file array of v size

File[] f=new File[v.size()];



// Copy vector data into f

v.copyInto(f);



// Print the results

System.out.println("\nResults");

System.out.println("------------------------------------------");



// Loop till end of size

for(File k:f)

{



// Print the file path

System.out.println("Found at "+k.getAbsolutePath());



}



}



}

Sample Output



Starting search....

-------------------------



Searching in f:\songs

Searching in f:\songs\A R Rahman - Superheavy

Searching in f:\songs\Agneepath

Searching in f:\songs\Aisha

Searching in f:\songs\Alex Clare

Searching in f:\songs\Anandam

Searching in f:\songs\Anandam\covers

Searching in f:\songs\Andala Rakshasi

Searching in f:\songs\Anjaana Anjaani

Searching in f:\songs\Annadammula Anubandham

Searching in f:\songs\Annadammula Anubandham\artwork

Searching in f:\songs\Awaara

Searching in f:\songs\Barfi!

Searching in f:\songs\Bharateyudu

Searching in f:\songs\Bodyguard

Searching in f:\songs\Brothers (2012)

Searching in f:\songs\Cameraman Ganga Tho Rambabu

Searching in f:\songs\Cheli

Searching in f:\songs\Dabangg 2

Searching in f:\songs\Damarukam

Searching in f:\songs\Delhi 6

Searching in f:\songs\Devudu Chesina Manushulu

Searching in f:\songs\Dhenikaina Ready

Searching in f:\songs\Emraan Hits

Searching in f:\songs\Emraan Hits\covers

Searching in f:\songs\English

Searching in f:\songs\Enrique Iglesias

Searching in f:\songs\fifa

Searching in f:\songs\Flo Rida

Searching in f:\songs\Fun

Searching in f:\songs\Gabbar Singh

Searching in f:\songs\Gangnam Style (?????)

Searching in f:\songs\Ghajini

Searching in f:\songs\Ghatikudu

Searching in f:\songs\Gotye

Searching in f:\songs\i hate love stories

Searching in f:\songs\Jaane Tu Ya Jaane Na

Searching in f:\songs\Jab Tak Hai Jaan

Searching in f:\songs\Jhootha Hi Sahi

Searching in f:\songs\Johnny

Searching in f:\songs\Julayi

Searching in f:\songs\Justin Bieber

Searching in f:\songs\KIKK

Searching in f:\songs\Krishnam Vande Jagadgurum

Searching in f:\songs\Linkin Park - Project Revolution

Searching in f:\songs\Love To Love

Searching in f:\songs\Love To Love\Love To Love (2012) ~128Kbps

Searching in f:\songs\Maroon 5

Searching in f:\songs\Melody

Searching in f:\songs\Mr. Perfect

Searching in f:\songs\Nene Ambani

Searching in f:\songs\Ninnu Choosthe Love Vasthundi

Searching in f:\songs\Nirantharam Nee Oohale

Searching in f:\songs\Ok Ok

Searching in f:\songs\Orange

Searching in f:\songs\Orange\artwork

Searching in f:\songs\Other Stuff

Searching in f:\songs\Pitbull

Searching in f:\songs\Power

Searching in f:\songs\Prema Desam

Searching in f:\songs\Premikudu

Searching in f:\songs\Premikula Roju

Searching in f:\songs\Raghavan

Searching in f:\songs\Routine Love Story

Searching in f:\songs\Sakhi

Searching in f:\songs\Sarocharu

Searching in f:\songs\Surya Krishnan

Searching in f:\songs\Surya Krishnan\Surya SO Krishnan-320kbps

Searching in f:\songs\Talaash

Searching in f:\songs\Taylor Swift

Searching in f:\songs\Teri Meri Kahaani

Searching in f:\songs\The Official UK Top 40 Singles Chart 15-07-2012

Searching in f:\songs\Thuppakki

Searching in f:\songs\Unnale Unnale

Searching in f:\songs\Vaasu_2002_320VBR

Searching in f:\songs\Vaasu_2002_320VBR\Vaasu (2002) ~ 320 VBR

Searching in f:\songs\Vicky Donor

Searching in f:\songs\Vicky.Donor

Searching in f:\songs\Vilan

Searching in f:\songs\Viswaroopam

Searching in f:\songs\Westlife

Searching in f:\songs\Yeto Vellipoyindhi Manasu



Results

------------------------------------------

Found at f:\songs\English\Whistle.mp3

Found at f:\songs\The Official UK Top 40 Singles Chart 15-07-2012\06 Flo Rida -

Whistle.mp3

Spring Hibernate How to Remove Directory in Java easily

Simple way to Delete a Folder in Java


One of the easiest ways to delete a folder is to apply a smart logic. When you have got it into an idea, you will have to immediately recall that it is 'repeat' what can make the things go. Well, if i want to delete a folder, then all i need to do is to delete all the files in it including the folders and finally the folder itself. Here i have written a simple method and also explained how-to delete a folder in Java.


import java.io.*;

class JavaDeleteAFolder
{
public static void main(String args[]) throws Exception
{
// Create a file pointing a folder
File f=new File("myfolder");

// Delete the folder
delete(f);
}
public static void delete(File file)
{

// Check if file is directory/folder
if(file.isDirectory())
{
// Get all files in the folder
File[] files=file.listFiles();

for(int i=0;i<files.length;i++)
{

// Delete each file in the folder
delete(files[i]);

}

// Delete the folder
file.delete();

}


else
{

// Delete the file if it is not a folder
file.delete();

}
}
}

delete(File file): This is what the method i have written. This method takes a file object.

What it does with the file object?

  • It checks whether the given file object points to a folder (directory) or just a normal file.
  • If the above condition is not satisfied, then the file is not a folder and is just a normal file.
What if the file is a directory?

  • List all the files in the directory using file.listFiles() which will return an array of all the files (including sub-folders) in the folder that the file object points out to.
  • Write a for-loop and then, call the delete(File file) method again. Again, this method checks if the file is a directory or not. If it is then things go from the starting of the above point. If it is just a normal file, then it will simply be deleted using the delete() method in the java.io.File
  • After all the files in the folder were deleted, delete the folder itself.

Spring Framework Check whether a file is a directory or file

An example on checking whether a file is directory or a normal file in Java using Java IO.


Check now!


import java.io.*;
class CheckFile
{

public static void main(String args[])
{
// Create a file object for a [directory (here)]
File file=new File("C:/java");

// If file is a directory
if(file.isDirectory())

// Print then.
System.out.println(file.getName()+" is a directory");

// If not a directory, then obviously a file
else System.out.println(file.getName()+" is a file");

/* You can alternatively use.. */

// Check if file object represents a normal file
if(file.isFile())

// Print then.
System.out.println(file.getName()+" is a file");

// If not a file, then will be a dir
else System.out.println(file.getName()+" is a directory");
}

}

Output


java is a directory
java is a directory

Any of the two methods can be used.

Also see my post on Removing a directory in Java easily

Spring Framework Remove File extension in Java

An example logic on filtering the name of the file without extension in Java using String Handling and Java IO


Let's Filter


import java.io.*;
class RemoveExt
{
public static void main(String args[])
{

// Create a File object for C:\java
File f=new File("C:/java");

// Get all the files in a directory
File[] files=f.listFiles();

// Loop till end of all files
for(File t:files)
{
// Go inside only if file object t is not a directory
if(!t.isDirectory())
{
// Get the name of the file t
String name=t.getName();

// If name has an extension..
if(name.contains("."))
{

// Filter the name without extension
String extRemoved=name.substring(0,name.lastIndexOf('.'));

// Print the name with & without extension
System.out.println("Extension removed for "+name+" and it's now "+extRemoved);

}

}

}

}

}

For renaming the file:  You can use renameTo(File dest_file) method in the File class pointing the extRemoved [See above], this method should be called on the source file and the parameter is the complete path of the file that you were to rename.

Also see my post on Getting file extension in Java

Spring Framework Get Extension of a File in Java

An example logic on getting and printing extension of a file in Java using String handling and Java IO.


Example


// Import for File class
import java.io.*;

class GetFileExt
{

public static void main(String args[])
{

// Create a file object for directory C:\java
File f=new File("C:/java");

// List all the files in the directory, get their File objects.
File[] files=f.listFiles();

// Loop till end of all files
for(int i=0;i<files.length;i++)
{

// Get the name of each file
String name=files[i].getName();

// File should not be a directory, and file should have an extension [this logic also filters folders containing .]
if(!files[i].isDirectory())
{

if(name.contains("."))
{

// Print the name of the file, and the extension
System.out.println("Extension for "+name+" is "+name.substring(name.lastIndexOf('.'),name.length()));

}

}

}
}

}

Main Logic


lastIndexOf('.'): This method present in the String class returns the last index of the character '.'. For example, if a file name is like file.n.ex then the lastIndexOf('.') will return, 6 but not 4. It is obvious.

substring(name.lastIndexOf('.'),name.length()): The substring method present in the String class, takes start and end positions as parameters, this method returns a string between the start and end parameters. Here, name consists of extension too. So, the last index of '.' is the first (start) parameter and name.length() means end of the string is the end parameter. So, it is obvious that the extension is filtered.

Also see my other posts on Deleting all the files in a folder in Java, for help with lastIndexOf() method see my post lastIndexOf String and Character in Java Example

Spring Hibernate Open a File in Java - 3 Effective Ways to Achieve

Being the platform for developing almost anything that you dream of, opening a file in Java is just a tiny thing infront of it and you can easily achieve this using the Runtime, ProcessBuilder and the Desktop classes. These are the 3 effective ways that i can suggest for you to open external files in Java.


import java.awt.*;
import java.io.*;
class OpenAFile
{
public static void main(String args[]) throws Exception
{

// First way. Using the java.lang.Runtime class

// Create a Runtime object
Runtime r=Runtime.getRuntime();
// Open a file
r.exec("notepad.exe OpenAFile.java");

// Second way. Using the java.lang.ProcessBuilder class


// Create a ProcessBuilder object
ProcessBuilder pb=new ProcessBuilder("notepad","OpenAFile.java");

// Start opening the file
pb.start();

// Third way. Using the java.awt.Desktop class

// Get a Desktop object
Desktop dk=Desktop.getDesktop();

// Open a file
dk.open(new File("OpenAFile.java"));

}
}



Runtime class: Runtime class is in the java.lang package. This class contains the exec(String file) method which is capable of executing (not opening) a file i.e. it can open applications instead of normal files that do depend on other applications to be opened. So, in order to open a normal file using this, we can specify the command line parameters as shown in the above example. This is simple, all you need to do is to first specify the, path and the file name of the application that you are going to open a file with followed by a space and then the complete path and the name of the file.  Here in the above example, i opened the same program which is in the same directory, the notepad too as is a system pre-built application it can easily be accessed with its name and there is no need to specify it's complete path as it (the path) was already specified in the Environment Variables of Windows Operating System. If it is a new application, then you must place the entire path of the application program followed by a space and then the path of the file that you are going to open.

r.exec("notepad.exe OpenAFile.java"): The method takes a string which points the path of the program that is to be executed. Here, i want to execute notepad.exe and with this application i want to open OpenAFile.java so i specified it as an argument for the application.

ProcessBuilder class: Unlike the Runtime class, ProcessBuilder class is quite efficient because the method in it takes 2 parameters (here), the first one is the application and the next one is the file that is to be opened with the specified application.

Desktop: The last class, is the most efficient of all. If your program is to execute in an entirely new system, and don't know what applications it has or what applications can open a file. You can use java.awt.Desktop class to open a file.

Desktop.getDesktop(): This returns an object of the Desktop class.

dk.open(new File("OpenAFile.java")): This method takes a file which takes a string that points a normal file (not an application) and opens it with the default application associated with that file type. Looks more efficient! :)

throws Exception: As we are using a File in the open method discussed above, the method throws an IOException if the file may not be granted for reading or opening purpose.

Spring Hibernate Using Java FileReader to Read a File

Java FileReader in character streams used to read files in the same way as in FileOutputStream. Instead of bytes we use characters. The Java FileReader example below demonstrates it.



import java.io.FileReader;
import java.io.File;
class JavaFileReader
{
public static void main(String args[]) throws Exception
{

// Create File object for JavaFileReader.java
File f=new File("JavaFileReader.java");

//---------First way--------//

// Create FileReader object
FileReader fr=new FileReader(f);

// Create a char array of file length
char[] c=new char[(int)f.length()];

// Dump data into char array c
fr.read(c);

System.out.println("\n\nFirst way\n");

// Print the data
for(int i=0;i<c.length;i++)
{
System.out.print(c[i]);
}

// Close FileReader
fr.close();

//---------Second way--------//

// Create FileReader object
FileReader fr1=new FileReader(f);

// Create char array of file length
char[] c1=new char[(int)f.length()];

// Dump from 0 to end into c1
fr1.read(c1,0,c1.length);

System.out.println("\n\nSecond way\n");

for(int i=0;i<c1.length;i++)
{
// Print every character
System.out.print(c1[i]);
}

// Close FileReader
fr1.close();

//---------Third way--------//

// Create FileReader object
FileReader fr2=new FileReader(f);

// An integer whose initial value is 0
int k;

System.out.println("\n\nThird way\n");

// Read and store in k till end of file
while((k=fr2.read())!=-1)
{
// Print what is read
System.out.print((char)k);
}

// Close the FileReader
fr2.close();

}
}
why f.length(): As in the FileInputStream, there is no method like available() in the FileReader class. So, we have used the f.length() and to obtain it we need to create a java.io.File Object.

fr.read(c): This method dumps the entire data that the java.io.FileReader points into the char array 'c'.

fr.read(c1,0,c1.length): This method dumps the entire data that the java.io.FileReader points, into the char array 'c1' from the start position '0' till the end position 'c1.length' (nothing but the end of the file).

(k=fr2.read())!=-1: This method, reads each character from the file (JavaFileReader.java) at a time and store in an integer called 'k' whose initial value is '0' (because it is Java! :)) . After the value read is stored in 'k' , the System.out.print() method is called instead of println() (which prints in a new line) because we don't want each character in a new line instead we want the file as it is. This prints the value of 'k' ( to print the char, k is converted into char type).

---------------------------------------
Output
---------------------------------------


First way

import java.io.FileReader;
import java.io.File;
class JavaFileReader
{
        public static void main(String args[]) throws Exception
        {

// Create File object for JavaFileReader.java
        File f=new File("JavaFileReader.java");

//---------First way--------//

// Create FileReader object
        FileReader fr=new FileReader(f);

// Create a char array of file length
        char[] c=new char[(int)f.length()];

// Dump data into char array c
        fr.read(c);

        System.out.println("\n\nFirst way\n");

        // Print the data
                for(int i=0;i<c.length;i++)
                {
                System.out.print(c[i]);
                }

        // Close FileReader
        fr.close();

//---------Second way--------//

        // Create FileReader object
        FileReader fr1=new FileReader(f);

        // Create char array of file length
        char[] c1=new char[(int)f.length()];

        // Dump from 0 to end into c1
        fr1.read(c1,0,c1.length);

        System.out.println("\n\nSecond way\n");

                for(int i=0;i<c1.length;i++)
                {
                // Print every character
                System.out.print(c1[i]);
                }

        // Close FileReader
        fr1.close();

//---------Third way--------//

// Create FileReader object
        FileReader fr2=new FileReader(f);

// An integer whose initial value is 0
        int k;

        System.out.println("\n\nThird way\n");

// Read and store in k till end of file
                while((k=fr2.read())!=-1)
                {
                // Print what is read
                System.out.print((char)k);
                }

        // Close the FileReader
        fr2.close();

        }
}

Second way

import java.io.FileReader;
import java.io.File;
class JavaFileReader
{
        public static void main(String args[]) throws Exception
        {

// Create File object for JavaFileReader.java
        File f=new File("JavaFileReader.java");

//---------First way--------//

// Create FileReader object
        FileReader fr=new FileReader(f);

// Create a char array of file length
        char[] c=new char[(int)f.length()];

// Dump data into char array c
        fr.read(c);

        System.out.println("\n\nFirst way\n");

        // Print the data
                for(int i=0;i<c.length;i++)
                {
                System.out.print(c[i]);
                }

        // Close FileReader
        fr.close();

//---------Second way--------//

        // Create FileReader object
        FileReader fr1=new FileReader(f);

        // Create char array of file length
        char[] c1=new char[(int)f.length()];

        // Dump from 0 to end into c1
        fr1.read(c1,0,c1.length);

        System.out.println("\n\nSecond way\n");

                for(int i=0;i<c1.length;i++)
                {
                // Print every character
                System.out.print(c1[i]);
                }

        // Close FileReader
        fr1.close();

//---------Third way--------//

// Create FileReader object
        FileReader fr2=new FileReader(f);

// An integer whose initial value is 0
        int k;

        System.out.println("\n\nThird way\n");

// Read and store in k till end of file
                while((k=fr2.read())!=-1)
                {
                // Print what is read
                System.out.print((char)k);
                }

        // Close the FileReader
        fr2.close();

        }
}

Third way

import java.io.FileReader;
import java.io.File;
class JavaFileReader
{
        public static void main(String args[]) throws Exception
        {

// Create File object for JavaFileReader.java
        File f=new File("JavaFileReader.java");

//---------First way--------//

// Create FileReader object
        FileReader fr=new FileReader(f);

// Create a char array of file length
        char[] c=new char[(int)f.length()];

// Dump data into char array c
        fr.read(c);

        System.out.println("\n\nFirst way\n");

        // Print the data
                for(int i=0;i<c.length;i++)
                {
                System.out.print(c[i]);
                }

        // Close FileReader
        fr.close();

//---------Second way--------//

        // Create FileReader object
        FileReader fr1=new FileReader(f);

        // Create char array of file length
        char[] c1=new char[(int)f.length()];

        // Dump from 0 to end into c1
        fr1.read(c1,0,c1.length);

        System.out.println("\n\nSecond way\n");

                for(int i=0;i<c1.length;i++)
                {
                // Print every character
                System.out.print(c1[i]);
                }

        // Close FileReader
        fr1.close();

//---------Third way--------//

// Create FileReader object
        FileReader fr2=new FileReader(f);

// An integer whose initial value is 0
        int k;

        System.out.println("\n\nThird way\n");

// Read and store in k till end of file
                while((k=fr2.read())!=-1)
                {
                // Print what is read
                System.out.print((char)k);
                }

        // Close the FileReader
        fr2.close();

        }
}

Spring Hibernate Java FileWriter Example - 3 Ways to Write a File

The java.io.FileWriter is useful to work with characters directly instead of bytes. All the Writer and the Reader classes in Java are treated as Character Streams.

java.io.FileWriter is sub class of OutputStreamWriter which contains the overloaded methods, write(int c), write(char[] c),write(char[] c, int start, int end). These methods help in writing data to a file. Note that here, the method is taking char[] instead of byte[] as in the FileOutputStream (FileOutputStream is a sub-class of OutputStream).


import java.io.FileWriter;
class FileWriterExample
{
public static void main(String args[]) throws Exception
{
// The string to be written
String st="I will be in the file using FileWriter class.";
// Convert st to array
char[] c=st.toCharArray();

// First way
// FileWriter object
FileWriter fw=new FileWriter("output.txt");
// Write the char array
fw.write(c);
// Close FileWriter
fw.close();
// Second way
FileWriter fw1=new FileWriter("output1.txt");
// Write from 0 to end
fw1.write(c,0,c.length);
// Close fw1
fw1.close();
// Third way
FileWriter fw2=new FileWriter("output2.txt");
for(int i=0;i<c.length;i++)
{
fw2.write(c[i]);
}
// Close fw2
fw2.close();
}
}

Spring Hibernate Write to a File in Java IO - 3 Simple Ways

Write to a File in Java IO is easy to do with the three little methods different from each other in FileOutputStream class does the thing. Here is a Java Tutorial to achieve this.


import java.io.*;
class FileWrite
{
public static void main(String args[]) throws Exception
{
// Create a string to write to
String st="I am going to be written in the file.";
// First way
// Create FileOutputStream object
FileOutputStream fout=new FileOutputStream("output.txt");
// Convert string to bytes
byte[] b=st.getBytes();
// Write the byte array
fout.write(b);
// close fout
fout.close();
// Second way
FileOutputStream fout1=new FileOutputStream("output1.txt");
// Convert string to char array
char[] c=st.toCharArray();
for(int i=0;i<c.length;i++)
{
fout1.write(c[i]);
}
fout1.close();
// Third way
FileOutputStream fout2=new FileOutputStream("output2.txt");
byte[] b1=st.getBytes();
fout2.write(b1,0,b1.length);
fout2.close();
}
}
String st: The string which will be written in the file.
getBytes(): Convert the string into a byte array that contains ascii values of each character in the string in order.
fout.write(b): Write the byte array to the file output.txt because fout points to that file only.
toCharArray(): Convert the string to char array of length of the string and containing all the characters in the string in order.
fout1.write(c[i]): Write each character in the string to the file. The method take int, but the char is automatically treated as int i.e. the ascii value will be sent and then be written to output1.txt
fout2.write(b1,0,b1.length): Write the byte array from index '0' till the length of the array i.e. till the end. You can alternatively, write partially by specifying the start and the end index in the last two parameters of the method that we are discussing in this paragraph.

Spring Hibernate 3 Ways to Read a File using FileInputStream in Java IO

Reading a file in Java IO (streams) with FileInputStream is much easier than what you think of. Here are 3 effective ways you can use to achieve it.The sample tutorial decides and simplifies doing the task.


import java.io.*;
class ReadAndPrintFile
{
public static void main(String args[]) throws Exception
{
//---------------------------First way-------------------------//
FileInputStream fin=new FileInputStream("ReadAndPrintFile.java");
// Create a byte array
byte[] b=new byte[fin.available()];
// Read data into the array
fin.read(b);
for(int i=0;i<b.length;i++)
{
System.out.print((char)b[i]);
}
//---------------------------Second way-------------------------//
int k=0;
FileInputStream fin1=new FileInputStream("ReadAndPrintFile.java");
System.out.println("\n\nSecond way\n");
// Read till the end of file
while((k=fin1.read())!=-1)
{
System.out.print((char)k);
}
//---------------------------Third way-------------------------//
FileInputStream fin2=new FileInputStream("ReadAndPrintFile.java");
byte b1[]=new byte[fin2.available()];
fin2.read(b1,0,b1.length);
System.out.println("\n\nThird way\n");
for(int i=0;i<b1.length;i++)
{
System.out.print((char)b1[i]);
}

// Close the document
fin.close();
fin1.close();
fin2.close();
}
}
fin.read(b): Dump the entire data that is read into the byte array which is stored in RAM.
(k=fin.read())!=-1: Reading each byte from the file starting from the index '0' till the end of the file. If  end of the file is reached the fin.read() will return -1.
fin.read(b1,0,b1.length): The first parameter is the byte array in which the data should be dumped into, the second parameter is the start-index of the file, that is from which the dumping should start, the last parameter is the index. Here i'm saying to dump till the end of the file i.e. the entire file is dumped as i am specifying '0' as start and 'b1.length' as last index which is equal to fin.available().

-------------------------------------
Output
-------------------------------------

import java.io.*;
class ReadAndPrintFile
{
        public static void main(String args[]) throws Exception
        {

//---------------------------First way-------------------------//
        FileInputStream fin=new FileInputStream("ReadAndPrintFile.java");

        // Create a byte array
        byte[] b=new byte[fin.available()];

        // Read data into the array
        fin.read(b);

                for(int i=0;i<b.length;i++)
                {
                System.out.print((char)b[i]);
                }

//---------------------------Second way-------------------------//

        int k=0;

        FileInputStream fin1=new FileInputStream("ReadAndPrintFile.java");
        System.out.println("\n\nSecond way\n");
                // Read till the end of file
                while((k=fin1.read())!=-1)
                {
                        System.out.print((char)k);
                }

//---------------------------Third way-------------------------//

        FileInputStream fin2=new FileInputStream("ReadAndPrintFile.java");
        byte b1[]=new byte[fin2.available()];
        fin2.read(b1,0,b1.length);

        System.out.println("\n\nThird way\n");
                for(int i=0;i<b1.length;i++)
                {
                System.out.print((char)b1[i]);
                }


        // Close the document
        fin.close();
        fin1.close();
        fin2.close();
        }
}

Second way

import java.io.*;
class ReadAndPrintFile
{
        public static void main(String args[]) throws Exception
        {

//---------------------------First way-------------------------//
        FileInputStream fin=new FileInputStream("ReadAndPrintFile.java");

        // Create a byte array
        byte[] b=new byte[fin.available()];

        // Read data into the array
        fin.read(b);

                for(int i=0;i<b.length;i++)
                {
                System.out.print((char)b[i]);
                }

//---------------------------Second way-------------------------//

        int k=0;

        FileInputStream fin1=new FileInputStream("ReadAndPrintFile.java");
        System.out.println("\n\nSecond way\n");
                // Read till the end of file
                while((k=fin1.read())!=-1)
                {
                        System.out.print((char)k);
                }

//---------------------------Third way-------------------------//

        FileInputStream fin2=new FileInputStream("ReadAndPrintFile.java");
        byte b1[]=new byte[fin2.available()];
        fin2.read(b1,0,b1.length);

        System.out.println("\n\nThird way\n");
                for(int i=0;i<b1.length;i++)
                {
                System.out.print((char)b1[i]);
                }


        // Close the document
        fin.close();
        fin1.close();
        fin2.close();
        }
}

Third way

import java.io.*;
class ReadAndPrintFile
{
        public static void main(String args[]) throws Exception
        {

//---------------------------First way-------------------------//
        FileInputStream fin=new FileInputStream("ReadAndPrintFile.java");

        // Create a byte array
        byte[] b=new byte[fin.available()];

        // Read data into the array
        fin.read(b);

                for(int i=0;i<b.length;i++)
                {
                System.out.print((char)b[i]);
                }

//---------------------------Second way-------------------------//

        int k=0;

        FileInputStream fin1=new FileInputStream("ReadAndPrintFile.java");
        System.out.println("\n\nSecond way\n");
                // Read till the end of file
                while((k=fin1.read())!=-1)
                {
                        System.out.print((char)k);
                }

//---------------------------Third way-------------------------//

        FileInputStream fin2=new FileInputStream("ReadAndPrintFile.java");
        byte b1[]=new byte[fin2.available()];
        fin2.read(b1,0,b1.length);

        System.out.println("\n\nThird way\n");
                for(int i=0;i<b1.length;i++)
                {
                System.out.print((char)b1[i]);
                }


        // Close the document
        fin.close();
        fin1.close();
        fin2.close();
        }
}

Spring Hibernate Using file.exists() to check the existence of a File in Java IO

Checking the existence of a file is easy in Java and is a method behind. The file.exists() method in java.io.File does the thing. Here is a sample tutorial.


import java.io.*;
class FileExistence
{
public static void main(String args[])
{
File f=new File("myfile.txt");
// Print the name
System.out.println("The name of the file is "+f.getName());
// Does the file exist
System.out.println("Does the file exist? "+f.exists());
}
}
f.exists(): Check the existence of a file. If the file is present, it returns true else it returns false.

-----------------------------------
Output
-----------------------------------
The name of the file is myfile.txt
Does the file exist? false

MPVWCWTNM4YU

Labels

.equals = operator abstract class abstract method abstract window toolkit Access Modifiers accessing java beans accessing javabeans action events actionperformed active addition Advanced Advanced Overloading AdvJavaBooks Agile development ajax alive AMQP and Android anonymous class anonymous inner class Ant ant tutorials anti patterns antipatterns Apache Camel api for jsp api for servlet api for servlets api jsp application context application scope application session Apps Architecture are you eligible for the ocmjd certificaiton are you eligible for the scjd certification arithmetic operator arpanet array construction array declaration array initialization array list array to list conversion arraylist arraylist of strings arraylist of types arraylist questions arraylists Arrays arrays in java ask for help assert assert in java assertions assertions in java assignment assignment operator Atlassian attribute visibility authentication authorization autoboxing autounboxing awt AWT Event Handling awt interview questions AWT Layouts awt questions awt questions and answers backed collection backed collections Basic Basics of event handling bean attributes bean properties bean scope Beginner best practices BigData blocked books boxing buffer size bufferedreader bufferedwriter business delegate business delegate pattern calendar case statement casting in java casting interview questions chapter review choosing a java locking mechanism choosing a locking mechanism choosing a thread locking mechanism class inside a method class questions class with no name class without a name classes interview questions Clipboard closing jsp tags code snap coding cohesion collection generics collection interview questions collection methods collection of types collection questions collection searching collection types Collections Collections Framework collections interview questions collections sorting colors in java swings colors in swing command line arguments communication between threads comparable comparator comparison operators compiling java classes computers concurrency example and tutorial config Configuration ConnectionPooling constructor creation constructor interview questions constructor overloading constructors in java containers contents of deployment descriptor contents of web.xml context context scope converting array to list converting list to array core java core java interview core java interview question core java interview questions core java questions core java; core java; object oriented programming CoreJava CoreJavaBooks CORS coupling create threads creating 2 dimensional shapes creating 2D shapes creating a frame creating a jframe creating a thread creating an arraylist creating an inner class creating an interface creating java beans creating java threads creating javabeans creating threads creating threads in java CSS cURL currency current thread determination custom tag library custom taglib custom taglibs custom tags CVS dao dao design pattern dao factory pattern dao pattern data access object data access object pattern data structure and algorithm database date and time tutorial date format dateformat dates deadlock deadlocks debugging Declarations decorator pattern decrement default deleting sessions deploy web app deployment deployment descriptor deployment descriptor contents deployment of web application deserialization deserialize design pattern design pattern interview questions design patterns Designpatterns destory method destroy destroying sessions determining current thread determining the current thread Developer Differences different types of collections display stuff in a frame displaying images displaying images in java swings displaying images in swings displaying text in a component division do while loop doget dohead dopost doput DOS Downloads drawing a line drawing an ellipse drawing circles drawing ellipses drawing lines Drools tutorial eBooks Eclipse Eclipse Tutorial Encapsulation encapsulation in java enhanced for loop entity facade pattern enumerations enumerations in java enums equal to equals equals comparison error and exception error codes error handling in servlets error page event handling in swings event listeners exam prep tips example servlet Examples exception exception handling exception handling in servlets exception handling interview questions exception handling questions Exceptions exceptions in java exceptions in web applications explicit locking explicit locking of objects file file navigation filereader filewriter final class final method FireBug first servlet FIX protocol FIX Protocol interview questions FIX protocol tutorial font fonts for each loop for loop form parameters form values formatting forwarding requests frame frame creation frame positioning frame swings front controller front controller design pattern front controller pattern fundamental.Java FXML Games garbage collection garbage collection interview questions garbage collection questions garbage collector gc gc questions general generic Generics generics collections Geo get get set methods getattribute getting bean property getting form values getting form values in servlet getting scwcd certified getting servlet initialization parameters getting sun certified Google Graphics2D gregorian calendar handling strings in java hash hash map hash table hashcode hashmap hashset hashtable head head request HeadFirst heap heaps hibernate hibernate interview questions hibernate interview questions and answers hibernate questions hibernate questions and answers Hibernate Tutorial HibernateBooks homework How To HTML HTML and JavaScript html form http request http request handling http request header http request methods http request servlet http request type http session httprequest httprequest methods httpservlet httpservlet interview questions httpservlet interview questions with answers httpsession httpsession interview questions httpsession questions HttpSessionActivationListener HttpSessionAttributeListener HttpSessionBindingListener if if else if else block if else statement Image IO implementing an interface Implicit objects increment info inheritance inheritance in java init init method Initialization Blocks inner class inner class inside a method inner classes innerclass installation instanceof instanceof operator IntelliJ interaction between threads interface interface interview interface questions interfaces interfaces in java interfaces interview questions internet history interrupting a thread interrupting threads Interview interview questions interview questions on design patterns interview questions on exception handling interview questions on java collections interview questions on serialization introduction to java threads introduction to jsps introduction to threading introduction to threads invalidating session Investment Banking IO Package iscurrentthread iterator J2EE j2ee api j2ee design pattern j2ee design pattern interview questions j2ee design patterns j2ee hibernate interview questions j2ee history j2ee interview j2ee interview questions j2ee mvc j2ee mvc pattern j2ee programmer j2ee questions j2ee servlet api j2ee session j2ee struts interview questions java java 5 tutorial Java 8 java arrays java assertions java assignments java awt questions java bean java bean scope java beans java beginners tutorial Java career java certification Java Class java collection interview questions and answers java collection tutorial java collections java collections interview questions java constructors java currency Java CV java data base connectivity java database connectivity java database connectivity interview questions and answers java dates java design pattern java design patterns java developer certification Java EE java encapsulation java enums java event listeners java exceptions java formatting java garbage collection java garbage collector java gc java heap Java I/O java inheritance java input output Java Interface Java Interview Java Interview Answers Java Interview Questions Java Introduction java io java IO tutorial java iterator java jdbc Java JSON tutorial Java Key Areas java lists java literals java locks nested Java Media Framework java methods java multithreading Java multithreading Tutorials java nested locks java networking tutorial java numbers Java Objects java operators java overloading java parsing Java Programming Tutorials java race conditions java regex java regular expressions Java resume java scjp java searching java serialization java server pages java server pages api java server pages questions java spring interview questions. j2ee spring interview questions java stack java strings java swing java swing event listeners java swing frame java swing images java swings java swings images java thread explicit locking java thread lock scope java thread locking java thread locking mechanism java thread locking objects java threads java threads race condition java tips java tokenizing Java Tools Java Tutorial java ui questions Java Utilities java variables java wrappers Java xml tutorial java.lang java8 javabean javabean accessing javabean scope JavaBeans javac JavaEE JavaFX JavaFX 3D JavaFX 8 JavaOne JavaScript JavaTips JDBC jdbc driver jdbc example jdbc interview questions jdbc interview questions and answers jdbc interview questions with answers jdbc sample code JDBC Tutorial jdbc type 1 driver jdbc type 2 driver jdbc type 3 driver jdbc type 4 driver Jdeveloper JDK JDK8 JEE Tutorial jframe jframe creation jframe position jframe positioning JIRA JMeter JMS JMX join() joining threads JPA JQuery JS JSF JSF Tutorial JSONP JSP jsp and java beans jsp and servlets jsp and xml jsp api jsp code jsp compilation jsp conversion jsp directives jsp error page jsp error page directive jsp implicit objects jsp interview jsp interview questions jsp introduction jsp intvw questions jsp life jsp life cycle jsp life-cycle jsp lifecycle jsp page directive jsp questions jsp sample jsp scripting jsp scriptlets jsp servlets jsp summary jsp synopsis jsp tag libraries jsp tag library jsp taglib jsp tags jsp technology jsp to servlet jsp to servlet conversion jsp translation jsp usage jsp usebean jsp xml tags jsp xml tags usage jsp-servlet jsp:getProperty jsp:setProperty jsp:usebean jsps JSTL JUnit testing keyword synchronized keyword volatile Keywords Lambda Expressions Learning libraries life cycle life cycle of a jsp life cycle of a servlet life cycle of a thread life cycle of jsp life cycle of threads lifecycle of a thread linked list linkedhashmap linkedhashset linkedlist linux List listeners lists Literals locale lock manager pattern lock scope locking objects using threads log Logging logging errors logical and logical operators logical or loops loosely coupled making an arraylist making threads sleep making threads sleep for time MapReduce maps maps usage Maven Maven Tutorial max priority member access method arguments method local inner class method overloading method overriding method return types methods creating classes min priority Miscellaneous mobile mock exam model view controller model view controller design pattern model view controller pattern Multi Threading Multi-threading multiple threads multiplication multithreading multithreading in java multithreading interview questions multithreading questions mvc mvc design pattern mvc pattern MyEclipse mysql nested java lock nested java locks nested java thread locks nested locks nested thread locks NetBeans Networking new news nio NonAccess Modifiers norm priority normal inner class Normalization not equal to Notepad notify notifyall number format numberformat numbers object comparison object notify object orientation object oriented object oriented programming Object Oriented Programming in java objects interview questions ocmjd certification ocmjd certification eligibility OO OO Java oops OpenCSV OpenCV opening jsp tags OpenJDK OpenJFX Operators or Oracle Oracle ADF Mobile Oracle Certified Exams oracle certified master java developer oracle database ORM other topics out overloading overloading constructors overloading in java overriding page page directive page scope parsing passing variables passing variables to methods performance Platform Playing with Numbers points to remember polymorphism positioning a frame post practice exam Primitive Casting primitive variables printwriter priority queue priority queues priorityqueue priorityqueues private processing form values Products programming Projects protected public put questions questions on garbage collection questions on java strings queue quick recap quick review race conditions read objects from stream reading http request header RealTime_Tips redirecting to another servlet redirection reference reference variable casting reference variables Refreshing Java regex Regular Expressions regular inner class relational operators reminder request request dispatcher request forwarding request header request object. httpservletrequest request scope requestdispatcher response RESTClient RESTful retrieving values from session return error codes return types returning values runnable runnable interface running running java programs RUP sample jsp sample questions sample questions scwcd sample servlet scanner Scene Builder scjd certification scjd certification eligibility requirements scjp SCJP Certification scjp exam scjp exam questions scjp exam sample questions scjp questions scjp test scjp test questions scope scope of java locks scope of java thread locks scope of locks scripting in jsp scriptlet tags scriptlets scriptlets in jsp pages scwcd scwcd certification scwcd certification practice exam scwcd exam scwcd exam questions scwcd jsp summary scwcd mock exam scwcd mock exam answers scwcd practice exam scwcd practice test scwcd questions scwcd test SDLC searching searching arrays searching collections searching in java searching treemap searching treesets security self assement self assement scwcd self assessment scjp self test self test scjp self test scwcd send error method senderror method sending error code to browser serialization serialization in java serialization interview questions Serialization on Swing serialization questions service service method servlet servlet and forms servlet and jsp servlet api servlet attributes servlet code servlet container servlet context servlet error handling servlet exception handling servlet handling http request servlet initialization servlet initialization parameters servlet interview servlet interview questions servlet interview questions with answers servlet intvw questions servlet life cycle servlet lifecycle servlet questions servlet questions with answers servlet request servlet request dispatcher servlet request type servlet skeleton servletcontext servletcontextevent servletrequest Servlets servlets and jsps servlets api servlets details servlets request handling session session clean up session event listeners session facade pattern session interview questions session invalidation session listeners session management session questions session scope session timeout session tracking through url rewriting set collections set status method setattribute sets setstatus method setting bean property setting request type short circuit operators Singleton sleep sleeping threads soapUI Software Installation sorting sorting arraylist sorting arrays sorting collections special collections special inner classes split spring spring and hibernate interview questions spring batch Spring Core Spring Framework Spring Integration spring interview questions Spring JDBC Spring MVC Spring security Spring tutorial SQL SQL and database tutorial examples SQL Tutorial SSL stack stacks stacks and heaps static static class static declaration static imports static inner static inner class static method Static variable stopped stopping a thread stopping thread stopping threads Stored Procedure storing values in session Streams strictfp StrictMath string string buffer string builder string class string formatting String Handling string interview questions string manupulation string questions string tokenizer stringbuffer stringbuffer questions stringbuilder Strings strings in java struts Struts 1 Struts 1.2 Struts 2 struts framework interview questions struts interview questions struts interview questions with answers struts mvc interview questions struts questions Struts2 StrutsBooks submitting request subtraction Sun Certification sun certified java developer Sun Certified Java Programmer swing swing action performed swing and colors Swing Components swing event handling swing event listeners swing events Swing Hacks swing images Swing Look And Feels swings swings frame switch block switch case block switch case statement Sybase Sybase and SQL Server synchronization synchronized code synchronized keyword synchronized method System Properties tag lib tag library tag-lib taglibs tags TDD Technical Blogging ternary operator Test Driven Development test scjp Testing the context the session the volatile keyword thread thread class thread deadlocks thread interaction thread interruption thread life cycle thread lifecycle thread lock scope thread locks thread notify thread priorities thread race conditions race conditions in threads thread sleep thread states thread stoppage thread stopping thread synchronization thread syncing thread yield Threads threads in java threads interview questions threads life cycle threads questions tibco tightly coupled tips tips and tricks tips.FXML tokenizing Tomcat Tools toString transitions treemap treeset tricks Tricks Bag try catch try catch finally. finally block Tutorial type casting in java ui programming with java swings UML unboxing unit testing unix url rewriting use bean usebean using a arraylist using collections using colors using colours using command line arguments using different fonts using expressions using font using fonts using fonts in swings using hashmap using http session using httpsession using iterator using java beans in jsp using javabean in jsp using javabeans in jsp using javac using lists using maps using request dispatcher using scriptlets using session persistense using sets using special fonts using system properties using the jsp use bean using treeset using use bean Using Variables using volatile Using Wrappers using xml in jsp Util pack value object value object design pattern value object pattern var-args varargs Variable Arguments Variables vector vector questions vectors visibility vo pattern volatile volatile keyword volatile variables wait method waiting web app exception handling web app interview web application deployment web application exceptions web application scope web application security web component developer web component developer certification web context web context interfaces web context listeners web interview questions web security web server web servers Web services web.xml web.xml deployment webapp log weblogic website hacking website security what are threads what is a java thread what is a thread what is thread while loop windows windows 8 wrapper classes wrappers write objects to stream WSAD xml xml and jsp xml tags xslt yield()