Tuesday, March 23, 2010

Assertions

Selective enabling and Disabling:

  • With no Arguments(as in the preceding examples) enables or disables assertions in all classes ,except for the System class.
  • With packae name: Enables or disables assertions in the package specified ,and any packages below this package in the same directory hierarchy.
  • With a class name Enables or disables assertions in the class specified.

java -ea -da:com.geeksanonymous.Foo

The preceding command tells the JVM to enable the assertions in general,but disable them in the class.geeksanonymous.Foo.You can do the same selectively for a package as follows:

java -ea -da:com.geeksanonymous...

Thursday, December 3, 2009

Saturday, November 21, 2009

Friday, August 14, 2009

String Builder Class

The thread safe StringBuffer class has a replacement in the form of StringBuilder .It doesnot have synchronized methods so it works much faster .So if you are performing a number of string operations in a single thread you will gain a tremendous performance while using this class .The string builder class consist of mutable sequence of charecters
.It provides an API ,which is compatible with StringBuffer,but there is no guarntee of its sychronization.This class is designed in such a way that it can be used as a drop in replacement
for StringBuffer in places

Thursday, August 13, 2009

Process Builder

An operating system process is created by using this class.A collection of process attributes is managed by ProcessBuilder instance.By using those attributes,the start() method creates a new process instance.To create a new subprocess with identical/related attributes the start method can be invoked from the same instance.
These process attributes are managed by each process builder in the following way:
Command: Command consist of a list of strings which makes the external program file to be invoked and its argument,if any significant.The String list representing a valid operating system is System dependent.

Environment:
A mapping which is System dependant varying from variables to values.The copy of the enviornment of the current process is the initial value.

Working Directory:
The current working directory of the current process is the default valueusually the system property,user.dir,imparts the name of the directory

RedirectErrorStream property:

At initial stage the standard output and error output of a subprocess are sent to two separate streams,meaning that this property is false.The false property can be accessed using two of the methods

--Process.getInputStream()

--Process.getErrorStream()

Friday, July 17, 2009

inheritence Demoonstration

package EmployeeandDate;
public class Date
{
int day,month,year;
public Date(int d,int m,int y)
{ day=d;
month=m;
year=y;
}
public String GetDate()
{
return day+"-"+month+"-"+year;
}
}

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

package EmployeeandDate;
public class Employee
{ public String Name;
public int ID_No;
public String CompanyName;
Date d;
public Employee()
{}
public Employee(String n,int id,String c_name, Date dob)
{
Name=n; ID_No=id; CompanyName=c_name; d=dob;
}
public String GetDetails()
{ return "Name: "+Name+"\n"+"ID: "+ID_No+"\n"+"company Name: "+CompanyName+"\n"+d.GetDate(); }
}
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

package EmployeeandDate;
public class Master extends Employee
{ public int dept_id;
public Master(String n,int id,String c_name, Date dob,int e)
{
Name=n;
ID_No=id;
CompanyName=c_name;
d=dob;
dept_id=e;
}
public String GetDetails()
{ return "Name: "+Name+"\n"+"ID: "+ID_No+"\n"+"company Name: "+CompanyName+"\n"+d.GetDate()+"\n"+dept_id; }
}
::::::::::::::::::::::::
import EmployeeandDate.Master;
import EmployeeandDate.Date;
class Test
{
public static void main(String args[])
{ Master m=new Master("Vishal Hegde",007,"Johnson Private Limited",new Date(1,1,1989),123);
System.out.println(m.GetDetails()); }
}::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::