Blogger templates

Your Ad Here

Video

Blogroll

Blogger news

"Hello World" in Openlaszlo

Lets start with Hello world program using openlaszlo like any other programming language and framework.

1.Create a file helloworld.lzx inside the Hello World folder. 

2. <canvas debug = "true">
   <text id =helloworld>Hello world</text>
   </canvas> 

3. Browse to the following location on your browser:  http://127.0.0.1:8080/lps-4.4.0/Workspace/HelloWorld/helloworld.lzx


4. Thats its...You have completed writing the first openlaszlo program.


Explanation : Hello World 

1. Every openlaszlo program file have an extension .lzx

2. Every laszlo code is wrapped inside  <canvas></canvas> tag  

3.<text></text> is a class used for non-editable text fields. Here it will simply display Hello World on the browser.


Next : How to debug in Openlaszlo 

 

Setting up Openlaszlo development environment

1. Firstly, download the latest openlaszlo release 4.4 from http://openlaszlo.org/download  or alternatively download directly from  http://download.openlaszlo.org/4.4.0/openlaszlo-4.4.0-windows-dev-install.exe

2. Double click and install the setup. On WinXP, it installs in the following location. C:\Program Files\OpenLaszlo Server 4.4.0 

3. Upon installation tomcat server will start automatically. If it doesn’t, click the following file to start the tomcat server. C:\Program Files\OpenLaszlo Server 4.4.0\Server\lps-4.4.0\lps\utils\startTomcat.bat 

4. At any point in time when you want to stop the tomcat server, click the stopTomcat.bat file lying in the  same folder.  

5. Browse to the following location on your browser, to see the opening welcome screen  http://127.0.0.1:8080/lps-4.4.0/laszlo-explorer/index.jsp  

6. Create a folder inside C:\Program Files\OpenLaszlo Server 4.4.0\Server\ lps-4.4.0, called Workspace. All our developments using openlaszlo will be doing in this directory.

7. Next we will see how to create a openlaszlo program. Lets start with "Hello world" program. Create a folder called HelloWorld inside Workspace.



 

Class Based Object Oriented Programming


A class is the implementation of an abstract data type (ADT). It defines attributes and methods which implement the data structure and operations of the ADT, respectively. Instances of classes are called objects. Consequently, classes define properties and behaviour of sets of objects
Class-based programming, or more commonly class-orientation, refers to the style of object-oriented programming in which inheritance is achieved by defining classes of objects, as opposed to the objects themselves.

 

For example : 

 

Class fruit {

       String colour;

       String taste; 

       String getTaste(); 

}



Here fruit is a class with color and  taste are the attributes and getTaste() is the method for getting the taste of the fruit. Here the class has a self existence and a meaning of its own. That is what object oriented concept means.


Class-based model, as opposed to an object-based model, is the most popular and developed model of OOP. In this model, objects are entities that combine state (i.e., data), behavior (i.e., procedures, or methods) and identity (unique existence among all other objects). The structure and behavior of an object are defined by a class, which is a definition, or blueprint, of all objects of a specific type. An object must be explicitly created based on a class and an object thus created is considered to be an instance of that class. An object is similar to a structure, with the addition of method pointers, member access control, and an implicit data member which locates instances of the class (i.e. actual objects of that class) in the class hierarchy (essential for runtime inheritance features). 


 

Access Specifiers In Object Oriented Programming


The main purpose of using access specifiers is to provide security to the applications. The availability (scope) of the member objects of a class can be controlled using access specifiers.
PUBLIC: As the name specifies, it can be accessed from anywhere in the project. If a member of a class is defined as public then it can be accessed anywhere in the class as well as outside the class. This means that objects can access and modify public fields, properties, methods.
Its just like a public property. Anyone can use,modify without any permission. Making and object or method should be done in extreme care, since anyone will be able to modify the value.
PRIVATE: As the name suggests, it can't be accessed outside the class. Its the private property of the class and can be accessed only by the members of the class.
This is like an object in our home. We will not allow an outside agent to change or even access that. In programs we will make an objects or methods private only if it has the use only in that particular class.
PROTECTED: Protected variables can be used within the class as well as the classes that inherites this class.
Protected is just like a family matter. All the members in that particular family will be allowed to view or modify.
DEFAULT: A Default property is a single property of a class that can be set as the default. This allows developers that use your class to work more easily with your default property because they do not need to make a direct reference to the property. Default properties cannot be initialized as Shared/Static or Private and all must be accepted at least on argument or parameter. Default properties do not promote good code readability, so use this option sparingly. 




Next : Class Based Object Oriented Programming 
 

Inheritance in Object Oriented Programming

Inheritance provides a powerful and natural mechanism for organizing and structuring software.Classes inherit state and behavior from their superclasses, and explains how to derive one class from another using the simple syntax provided by the Java programming language. In object-oriented programming, inheritance is a way to form new classes (instances of which are called objects) using classes that have already been defined.
The new classes, known as derived classes, take over (or inherit) attributes and behavior of the pre-existing classes, which are referred to as base classes (or ancestor classes). It is intended to help reuse existing code with little or no modification.
An advantage of inheritance is that modules with sufficiently similar interfaces can share a lot of code, reducing the complexity of the program. Inheritance therefore has another view, called polymorphism, which describes many pieces of code being controlled by shared control code. Inheritance is typically accomplished either by overriding (replacing) one or more methods exposed by ancestor, or by adding new methods to those exposed by an ancestor. 


For example :
We can inherit all properties of a vehicle, like wheels, engine etc. to an object car. That means a "car is a vehicle". Car will have all the properties of a vehicle plus some unique features.


Next : Access Specifiers In Object Oriented Programming 
 

Object Oriented Programming Overview

The concepts of Object-Oriented programming have been there for over three-four decades. Initially developed as a means of developing systems that better reflected real life needs and were more user friendly. OO’s popularity and sophistication has increased in the past several years as businesses are abandoning their mainframe systems and incorporating more client-server models to run their businesses and are integrating web technology as a business tool. One of the primary features of OO programming is its relative flexibility and easily adaptability to changing business needs.
When the hardware and software became increasingly complex, quality was often compromised in different phases. As a result, researchers studied ways to maintain software quality and developed object-oriented programming in part to address common problems reusable units of programming logic. The methodology focuses on data rather than processes, with programs composed of self-sufficient modules (objects) each has a independent existence and data structure. This is in contrast to the existing modular programming which had been dominant for many years that focused on the function of a module, rather than specifically the data. 
An object-oriented program may be viewed as a collection objects, as opposed to the conventional model, in which a program is seen as a list of tasks (subroutines) to perform. In OOP, each object is capable of receiving messages, processing data, and sending messages to other objects and can be viewed as an independent 'machine' with a distinct role or responsibility. 
The Simula programming language was the first to introduce the concepts underlying object-oriented programming (objects, classes, subclasses, virtual methods, coroutines, garbage collection, and discrete event simulation) as a superset of Algol. Simula was used for physical modeling, such as models to study and improve the movement of ships and their content through cargo ports. Smalltalk was the first programming language to be called "object-oriented".




Next : Inheritance in Object Oriented Programming

Object Oriented Programming

Object-oriented programming (OOP) is a programming paradigm that uses "objects" and their interactions to design applications and computer programs.
Programming techniques may include features such as encapsulation, modularity, polymorphism, and inheritance. It was not commonly used in mainstream software application development until the early 1990s. Many modern programming languages now support OOP.
Languages which are designed with the OOP paradigm allow programmers to think in new ways. They will also support inheritance, and instead of using function calls, they will use messages. The goal of a computer program is to alter data. What the program does to the data is more important than how it does it.
Object-oriented programming is a method of programming based on a hierarchy of classes, and well-defined and cooperating objects.
Object-Oriented Programming has the following advantages over conventional approaches:
  • OOP provides a clear modular structure for programs which makes it good for defining abstract datatypes where implementation details are hidden and the unit has a clearly defined interface.                     
  • OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones. 

OOP provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces.  
One object-oriented concept that helps objects work together is inheritance. Inheritance defines relationships among classes in an object-oriented language. In the Java programming language, all classes descend from java.lang.Object and implement its methods. 

Create SqlMapConfig.xml


Consider the following:
  • We are going to use JDBC to access the database testdb.
  • JDBC driver for MySQL is "com.mysql.jdbc.Driver".
  • Connection URL is "jdbc:mysql://localhost:3306/testdb".
  • We would use username and password is "root" and "root".
  • Our sql statement mappings for all the operations would be described in "Employee.xml".
Based on the above assumption we have to create an XML configuration file with name SqlMapConfig.xml with the following content. This is where you need to provide all configurations required for iBatis:
It is important that both the files SqlMapConfig.xml and Employee.xml should be present in the class path. For now we would keep Employee.xml file empty and we would conver its content in subsequent chapters.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">

<sqlMapConfig>
<settings useStatementNamespaces="true"/>
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver"
value="com.mysql.jdbc.Driver"/>
<property name="JDBC.ConnectionURL"
value="jdbc:mysql://localhost:3306/testdb"/>
<property name="JDBC.Username" value="root"/>
<property name="JDBC.Password" value="root"/>
</dataSource>
</transactionManager>
<sqlMap resource="Employee.xml"/>
</sqlMapConfig>


IBATIS Installation


Here are the simple steps you would need to carry out to install iBATIS on your Linux machine:
  • Download latest version of iBATIS from Download iBATIS.
  • Unzip the downloaded file to extract .jar file from the bundle and keep it in appropriate lib directory.
  • Set PATH and CLASSPATH variables at the extracted .jar file(s) appropriately.
Here are the steps I carried out on my linux machine after downloading iBATIS binary file:
 
$ unzip ibatis-2.3.4.726.zip
inflating: META-INF/MANIFEST.MF
creating: doc/
creating: lib/
creating: simple_example/
creating: simple_example/com/
creating: simple_example/com/mydomain/
creating: simple_example/com/mydomain/data/
creating: simple_example/com/mydomain/domain/
creating: src/
inflating: doc/dev-javadoc.zip
inflating: doc/user-javadoc.zip
inflating: jar-dependencies.txt
inflating: lib/ibatis-2.3.4.726.jar
inflating: license.txt
inflating: notice.txt
inflating: release.txt
$pwd
/var/home/ibatis
$set PATH=$PATH:/var/home/ibatis/
$set CLASSPATH=$CLASSPATH:/var/home/ibatis\
/lib/ibatis-2.3.4.726.jar


 
Next : Create sqlmapconfig.xml

iBATIS vs Hibernate



There are many differences between iBatis and Hibernate but both the solutions work well, given their specific domain.
  • You want to create your own SQL's and are willing to maintain them.
  • your environment is driven by relational data model.
  • you have to work existing and complex schema's.
And simply use Hibernate if:
  • Your environment is driven by object model and wants generates SQL automatically.
To count there are few differences:
  • iBATIS is:
    • Simpler
    • Faster development time
    • Flixable
    • Much smaller in package size
  • Hibernate:
    • Generates SQL for you which means you don't spend time on SQL
    • Provides much more advance cache
    • Highly scalable
Other difference is that iBATIS makes use of SQL which could be database dependent where as Hibernate makes use of HQL which is relatively independent of databases and it is easier to change db in Hibernate.
Hibernate maps your Java POJO objects to the Database tables where as iBatis maps the ResultSet from JDBC API to your POJO Objets.
If you are using stored procedures, well you can do it in Hibernate but it is little difficult in comparision of iBATIS. As an alternative solution iBATIS maps results sets to objects, so no need to care about table structures. This works very well for stored procedures, works very well for reporting applications, etc
Finally, Hibernate and iBATIS both are open source Object Relational Mapping(ORM) tools available in the industry. Use of each of these tools depends on the context you are using them. Hibernate and iBatis both also have good support from SPRING framework so it should not be a problem to chose one of them.

Next : Ibatis installation 

Advantages of IBATIS

Few advantages of using IBATIS:
  • Suppports Stored procedures: iBATIS encapsulates SQL in the form of stored procedures so that business logic is kept out of the database, and the application is easier to deploy and test, and is more portable.
  • Supports Inline SQL: No precompiler is needed, and you have full access to all of the features of SQL.
  • Supports Dynamic SQL: iBATIS provides features for dynamically building SQL queries based on parameters.
  • Supports O/RM: iBATIS supports many of the same features as an O/RM tool, such as lazy loading, join fetching, caching, runtime code generation, and inheritance.



    Next : Ibatis vs Hibernate 

IBATIS Design Advantages

IBATIS has the following design advantages
  • Simplicity: iBATIS is regarded as one of the simplest persistence frameworks available today.
  • Fast Development: iBATIS's is mainly focused to do all it can to facilitate hyper-fast development.
  • Portability: iBATIS can be implemented for any language or platform like Java, Ruby, and C# for Microsoft .NET.
  • Independent Interfaces: iBATIS provides database-independent interfaces and APIs that help the rest of the application remain independent of any persistence-related resources,
  • Open source: iBATIS is free and an open source software. This helps many to use the resource whenever needed.

      
    Next: Advantages of ibatis 
 

Most Reading

Stats