To undestand BPEL/ESB it is recommended to have a good knowledge of java,xml and j2ee server.YOu need not be a bond in all the three but you should have the concept about all the three to get an inner view of the process.
I will try to explain java in my words.
JAva as everyone of us knows is a programming language which is derived from c++.
It is an object oriented programming language.
Object-oriented programming (OOP) is a programming pattern that uses "objects" – data structures consisting of datafields and methods together with their interactions – to design applications and computer programs.
Java is generally referred to as java programming language.The java Virtual machine,java api and java class file work together to make the java phemonenon possible.Java is a robust language and is platform independent.Platform independent mean write once and execute any where.Once you have written the java code you can run it in any where jre is available.
We have discussed that the java architecture consist of four specification.
1>Java programming language.
2>Java class file format.
3>Java application programming interface(java API)
4>Java virtual machine.
Now we will check both the compile-time environment and run-time-environment
Compile time environment
Programme.java -àcompiler àProgramme.class
We have written a simple programme called Programme.java.
The compiler convert it into byte code Programme.class.
This is the only function that took place in compiler.
Now you have the class file so you can execute it in any platform.
It can be on local machine or it can be transferred to another system.
Run-time environment
Run time consist of java api and java virtual machine.The java api and jvm together is also called as java platform.When we write Java programme it access system resources by calling methods in the class which implements java api(example string.class, object.class) .
The class file that we have created “Programme.class” and the class file which implement java api together enters the java virtual machine which acts as an interpreter and execute the byte code to fetch the result.
So finally it comes to JVM.Now we will try to peep inside the JVM what it is and what it does.
Java virtual machine is an abstract computer.Its main job is to load the class files and execute the byte code.JVM contains a classloader and a execution engine.The classloader loads your programme class file and the class file from java api it converts it into byte code and then execution engine execute the byte code.
A simple execution engine acts as an interpreter which executes the byte code one by one,however we have another execution which is much faster than the simple execution engine ,it is just in time compiler or JIT.In this scheme the byte code is converted to native machine code the first time the method is invoked it is then cached so that the next time the code is invoked it can be directly loaded.So it will save time and the execution will be much faster.Now we will check each of the component individually.
Class loader-When a class file run it may need other class files also to perform its execution.These class files are loaded by the class loader in JVM.The class file may be present in the local system or may be in the network.The JVM uses the classpath to point to these class variables.The classpath can be added by using java –cp or java –classpath command.
Example- java –cp c:\jdk_home\jre\lib\tools.jar
One class files are loaded it goes to verification phase where in it check whether the java code fulfills the basic rules of java.This step ensure that no illegal actions are performed.
The jvm act as byte code interpreter that execute the byte code for the loaded class.The JVM keeps track of the memory so once the execution is completed and jvm finds that the object is no longer required.It marked the instace for garbage collection..Thus it manages memory also.Essentially in real application a jvm instance start running by calling the main() method .The main method must be public ,static,return void,and accept once parameter a string array.We will check these details later.This is infact very confusing in java as most of the things are interrealated and we can not have all the concepts at a single time so we will check these in our order.
Java-Object Oriented Programming
An object is a run time representation of a thing.Object oriented programming approach ensures that the programme survives the changes in the changing world and changing business needs.An object is an idividual entity which can be changed without changing the whole application.In shor we can say it is adaptable and reusable.It also defines the term abstraction,encapsulation,inheritance and polymorphism.I will cover it as soon the lesson will proceed.
JDK-Java development kit
The java development kit provides following
1>Compiler that is javac which is used to compile the java code.
If we have a programme movie.java then we will compile it by following command
Javac movie.java
This will create the byte code for the movie code called movie.class.
2>It provides the core class library.The library contains all the class files which are required for the execution of a programme.The jdk provide the library in the form of rt.jar file.
3>Debugger-It provides a debugger which helps in debugging ,finding the real place of error with the exact error messages.In JDK the debugger provided is jdb.
4>Byte code interpreter or jvm-IT interpret the byte code.
5>Documentation generator-Provide opportunity to create the java doc representing the structure of class files in the programme.
6>Java archieve utility-Several class files can be bunched together to form a jar file out of it.
Different edition of java
Java,Micro Edition-Used for small applications like smart cards,pagers,mobile etc.
Java Platfrom Standard Edition-Development environment for internet applications
Java Platform,Enterprise Edition-For implementation in application server.
Integrated development Environment
IDE is a tool which is used now a days to write your programme.It has many components which helps us in writing our code easily.It has some prebuilt code and other faciliteis which helps in decreasing the real time of creating an application code.
Most commonly used IDE is eclipse and jdeveloper.However we will be using jdeveloper for illustration.Again covering jdeveloper is a vast topic so I will directly go inside programming concept.You can write the same code in notepad and save and compile it using your command prompt.
Programming
To Start with programming in java we first of all need to know what is an object and what is a class.
We will try to understand the concept with the following example.Let suppose we want to construct a house.We might be having lot of ideas in our mind but we can not go with the same idea to construct a real house as physically the implemetation will be very different.So we need to model an architecture for the building i.e we need to first create map which covers all the essential details like how much materila will be used,what will be the cost and all other important details.
In java the class does the same work.It is the blueprint which defines the object.So essentially a class contain several properties and methods.
Now once the blue print or map is ready one can go ahead with this and implement the map in to physical existence.
In java objects do the same work.They use the class to retain there structure and behaviour to perform the task.
Understanding variable and methods
Lets suppose we have a pen then what can be attribute and functionality of the pen.The attribute may be lead colour,brand name,ink quantity and the methods can be to write.
In a similar way a class have variable and methods which together defines the attributes and functionality of the class.
As we have seen an object is basically derived from class.The object must be referenced to work with it.In java we create an object using the new command.
So if we have a Movie class we can create a object of movie class by following method
Movie obj=new Movie();
Here obj is our object and the new operator is used to create an object for a class.The object “obj” contains the reference for the newly created object of the movie class.
Let suppose our movie class has some methods.
How one will execute this method.They have to be called from the object
So if we have a method called rating() in our movie class it can be invoked by the object in the following way.
Call method from object- obj.rating()
As we have discussed the object has a reference.Its values are stored in the memory as a hashcode value.We will check it once we will get in to the details of programming.
As we have seen in our real world example we need to have a map in order to construct a house then only physical implementation tooks place.So this map can be used to create many other physical implementation.It can be implemented in the similar way by some other or can be changed in some way by others.Similarly in java a class can have multiple instance(objects).So we got the following idea about the class and object.A class is a template for the objects.A class defines variables and methods for all the instances of the class.
Now we will check some important terminology and concepts of oops(object oriented programming langauge).Java is called as an object oriented programming langague.The reason I am covering these definiton later is that I wanted to present an idea of object before getting in to what an object oriented programming languge mean.
Encapsulation
Encapsulation allows you to ignnore the low level details of how the object is structured and how it works internally.Lets take example of a television.We are not bothered about how it works internally.We only need to know how to start it and close it that is through interfaces provided like remote but we are not at all bothered how the lcd of tv works how it gets signal from antenna.These low level details are not required by us.Lets suppose the television company changes the software internally but still the interfaces are same that is still remote is same.So encapsulation hides the internal structure and operation of an object behind an interface.In our example television is an object and remote is the interface.
Inheritance
We often come across words saying that guy has inherited most of his father’s style or something like that.What exactly it mean.It mean that both the father and the son have commonality in them.Similary in java one class can inherit the other class.The class which is inherited is called as superclass and the one who inherit it is called as subclass.
A subclass is a kind of superclass.Now lets dig more in to it in terms of java ,Lets suppose we have a class called “two wheeler” as clear from the name,This class contain variables like wheel,gear,brakes and methods run stop.Now any other classes like herohonda,yamaha should be a subclass for the “two wheeler” class as “two wheeler” class is the superclass which defines all the basic format for a two wheel vehicle so it does not depend whether it is a herohonda motorcycle or a yamaha ,they have to have the brakes,gears and methods to run ,stop.But herohonda or yamaha can have there extra variable and methods in addition to the methods and variables defined in super class,i.e.
Herohonda can implement its own quickstart method,yamaha can have its own lighting on-off mechanism.So a subclass object should have all the variables and methods of a superclass object and in addition it can have its own methods and variables.
Polymorphism
Polymorphism means many forms.It means one operation can be perfomed by different methods or different ways.Suppose we have three person A,B and C all of them go to office by their own convenient way.A prefers to walk ,B uses motorcycle and C uses a Car.One important requirement of polymorphism is that same operation should be called for all the objects.So in our case if we issue an operation go to office then for the three person A,B and C the operation will be same but the way of going to office is different.
So Essentially a polymorphism requires that an object should send same message to different objects,enabling different objects to repsond in their own way.Polymorphism requires that the different objects implementing the same operation must have same semantics.In java we use the concept of polymorphism in overloading and overriding.
For the time being overloading a method mean using the same semantics but with different parameters to call a method and over riding means the sub class defining the same method in its own term as in the superclass.Java does not support operator overloading .Opearator overloading is supported only for + operator.
We will be covering all these definition later also when we will start programming.
Java Package
In java certain classes are grouped together in to a package as per their functionality.For example
Java.lang –contains all language functions
Java.io-Interface for all input/output operation.
And many more
When we write any java programme the very first line in the code is the package name i.e which package does this programme belong to.This is done essentially to separate two different programmes from each other.It is sort of name space in xml.If two classes have same name they can be differentiated by their package name.A good programming practice is that we should have a package and should have two folders source and code for .java file and for .class file.I will suggest to download the java SE documentation to understand the various package interface classes and methods avaialable.
You can go to www.sun.java.com go to java documentation there and download the java se documentation.
Contents of a java file
A java file should essentially contains the following things
1>the first statement should be the package keyword followed by the package name.
2>zero or more import statement followed by the class name.
3>One or more class or interface defintion followed by the blocks defining them.
Programming in java
Now we will start with the concept of programming.We will write a simple java programme,will see what are the different fields in there and how does it compile and execute.
For this we need to write a class.To define a class we need to have following things
1>Access modifier.-It specifies the availablility of the class from other classes.
2>Class keyword.-It tells java that the following block of code makes a class.
3>Instance filelds.-Constants and variable that are used by the object of class.
4>Consrtuctor.It is a method which has the same name as the name of the class and it is used to control the initial state of the object of a class created.
5>Instance methods.-It is the method within the class to perform the action.
6>Class fields-Constants and variables which are shared by all objects of that class.
7>Class methods-Methods that are used to control the value of class fields.
Understanding main() Method
AS we have seen earlier an interpreter need a main method to start the programme.One class should have one main method to start its execution or we can say it in other words that main the entry point for interepreter to start it.We need define main programme when we are writing an application however when you are writing an applete you need not define a main method as the browser has its own way of starting.
Important points about a main method
1>A main method must exist within a class.
2>It should have the following format
(Access modifier ) (static keyword) (return type) (arguments)
then the block of the code.
So a common format of a main method will be
public static void main(String[] args)
here public is an access modifier,static is a keyword ,void is the rerturn type and String[] args is the argument type.
We have used a term Access modifier what does it mean.It mean the accessibility of the method.
Access modifier are of four type
1.>Public-Public methods can be used by any one.
2>Priavte-Private methods can be seen or used only by the methods within the class.
3>Protected-Protected methods can be accessed by all the classed within the same package and all the derived class(class which are inherited)
4>Default-If you do not specify any access modifier it mean it is of default type.A default method can be accessed only by the derivative and classes within that packageEven a derivative outside the package can not access this method.
Static Keyword-
If a method or variable is define as static it becomes a class method/class variable.
It means that it applies to the class of the object as a whole and not as individual objects hence it is shared by all the objects of the class.
Return Type
A return type is always required in a method.The return type defines the object type that is returned when a method is completed.It can stiring ,integer,object or void value.By default there is not return type in a method.
Arguments
Arguments are the parameters which are required for the method to perform its function.
Example programme
So far what all we have studied we will check them through programme.Hence I will write a simple programme to illustrate various parameters in a java code.Lets check this simple programme.
package practice;
public class Example {
static int phone;
int name;
String value;
public Example() {
}
public static void main(String[] args) {
Example exam = new Example();
System.out.println("This is the entry point for the interpreter");
System.out.println("Value of name =" + exam.name);
System.out.println("Class variable=" + phone);
}
}
Looking from the beginning.I have specified the name of the package.I am not importing any class so I have not used any import statement.
Public class example
Public is the access modifier class is the keyword for defining class and example is the name of my class.One very important point to note here is that the name of the programme should be same as the name of the class and it is case sensitive.So in our case the java code should be saved as Example.java and not example.java.
Next name and value parameter are instance varaibles they can be accessed by methods in a class through object of the class.However variable phone is a class variable and as we have discussed a class variable is present for all the object of the class.
Next is our main method
We are then creating an object for the class example.
Next is we have the system defined command to print the variable values.
If you look in to the code you will find a block called
public Example() {
}
This is the constructor block. And is called when we create a new object for the example class.If you have not defined a constructor the java will provide automatically a default constrructor for the programme.
The instance variables and class variable are assigned a default values as soon as we declare them as here int will have a default value of zero ,string will have a default value of null and so on.
Now look at the two print out statement we are accessing the instance variable name through an object of the class however we are accessing the class variable directly.This is because it is static variable and a static variable can be called directly within a method.
Now we will compile this project.
To compile you have just write
Javac Example.java
I believe you already have set your class path and path variable.This command will cause a .class file to generate in the same location where in where Example.java resides.
Now to run this .class file you need to issue the following command
Java Example
It will give you the following result
E:\jdeveloper\jdk\bin\javaw.exe -client -classpath E:\jdeveloper\jdev\mywork\Application1\Practice\classes practice.Example
This is the entry point for the interpreter
Value of name =0
Class variable=0
Since I am using the IDE Jdeveloper to run my program I am getting jdev jdk as my classpath.
Please check all my class files are generated within the practice package.
You can set the path and class path from command window also by using set command
Aslo during compile time you can provide the class path as follows
Javac –classpath
-d
No comments:
Post a Comment