Sunday, September 25, 2011

search a File in root directorys

/*
This programe searches the given file Which is in "C-directory" only in sub floders also
and also displys the all files and floders in directory and thair path also
if the u want to seach in the anether dir for that change the dir name in the programe
*/
import java.io.*;
public class FileSearch {

public void search( String path,String searchfile) {
File file = new File( path );
File[] filelist = file.listFiles();

for ( File f : filelist ) {
if ( f.isDirectory() ) {
search( f.getAbsolutePath(),searchfile );
System.out.println( "Directory:" + f.getAbsoluteFile() );
if(f.getName().equals(searchfile)){
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< break;
}
}
else {
System.out.println("------------------------------");
System.out.println( "File:" + f.getAbsoluteFile() );
if(f.getName().equals(searchfile)){
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< break;
}
}
}
}
public static void main(String[] args) {
FileSearch fs = new FileSearch();
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("press ENTER or enter the file name with extention");
String searchfile=br.readLine();


File[] dir=File.listRoots();
/*
for(int j=0;j<=dir.length;j++)
{
System.out.println(dir[j]);
fs.search(dir[j],searchfile);
}
*/

fs.search("C:/",searchfile); //call the function
}
catch(NullPointerException e)
{
System.out.println("enter abs file "+e);
}
catch(IOException e)
{
System.out.println("enter abs file "+e);
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("error "+e);
}
catch(Exception e)
{
System.out.println("enter abs file "+e);
}
finally{
System.out.println("you get null pointer if the file not get or not specifiy the absolute dir");
System.out.println("----------------------------------------------------------------------------");
fs=null;
}
}
static{
System.out.println("----------------------------------------------------------------------------");
System.out.println("please enter the file in the c dir only");
System.out.println("----------------------------------------------------------------------------");
}
}

Friday, April 1, 2011

CaseSencitive



/*
RULE: identofiers are case sensitive ( balance and Balance are two different)
*/


class CaseSencitive
{
public static void main(String[] args)
{
int bal;
int Bal;
System.out.println("legal identifiers");
}
}

Illegel

/*
RULE: following are some illegel identifiers
*/

class Illegel
{
public static void main(String[] args)
{
int 7g;
int .j;
int -m;
int :b;
int s#;
int int;
int for;
int enum;
System.out.println("illegal identifiers");
}
}

DontUse

/*
RULE: dont use keywords as identifiers
*/
class DontUse
{
public static void main(String[] args)
{
int if;
int for;
System.out.println(" illegal start of expressition");
}
}

NoLimit

/*
RULE: there is no limit to the number of characters in the identifiers
*/

class NoLimit
{
public static void main(String[] args)
{
int asdf_hghighiggu_jhgjhghgu_kjghuge_njgh$jfhfghaf;
System.out.println("No Limit ");
}
}

After the first character

/*
RULE: After the first character ( $ or _ or character ) identifiers contains
any thing i.e numbers also
*/

class AfterFirst
{
public static void main(String[] args)
{
int a333424;
int _34we;
int $a23deu;
System.out.println("legal identifiers");
}
}

identifyrs starts with characters

/*
RULE: identifyrs starts with characters(a to z or A to Z)
or starts with underscore (_) and currency ($)
not starts with numbers
*/

class StartWith
{
public static void main(String[] args)
{
int $x;
int _a;
int m;
System.out.println("legal identifiers");
}
}

classes and interfaces

/*
RULE: classes and interfaces
the first letter of the word should be Capital and connectig word letter also capital
the name should be nouns
*/

class Dog
{
public static void main(String[] args)
{
System.out.println("Hello Dog!");
}
}

class PrintWriter
{
System.out.println("this is class");
}

interface Car
{
}
interface Runnable
{
}

Methods

/*
RULE: The first letter should be small letter and followed
words shold be capital letters
*/
class Methods
{
int getBalance(int accno)
{
System.out.prinln("balance is")
}
void setBalance(int acc,int amount)
{
}
public static void main(String[] args)
{

System.out.println("Hello World!");
}
}

Variables

/*
RULE: like methods rules
starting letter should be small then next word with capital letter
SUN recomended that it should be small ans good meaning full sound
*/

class Variables
{
public static void main(String[] args)
{
int buttonWidth;
int bal;
double accountNo;
System.out.println("legel convetions");
}
}

Constants

/*
RULE: constants are should be capital letters
they are used final and static keywords
*/

class Constants
{
static final double accountNumber=22323543;
public static void main(String[] args)
{
final float PI=22.7f;
System.out.println("legel constant code convention");
}
}

Friday, February 25, 2011

Final_DataTypes

//RULE:we can use the final keyword with DataTypes but values of variables are not modifies later

public class Final_DataTypes
{
public void testMethod()
{
final int x=10;
System.out.println("ok");
}
}

Final_Methods

//RULE:we can use the final keyword with methods but methods are not overrides

public class Final_Methods
{
public final void testMethod()
{
final int x=10;
System.out.println("ok");
}
}

Final_Interface

//RULE:we can not use the final keyword to the interface

final interface Final_Interface
{
public static void main(String ar[])
{
System.out.println("illegal combination of final and interface");
}
}

Final_Class

//RULE:we can use the final keyword to a class but it doesent support inheritence concept

final class Final_Class
{
public static void main(String ar[])
{
System.out.println("ok");
}
}

Aabstract_Implements

/*
RULE:we can not implements an abstract class but extends
*/

abstract class Aabstract_Implements implements Aabstract_Class
{

public static void main(String ars[])
{
System.out.println("this example demonstate that we can not implements an abstract class");
}
}

Aabstract_Static

/*
RULE:we can not use abstract-class as static keywords commibinations
*/

abstract static class Aabstract_Static_Class
{
public void test()
{
System.out println("modifier not allowed here");
}
}

Abstract_Final

/*
RULE:we can not use the final keyword to a abstrct class
*/

final abstract class Abstract_Final
{
public static void main(String ar[])
{
System.out.println("illegal combination of final and interface");
}
}

Abstract_Private_Class

/*
RULE:we can not specifies abstract as private and protected
*/
abstract private class Abstract_Private_Class
{
public void test();
}

Aabstract_Public_Class

/*
RULE:-abstract may be have public access specifier
*/

abstract public class Aabstract_Public_Class
{
public void test()
{
System.out.println("allowed here combination of keywords");
}
}