Tuesday, July 13, 2010

what actually do u mean by oracle server?

Well it took me little affords to over come this great confusion about whats server when you are talking about the oracle databases. I heard people saying that all the work in oracle databases is done on Linux servers.
Now what was not getting in my head is, whats this server? I mean, i have done lots of programming in web servers,application servers but this oracle server??

Well Oracle calls its instance oracle server.Ooh, things are simple now.
But, whats there is oracle instance,
oracle instance is nothing but collection of some processes that must be running in the background along with the SGA also called as System Global Area.

Diffenece between tab and cat.

First of all what we are talking about here is the select query that returns tables that exist in the database.

Hence what we are differentiating here is
select * from tab and
select * from cat

Well I tried a lot to search for the difference by could not find anywhere, a proper answer.

Anyway, main difference is primarily concerned about the cluster in oracle databases.
Lets see it practically to make out the difference, observe the commands and there out put when they are run

desc tab;
output shows that there are 3 columns named
1:)table name
2:)table type
3:)cluster id

however,
desc cat;
output shows that there are 2 columns named
1:)table name
2:)table type

Hence the main difference is that with the cluster-id. Now whats that cluster id thing?
Well in order to increase the scalability of oracle databases ,Oracle came up with a concept called Oracle Clusters, now using these clusters u can creating multiple instances of oracle database on different machines.

And hence the additional column is nothing about talking about this cluster id. Now the difference b/t those select commands are quit simple.

Saturday, July 10, 2010

truncate and delete command

Well there is always this question about the difference between truncate and delete command.

First lets see what happens when u create a table.If you are using oracle 9i or below there is by default 8 blocks that are allocated for that table even if it does not have any data and this size increases by 8 every time. Hence when you populate the table with data that can not be held by these 8 block, next time there is allocation of 8 more block and hence size now becomes 16 block and so on.

But in latest Oracle databases the default size has been made as 0 block for table.

Now lets come to the difference.

When you delete data from the table, data gets lost but size of  the table remains the same.
Where as when you are truncate the table, size of the table becomes default size(as discussed above).

Now very critical question is
"truncate is a DDL or DML command"


If you had followed till now what i talked, answer to this question becomes way simple.
Well its a DDL command right?
That's because of the fact that its dealing with size of table.

For all the users doing Real DBA stuff, i meant running oracle on sun Solaris or any other Linux environment,
you can make use of
select * from user_ts_quotas ;
to see size of tables.

Wednesday, July 7, 2010

Whats Smon..

Well I was browsing for the Smon process i could not find much information about it.
Anyway putting it in very simple words its basically a process that must be up and running in the background in case any database instance is available.Whats interesting is that if u are using RAC than there can be many instance of the Oracle database that must be active at any instance, this is possible because of the clusters.
Hence to connect to any of the oracle databases available you must ensure that smon is running.

The simplest way to ensure this is by checking all the processes that are running at this time.This can be done by making use of ps -e command, if many processes are running we can make use of grep by pipe lining it with the ps-e out put.

Hence the command turns out to be
ps -ef |grep smon

Hence if grep gets u something means DB instance is up and running .

Tuesday, July 6, 2010

"POST"

Well its not html form submission type that we are talking about,we are talking about what's called Power On Self Testing.

What does it do?
Its basically is used in the process of loading operating system. This is the critical part of the booting process wherein this is held responsible for checking  hardware of the system, so in case anything goes wrong in testing process, it means that there is some part in the hardware that is not functioning as expected and since hardware is the basic part of any system, it makes no sense at all to boot the operating system(OS cant do anything without hardware). This failure makes the process(POST) not to transfer the control over to process responsible for operating system booting. Hence OS does not get booted. You can listen to some noise when any error is observed by POST.

The language responsible for post is fourth, i mean most of the POST programs are written by making use of programming language called Fourth.

Monday, July 5, 2010

Jdk7.0 is out?

Well jdk7.0 is about to be released with few more changes and cool features.

=>Algorithm for Garbage Collector in this version of Jdk is such that it more efficient and takes less pause time.
So program execution is faster.They call it to be First GC.

=>Also swings has been made better by providing even more API.

=>There is a mechanism introduced to make 64 bit pointer compressed and fitted in 32 bit, this reduces the memory requirements and performance.

=>Implementation of standard Elliptic-curve cryptography (ECC) for making java application use ECC out of box.


=>Unicode has been upgraded to 5.1.


=>There are many new API introduced for IO operations.


=> Attempt has been made to make the language as Modularize as possible.


=>Changes in the loader class,here they have provided a method which closes the resources which might be any file and other stuff. 

As quick as a snake's bite ( maybe quicker! )...

Hey I'm back and this time with a programming language that I have enjoyed programming in for the last few months probably most of you know what I'm talking about form the title ... well for those who don't know about it it's Python it's simple to learn... it's simple to use... and it's simple to what not?
So those who are not using it I strongly suggest you start to use it. It's basically a scripting language, dynamically and strongly typed, it's object oriented, you can also program functionally ( although I'd prefer LisP or Haskell to Python to program functionally ) and it's really fast. Now many of you may be wondering what is dynamic typing.... Now let me first tell you that it's got nothing to do with typing on your keyboard, it's the data-type of a variable that is under consideration. Now if you look up "Dynamic" on http//:www.dictionary.com under 'Computers' you find the meaning:
  • affected by the passage of time or the presence or absence of power: Dynamic memory must be constantly refreshed to avoid losing data.
What I need you to look at is "affected by the passage of time or the presence or absence of power". Here the data-type of the variable is what is affected. Suppose we have a variable say x declared as:

x = 10

the data-type of x is an INTEGER.
Now suppose I do this:

x = "aj"

here the data-type of the same variable is now STRING.
But in a "statically" typed language as C or C++, the data-type of a variable once declared cannot be changed. But what is the use of this?
Well it's easier to code and it makes a lot more flexible.

Sunday, July 4, 2010

what does the Class.forname() do?

Well the important thing about forName() method of Class is that it basically loads the driver.
Now, what do we mean by loading the driver?

It basically takes the class name passed as the string and it executes the static blocks of that particular class.
Now these static block have the code that is needed for making Driver Manager aware of the fact that there is one more driver been added to the list of the available drivers.Hence when are request for that particular driver is made, it is available for the Driver Manager.

Whats interested to notice is the fact that forName() does not create an instance of the class passed as string parameter.It basically executes the static part of a class.

What's the difference between web server and application server

When it comes the web servers they can process HTTP requests and the main job of these servers is to just send the response for the request received from web browser in the static form (may be Html,images etc) or send a redirect or delegate the response to other program like CGI, JSP(JavaServer Pages) ,server side JS.

Hence Web servers do not have the capability of the executing any business logic  Its job is to just get the request serve the request and send the response back.This results in lot of draw backs, which includes application scalability problem,session management


Whereas in Application servers, you can put in business logic for which would be executed by the server for the use of client program.This is mainly done by means of whats called EJB(Enterprise Java Beans).
Also its interesting that Application servers are the super set of the Web servers and hence Application server is capable of doing what web servers do(only allocating resources).
Its important to note that Application server clients can also be GUI running on PC and other Application server.

Thursday, January 21, 2010

Implicit objects in JSP

Well when it comes to Java Server Pages(JSP),the most important concept is "implicit objects".
What are implicit object basically? These are the objects that are created by JSP container (server) and you do not need to explicitly create these objects.
There are basically 9 implicit object as listed bellow(along with the corresponding API)
API implicit object

JspWriter ==> out
HttpServletRequest ==> request
HttpServletResponse ==>response
HttpSession ==>session
ServletContext ==> application
ServletConfig ==> config
Throwable ==> exception
PageContext ==> pageContext
Object ==> page

Well looking at the list of API we make out that these are the objects which basically give JSP the servletness features.Well if you are good at servlet than JPS is not that hard and so the "implicit objects".


Wednesday, January 20, 2010

An Example for "dirty checking" in Hibernate

As I have written about the features of hibernate in the previous post.One of them was dirty checking by hibernate.
Now what does dirty checking actually means?To see this practically lets look at the following class with name Computer.

public class Computer
{
private String name;
private Double prize;
public Computer()
{
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public Double getPrize()
{
return prize;
}
public void setPrize(Double prize)
{
this.prize = prize;
}
}
Here I have prize and name as class attributes and I have setter and getter for them.Also I make the name attribute as the primary key in the .hbm.xml file.
Now lets have a class(say Manager) which deals with the retrieval of the row of table Computer,which looks as given bellow


public class Manager
{
public static void main(String[] args)
{
Configuration config = new Configuration();
config.configure();
SessionFactory sf = config.buildSessionFactory();
Session session = sf.openSession();
session.beginTransaction();
Computer c = (Computer)session.load(Computer.class, new String("Mac"));
System.out.println(c.getName());
System.out.println(c.getPrize());
c.setPrize(111111);=========>imp. step
session.getTransaction().commit();
session.flush();
session.close();
}
}
Now here when I make the prize of the computer as 111111 in the imp. step, and after the execution of Manager class gets over and I go to the DB and see that the value of the prize has been changed to 111111.
Now the point to be noted is that we changed prize to a new value and did not do a explicit save after changing the value(by calling session.save(c)),but still the changes are made.This auto-updating of DB with reference to the change in the object is called "dirty checking" in terms of Hibernate.

Tuesday, October 13, 2009

Why to use hibernate when other persistence mechanism are there??

Well there are many reasons for hibernate to be used in place of others.

I list some of the most important reasons.

1:)Hibernate provides the Object Relation Mapping(ORM):
Well it has always been a concern for the java developers,they wanted a tool that can provide a proper ORM.Through ORM,the classes(POJO) are directly mapped to the tables and the object state is persisted as the row in that table.

2:)Hibernate provides Transparent and Automated persistence:
Transparent means that hibernate allows the class (that is to be persisted) to be free from any special implementation.Meaning that you don't have to implement any interface or extends to any class.Hence the developers don't have to consider anything about the persistence.

Automated is something that allows the programmers to be free from the low level database implements.Hence developers don't have to write low level queries,they are generated by hibernate(it uses its own query language called HQL).

3:)Hibernate supports Dirty Checking:
This makes sure that any changes that are made to the object will also be reflected in the database.Hence you don't have to again explicitly save the object.

4:)Hibernate support Fine-grained domain models:
This is the most important requirement for rich domain model.This basically allows you to have more classes than the tables.

Example in a design for a User entity we may have address,street no,city etc. as attributes,but wait there is a problem with this:what if a User has a home address,office address.Well you can have soo maany columns for each of them.

But in hibernate you can have a separate class called Address with all of the above as attributes.This basically reduces the time taken to execute the queries.

5:)Hibernate also supports the dynamic manipulation of meta-data:
Using this you can update the database schema even at the run time.

6:)Hibernate offers platform independence:
With this you can even work on legacy systems with out any problems.

7:)Hibernate supports polymorphic queries:
Well this feature of Hibernate is quite unique.This basically allows to retrieve the DB row and store it in super class reference.

Well the list continues.I must say that its really worth using Hibernate in application development.But its always better to use it in big application.

Friday, August 7, 2009

knowing class file content using javap command....


Well as we know that there is lots of discussion done when it comes to memory allocation for the String class Objects.As we have the concept of "constant pool" and "non-constant pool",the allocation of memory is quit different and really gets confusing some times.

Even in the scenarios like using String class and StringBuffer class,we all know that its better to use the StringBuffer object compared to that of String class as we can append some string despite of concatinating it,we do not actually know why its better but we implement it that way only.

We can obtain the best possible solution to these problems if we can see the bytecode generated after translation of the .java file to .class file.

Well java is not behind even in this aspect of it.Sun has provided a great tool called "javap" command.

Now what javap command does is,it takes the .class file name and prints the information about the class:access specifers,method signature,classes used with fully qualified package...

Also if you use option c with this command we get a different representation....
what it does??well it does not decompile the bytecode but it disassembles the code and gives the bytecode instruction specified by the java virtual mechine.....

Well take a look at this example....String class objects for constant and non constant pool.....

package com.lara;

public class Example
{
public static void main(String[] args)
{
}
void usingStringConstantPool()
{
String s = "java";
s = s+"geek";
System.out.println(s);
}
void usingStringNonConstantPool()
{
String s1 = new String("java");
s1 = s1+"geek";
System.out.println(s1);
}
}

now see this,what happens next...

E:\classFiles\com\lara>javap -c Example
Compiled from "Example.java"
public class com.lara.Example extends java.lang.Object{
public com.lara.Example();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."":()V
4: return

public static void main(java.lang.String[]);
Code:
0: return

void usingStringConstantPool();
Code:
0: ldc #2; //String java
2: astore_1
3: new #3; //class java/lang/StringBuilder
6: dup
7: invokespecial #4; //Method java/lang/StringBuilder."":()V
10: aload_1
11: invokevirtual #5; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
14: ldc #6; //String geek
16: invokevirtual #5; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
19: invokevirtual #7; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
22: astore_1
23: getstatic #8; //Field java/lang/System.out:Ljava/io/PrintStream;
26: aload_1
27: invokevirtual #9; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
30: return

void usingStringNonConstantPool();
Code:
0: new #10; //class java/lang/String
3: dup
4: ldc #2; //String java
6: invokespecial #11; //Method java/lang/String."":(Ljava/lang/String;)V
9: astore_1
10: new #3; //class java/lang/StringBuilder
13: dup
14: invokespecial #4; //Method java/lang/StringBuilder."":()V
17: aload_1
18: invokevirtual #5; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
21: ldc #6; //String geek
23: invokevirtual #5; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
26: invokevirtual #7; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
29: astore_1
30: getstatic #8; //Field java/lang/System.out:Ljava/io/PrintStream;
33: aload_1
34: invokevirtual #9; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
37: return

}

now the stuff that you see is more of the JVM specified instructions,so we won't go to that part but we can really make out from the out put that there is new operator being used by the second function twice hence 2 objects are created whereas in first case there is only one object created....
and that's perfectly fine with the theory about these....

But what a command,we can really have own proof of what exactly happens.....

There are other options also available..you can go through the API....one more interesting option is l which prints the local variable and out line table...


Friday, July 31, 2009

Is it that we should always use preparedStatement???(statement vs preparedStatement)

Well when it comes to the competition between preparedStatement and the statement object in JDBC,most of the time its preparedStatement that wins the game....
Reason being simple and not suppressing....

1:)Performance
2:)Efficiency

Actually when we get the statement object from connection object in JDBC there are three things that are done on DB side "FOR EVERY RUN OF THE JAVA PROGRAM"...
#1:The database query is first compiled
#2:there is a query plan that is generated by the database manager
#3:than at last we have the query being executed...

Now if we consider the case of the preparedStatement,than at the first run or execution of the program there is all the three steps that are carried out..but for the subsequent running of the program there will only be the last step that is carried out...
That's because the compiled query and the execution plan is already there with the DB...

Well than whats the use of having the statement object????
the prepapredStatement is considered to the static object...as there is only one type of query that you can possible execute with it....

Whereas in case of the statement object it considered to be the dynamic object as you can execute multiple query from one statement object.....

Thursday, July 30, 2009

Enabling JavaScript.....

Well i can across this question when i was attending a conference in the college......"what happens if you disable the javascript in the web browser"...well nothing like rocket science,answer would be u wont be getting the javascript part(or rather code) of the application being executed....as you have disabled the javascript in the run time environment....
well i was thinking what if we possibly can enable the javascript thought javascript...

Reason for this to be done is simple...as we type the url of any site in the address bar there is this complete html and JS code being downloaded there which than is executed by the browser....Now if i could write a code that can enable JS so that my JS code is executed at run time, will make sure that security feature i.e. authentication is enabled at the client side...

This really sounds like crap as the javascript is disabled from the run time environment how can first off all the JS code be executed....Quit funny:)

but what about the reverse part of it.....well disabling javascript is by using JS is not possible...
reason sounds quit simple...the security is compromised....

well its quit funny to get this kind of thoughts some times...

Program to find number of zero's in factorial of a number...

Resently a came accross this problem of finding the number of zero's in factorial of a number....
Well i think the logic is really simple...we have to find out the factors that contributes to 1 or more number of 0's.Whenever there are 1 or more zero's at the end of a number it always results in 0's at the end factorial number also.And the number of 5 also gives same number of 0's as there are many more numbers of the 2's compared to 5's.Similarly one 0 from 25 and two 0's from 50 and and soo on....
Hence we can compute the number of zero's by finding a value though the formula
value = (number/5^1+number/5^2+..............+number/5^n)
where
n = number/5;
Hope the idea is clear....
Now as far as the implementation in java is concerned here i also give the code for implementing it in java...
package com.lara;

import java.util.Arrays;
import java.util.Scanner;

public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number for which you want to find zeros");
System.out.println("Enter the total number of the cases");
int cas = sc.nextInt();
long result[]=new long [cas];
System.out.println("Enter the long elements one by one");
long num[] = new long[cas];
for(int i =0 ;i
{
num[i] = sc.nextLong();
}
for(int i=0; i
{
long n = num[i]/5;
for(int i1=1;i1
{
System.out.println("i1: "+i1);
System.out.println("i; "+ i);
result[i] += (long) (num[i]/Math.pow(5, i1));
}
}
System.out.println("number of the zeros are "+ Arrays.toString(result));
}
}

Well the fact remains that the execution time of this program in java is definitly more than that in C/C++....


Friday, April 10, 2009

Java DataBase Connectivity.....Simple

Here we are with the java database connectivity....
Suppose you are using a Oracle database with user name and password as root and root....

Now as we have already seen that we always prefer to use type 4 driver and also the "BUILD PATH " has to updated with the corresponding jar file....(can be downloaded from http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc101040.html)

We look at the JDBC in the steps....This makes it look lot more simple to learn and implementation always remains the same,i.e. always same steps have to be followed....

STEP 1:Register for the driver using Class.forName("oracle.jdbc.driver.OracleDriver");
=>this registers for the driver which will be used by ur
program to interact with the database
=> string argument in the forName method is a class developed by Sun
Microsystem .It's in a fully qualified package structure.
=>this is a checked exception type...meaning you have to use try,catch
or you have to delegate it the caller by using throws..

STEP 2:Get the connection object by using:
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE",
"root","root");
=>this basically gives the connection object by using the
driver that you have register in the
previous step.
=>now we have established the connection with the
database...
=>this again is a checked exception type.
=>first string in the arguments list is the url of the
database,thin is the type of the database in oracle,
@localhost meaning its there in you system...can
also be the ip address,1521 is the port number for
Oracle DB and at last as we know is the user name
and the password.(given at the time of installing Oracle database).

STEP 3:Get the statement objects:
Statement stmt = con.createStatement();
=>this basically helps you in executing any type of SQL
query, may be of type ddl,dml,dql..
=>this again is a checked exeception type.

STEP 4:Generate sql query which you want to execute,in our
case as:
String sql = "create table student(name varchar(12),ssn int,primary key(ssn));";
=>it can be any sql query that you want to execute.

STEP 5:Execute the sql query as:
stmt.execute(sql);
=>this creates a table in the db by name student...

STEP 6:close all the connection...
=>this again is a checked exeception type.
=>this step according to me is the most importent step and
ignored by people most of the time...its closes all the
connection that we have created...
Here we are with the complete implementation of
the JDBC...

package jdbc.con;
//this is package used to organize the project

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
//all the packages needed to be imported

public class Connectivity
{
public static void main(String[] args)
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(ClassNotFoundException ex)//here we are to handdle the exeception
{
ex.printStackTrace();
}
Connection con =null;
Statement stmt = null;
try
{
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "root", "root");
stmt = con.createStatement();
String sql = "create table student(name varchar(12),ssn int,primary key(ssn));";
stmt.execute(sql);
System.out.println("see the data base");
}
catch(SQLException ex)//throws SQLException
{
ex.printStackTrace();
}
finally//best way to close all the connections
{
try
{
if(stmt != null)
{
stmt.close();
}
}
catch(SQLException ex)
{
ex.printStackTrace();
}
try
{
if(con != null)
{
con.close();
}
}
catch(SQLException ex)
{
ex.printStackTrace();
}
}
}//end of main
}//end of the class
So here we are with the Java program which makes changes in the DataBase,the way you want it to make changes....Its simple and really feels great to have interaction from any Java Program to DataBase......As i always say:"Enjoy the Free world of JAVA"..

Friday, February 27, 2009

Types of Drivers....




First of all sorry for the late update of the blog!!!!!
Anyway yesterday i thought of writing about the Hibernate-the framework in java but than to know about that we need to know the Java DataBase Connectivity(JDBC) and to know about the JDBC we must know about the different types of drivers.......
So here we are with the different types of drivers.....huum
First thing is WHAT is a driver basically...
Now to interact with the database(any database may be mysql,oracle) you need to have a driver so that this interaction can possibly be done!!!!!in other words the driver basically is responsible for the connection between your program and the dabtabase.....and that's the reason WHY we need driver.
Now when it comes to the types of driver there are basically FOUR types of drivers
  • Type one Driver-This driver is also called as brige drive.As shown in the picture (forget about the JDBC api and stuff)what is noticeable is the the Database liberary API's.This type of driver basically needs the support from the Database library API.Not only library but also the ODBC driver is quite noticeable.Hence this type of driver basically needs a ODBC driver support(which can be provided by create a DSN).We will look at this supports in the jdbc connectivity.Because of these when ever you want to move your application from one computer to other you need to install these Database library and also you need to make sure that you have the DSN already been created with the same name as in the other system.From the java prospective this type of driver is basically also called as default driver as this comes with the jdk...i.e.you don't have to update the build path of the application.This is called as bridge driver as it acts as a bridge between the Calling Java Application and the ODBC.So a application has to through the JDBC,which interacts with the ODBC(through the DSN)which in turn interacts with the DataBase...
  • Type Two Driver and Type Three Driver-Both these drivers have the DB Directory so these don't basically need the ODBC support....And also these drivers must be provided by the DB vendors that you are using.....These drivers are not at all in use any where including industry....So we will give more importance to the next driver...
  • Type Four Driver-This basically is the widely used driver because of the features offered by this driver.The one you can see on the TOP.As you can see all you need is the type 4 driver,nothing else(no ODBC,no DSN and stuff).This type of drivers are basically provided by the DB vendors and you must "update the BuildPath" of the project by adding the external jar files.In case of Oracle you have to include the ojdbc14.jar.... Now to find this jar file you must go to the location where you have installed the Oracle,and in the directory D:\Oracle10GXE\app\oracle\product\10.2.0\server\jdbc\lib you will find the ojdbc14.jar.One very big advantage with the type 4 driver is that it can be used in any system where there is a Oracle database.No library and DSN of the same name all this is not reqiured(as in case of type 1 we need all this stuff).
 Next will be the database connectivity though java  program,till than just enjoy this free world of JAVA...

Saturday, January 31, 2009

Resolve Most Common Bugs When You Code (Java)

I have been reading lots of blogs and exploring lots of sites, but could not find much about the most common real time bugs and solutions at one place. So here comes my experiences one by one (simple ones to more complex) which I have earned with my almost 4 years of software industry experiences.

When you start learning java, first thing you do install the java and set the classpath. Since the classpath has been set, at command prompt if you shoot java or javac command it will be presented with the command options irrespective of the path from where you are shooting, in fact this is the way you check wheather the classpath has been successfully set.

I remember during my college days, I faced the problem where I was not able to set the classpath. First I have installed the JDK and opened the command prompt, tried to run the java and javac command. Since the classpath has not been set, it was not recognized as a external or internal command. Now I have set the classpath and at the same command prompt, I tried to run java commands again the result was the same.
Was that the OS problem or something wrong with my declarations?
Any guesses? ?????????

The reason is simple when you open the command prompt, it takes account of the classpath and provides the memory to run the command. Now the catch is if you modify the classpath and do not open the new command window to run java command and try to run with the same old command window it considers the same old classpath again.
So everytime you modify the classpath, open the new command window is always the best possible option.

Few more tips on classpth....coming soon :))
With how to write the web service to transfer the files across any geographical location over the internet using server client mechanism....:))))))))))))))
Till then enjoy...................
ATUL PATEL

Tuesday, January 27, 2009

what is CAFEBABE????


Yesterday when i was going through my classFiles folder which basically contains all of my .class files i found that some of the .java files(source programs) were missing so i was running all those .class files to which i didn't have the source file.....Meanwhile I got this thought as to what will happen if any of these files were not compiled and converted to a .class file by JVM...So i just opened text editor and typed some crap and saved it as ajay.class in my classFiles folder...
Now when i run this file i got an error which looks like "Exception in thread "main" java.lang.ClassFormatError: Incompatible magic value 218784115 in class file ajay"...Now according to the API the ClassFormatError is a part of java.lang package(can even be seen from the message printed through console object)and is Thrown "when the Java Virtual Machine attempts to read a class file and determines that the file is malformed or otherwise cannot be interpreted as a class file"...now the ClassFormatError is quite obvious but what's interesting are the last few words "magic value" what is it???? and the answer was quite interesting...Every class file which is compiler by JVM must have the first 4 bytes as "CAFEBABE" which bacisally is to tell the JVM that the class file is a valid one....i was more curious to know why it was 0xCAFEBABE and not something else......after doing little RnD i came up with a lot of stuff but none of them could make me 100% confident that i found the right answer,some of the answers were.....
  • some people say that its easier to represent in 32bits format
  • some say that there is no j or v in the hexadecimal so they came up with 'CAFEBABE'
Anyway one thing is per sure any class file has the fist 4 byte as 0xCAFEBABE.....
And its quite intersecting to know this fact isn't it!!!!!!!!
A tuitorial on how to use ecllipse..An IDE is coming up next
Till then enjoy the world of JAVA!!!!
AJAY:)