Parag’s Den

Dedicated to my adored friends…..

Archive for the ‘4. Learn’ Category

JDBC Driver Types

Posted by paragdongre on April 16, 2009

JDBC drivers are divided into four types or levels. The different types of jdbc drivers are:

Type 1: JDBC-ODBC Bridge driver (Bridge)
Type 2: Native-API/partly Java driver (Native)
Type 3: AllJava/Net-protocol driver (Middleware)
Type 4: All Java/Native-protocol driver (Pure)

4 types of jdbc drivers are elaborated in detail as shown below:

Type 1: JDBC-ODBC Bridge driver

The Type 1 driver translates all JDBC calls into ODBC calls and sends them to the ODBC driver. ODBC is a generic API. The JDBC-ODBC Bridge driver is recommended only for experimental use or when no other alternative is available.

jdbc-type1-driver

Advantage
The JDBC-ODBC Bridge allows access to almost any database, since the database’s ODBC drivers are already available.

Disadvantages
1. Since the Bridge driver is not written fully in Java, Type 1 drivers are not portable.
2. A performance issue is seen as a JDBC call goes through the bridge to the ODBC driver, then to the database, and this applies even in the reverse process. They are the slowest of all driver types.
3. The client system requires the ODBC Installation to use the driver.
4. Not good for the Web.

Type 2: Native-API/partly Java driver

The distinctive characteristic of type 2 jdbc drivers are that Type 2 drivers convert JDBC calls into database-specific calls i.e. this driver is specific to a particular database. Some distinctive characteristic of type 2 jdbc drivers are shown below. Example: Oracle will have oracle native api.
jdbc-type2-driver

Advantage
The distinctive characteristic of type 2 jdbc drivers are that they are typically offer better performance than the JDBC-ODBC Bridge as the layers of communication (tiers) are less than that of Type
1 and also it uses Native api which is Database specific.

Disadvantage
1. Native API must be installed in the Client System and hence type 2 drivers cannot be used for the Internet.
2. Like Type 1 drivers, it’s not written in Java Language which forms a portability issue.
3. If we change the Database we have to change the native api as it is specific to a database
4. Mostly obsolete now
5. Usually not thread safe.

Type 3: All Java/Net-protocol driver

Type 3 database requests are passed through the network to the middle-tier server. The middle-tier then translates the request to the database. If the middle-tier server can in turn use Type1, Type 2 or Type 4 drivers.

jdbc-type3-driver

Advantage
1. This driver is server-based, so there is no need for any vendor database library to be present on client machines.
2. This driver is fully written in Java and hence Portable. It is suitable for the web.
3. There are many opportunities to optimize portability, performance, and scalability.
4. The net protocol can be designed to make the client JDBC driver very small and fast to load.
5. The type 3 driver typically provides support for features such as caching (connections, query results, and so on), load balancing, and advanced
system administration such as logging and auditing.
6. This driver is very flexible allows access to multiple databases using one driver.
7. They are the most efficient amongst all driver types.

Disadvantage
It requires another server application to install and maintain. Traversing the recordset may take longer, since the data comes through the backend server

Type 4: All Java/Native-protocol driver

The Type 4 uses java networking libraries to communicate directly with the database server.

jdbc-type4-driver

Advantage
1. The major benefit of using a type 4 jdbc drivers are that they are completely written in Java to achieve platform independence and eliminate deployment administration issues. It is most suitable for the web.
2. Number of translation layers is very less i.e. type 4 JDBC drivers don’t have to translate database requests to ODBC or a native connectivity interface or to pass the request on to another server, performance is typically quite good.
3. You don’t need to install special software on the client or server. Further, these drivers can be downloaded dynamically.

Disadvantage
With type 4 drivers, the user needs a different driver for each database.

Posted in - Java | 1 Comment »

Java Database Connectivity

Posted by paragdongre on April 16, 2009

The JDBC ( Java Database Connectivity) API defines interfaces and classes for writing database
applications in Java by making database connections. Using JDBC you can send SQL, PL/SQL
statements to almost any relational database. JDBC is a Java API for executing SQL statements
and supports basic SQL functionality. It provides RDBMS access by allowing you to embed SQL
inside Java code. Because Java can run on a thin client, applets embedded in Web pages can
contain downloadable JDBC code to enable remote database access. You will learn how to
create a table, insert values into it, query the table, retrieve results, and update the table with
the help of a JDBC Program example.

Although JDBC was designed specifically to provide a Java interface to relational databases,
you may find that you need to write Java code to access non-relational databases as well.

JDBC Architecture
jdbc1
Java application calls the JDBC library. JDBC loads a driver which talks to the database.
We can change database engines without changing database code.

Java Database Connectivity Steps
Before you can create a java jdbc connection to the database, you must first import the
java.sql package.
import java.sql.*; The star ( * ) indicates that all of the classes in the package java.sql are
to be imported.

1. Loading a database driver,
In this step of the jdbc connection process, we load the driver class by calling Class.forName()
with the Driver class name as an argument. Once loaded, the Driver class creates an instance
of itself. A client can connect to Database Server through JDBC Driver. Since most of the
Database servers support ODBC driver therefore JDBC-ODBC Bridge driver is commonly used.
The return type of the Class.forName (String ClassName) method is “Class”. Class is a class in
java.lang package.
try {
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); //Or any other driver
}
catch(Exception x){
System.out.println( “Unable to load the driver class!” );
}

2. Creating a oracle jdbc Connection

The JDBC DriverManager class defines objects which can connect Java applications to a JDBC driver. DriverManager is considered the backbone of JDBC architecture. DriverManager class manages
the JDBC drivers that are installed on the system. Its getConnection() method is used to establish
a connection to a database. It uses a username, password, and a jdbc url to establish a connection
to the database and returns a connection object. A jdbc Connection represents a session/connection
with a specific database. Within the context of a Connection, SQL, PL/SQL statements are executed
and results are returned. An application can have one or more connections with a single database,
or it can have many connections with different databases. A Connection object provides metadata i.e. information about the database, tables, and fields. It also contains methods to deal with transactions.
JDBC URL Syntax:: jdbc: :

JDBC URL Example:: jdbc: : •Each driver has its own subprotocol
•Each subprotocol has its own syntax for the source. We’re using the jdbc odbc subprotocol, so the DriverManager knows to use the sun.jdbc.odbc.JdbcOdbcDriver.
try{
Connection dbConnection=DriverManager.getConnection(url,”loginName”,”Password”)
}
catch( SQLException x ){
System.out.println( “Couldn’t get connection!” );
}

3. Creating a jdbc Statement object
Once a connection is obtained we can interact with the database. Connection interface defines
methods for interacting with the database via the established connection. To execute SQL
statements, you need to instantiate a Statement object from your connection object by using the createStatement() method.
Statement statement = dbConnection.createStatement();
A statement object is used to send and execute SQL statements to a database.
Three kinds of Statements
Statement: Execute simple sql queries without parameters.
Statement createStatement()
Creates an SQL Statement object.
Prepared Statement: Execute precompiled sql queries with or without parameters.
PreparedStatement prepareStatement(String sql)
returns a new PreparedStatement object. PreparedStatement objects are precompiled
SQL statements.
Callable Statement: Execute a call to a database stored procedure.
CallableStatement prepareCall(String sql)
returns a new CallableStatement object. CallableStatement objects are SQL stored procedure
call statements.

4. Executing a SQL statement with the Statement object, and returning a jdbc resultSet.

Statement interface defines methods that are used to interact with database via the execution
of SQL statements. The Statement class has three methods for executing statements:
executeQuery(), executeUpdate(), and execute(). For a SELECT statement, the method to use is executeQuery . For statements that create or modify tables, the method to use is executeUpdate. Note: Statements that create a table, alter a table, or drop a table are all examples of DDL
statements and are executed with the method executeUpdate. execute() executes an SQL
statement that is written as String object.
ResultSet provides access to a table of data generated by executing a Statement. The table
rows are retrieved in sequence. A ResultSet maintains a cursor pointing to its current
row of data. The next() method is used to successively step through the rows of the tabular results.
ResultSetMetaData Interface holds information on the types and properties of the columns in
a ResultSet. It is constructed from the Connection object.

Test JDBC Driver Installation

import javax.swing.JOptionPane;

public class TestJDBCDriverInstallation_Oracle {

public static void main(String[] args) {
StringBuffer output = new StringBuffer();
output.append(“Testing oracle driver installation \n”);
try {
String className = “sun.jdbc.odbc.JdbcOdbcDriver”;
Class driverObject = Class.forName(className);
output.append(“Driver : “+driverObject+”\n”);
output.append(“Driver Installation Successful”);
JOptionPane.showMessageDialog(null, output);
} catch (Exception e) {
output = new StringBuffer();
output.append(“Driver Installation FAILED\n”);
JOptionPane.showMessageDialog(null, output);
System.out.println(“Failed: Driver Error: ” + e.getMessage());
}
}
}

Java JDBC Connection Example, JDBC Driver Example

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBCDriverInformation {
static String userid=”scott”, password = “tiger”;
static String url = “jdbc:odbc:bob”;
static Connection con = null;
public static void main(String[] args) throws Exception {
Connection con = getOracleJDBCConnection();
if(con!= null){
System.out.println(“Got Connection.”);
DatabaseMetaData meta = con.getMetaData();
System.out.println(“Driver Name : “+meta.getDriverName());
System.out.println(“Driver Version : “+meta.getDriverVersion());

}else{
System.out.println(“Could not Get Connection”);
}
}

public static Connection getOracleJDBCConnection(){

try {
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
} catch(java.lang.ClassNotFoundException e) {
System.err.print(“ClassNotFoundException: “);
System.err.println(e.getMessage());
}

try {
con = DriverManager.getConnection(url, userid, password);
} catch(SQLException ex) {
System.err.println(“SQLException: ” + ex.getMessage());
}

return con;
}

}

Posted in - Java | Leave a Comment »

Java Basics

Posted by paragdongre on April 16, 2009

History of Java
Java was developed by a team led by James Gosling at Sun Microsystems , a company best known by for its workstations. Java was originally called Oak and designed for use in embedded consumer electronic applications in 1991. It was redesigned for developing Internet application and renamed Java in 1995. Java Program can be embedded in HTML pages and downloaded by Web Browsers to bring live animation and interaction to Web clients.
The power of Java is not limited to web applications. Java is a general purpose programming language. It has full programming features and can be used to develop stand alone applications. Java is inherently object – oriented. Although many object- oriented languages began strictly as procedural languages. Java was designed to be object oriented from the start. Object oriented programming (OOP) is currently popular programming approach that replaces the traditional procedural programming technique.
Characteristics of Java
At the designed time of Java three main objective are taken into consideration viz. Portability (Platform Independent) , Architecture Neutral (Hardware Configuration of Machine), Security of programming codes. But apart from the these main character Java has so many another character. They are as follows.
A) Simple
B) Secure
C) Portable
D) Object-Oriented
E) Robust
F) Multithreaded
G) Architectural Neutral
H) Interpreted
I) High Performance
J) Distributed
K) Dynamic

    Simple :

No one language is Simple to learn but Java is bit easier compared to the popular Object Oriented Programming language like C++. Actually Java is partially modeled after C++ means it uses C++ programming syntax and object oriented features. But Java is great simplified and improved. For instance Pointers and Multiple Inheritance concepts are eliminated from Java instead of this simple structure interfaces are introduced. In Java specification we have so many in built packages, classes and method so that we can reuse it without rewriting the codes.
Java uses automatic memory allocation and garbage collection while in C++ we have to require to allocate memory to garbage collection.

    Java is Object Oriented

Object oriented programming models the real world. Everything in the world can be modeled as an object. A circle, A person, A window icon is an object. A Java Program is called object – oriented because programming in Java is centered on creating objects , manipulating objects and making objects working together. Java program is mostly a collection of objects talking to other objects by invoking each other’s methods. Every object is of certain type and that type is defined by a class or an interface. Most Java Program use a collection of objects of many different type.
i)Class : A template that describe the kinds of state and behavior that objects of its type support.
ii)Object: At runtime , when the Java Virtual Machine (JVM) encounters the new keyword , it will use the appropriate class to make an object which is an instance of that class. For Example
Suppose Demo is a class and is define as
Public class Demo
{
Int a , b; // instance variables
Public void show() // behavior (instance method)
{
System.out.println(“A: “+a+”B: “+b);
}
}
Statement for creating object is:
Demo d = new Demo();
Above statement is defined as with the help new keyword called to the constructor of data type of class Demo and after calling of the constructor initialize the member variable with their default value of their respective data types if not explicitly define and allocate the memory space and reference of this Object are kept into the reference variables d of type Demo . That object will have its own state , and access to all of the behaviors defined by its class.
iii)State (instance variable) : Each object (instance of a class) will have its own unique set of instance variables as defined in the class. The value assigned to an object’s instance variables make up the object’s state.
iv) Behavior(method) : When programmer creates the class he creates the methods for that class. Methods are where the class’ logic is stored. Methods are where the real work gets done. They are where algorithms get executed and data gets manipulated.
In short , An object has a properties and behaviors. Properties are described by using data and behaviors are defined by using methods. Objects are defined by using classes in Java. A class is like a template for the objects. An Object is a concrete realization of a class description.

    Java is distributed:

Distributed computing involves several computers on a network working together. Java is designed to make distributed computing easy because it handles TCP / IP protocols

    Java is interpreted: (Platform Independent)

The java programs are compiled into Machine code called bytecode. This code can be interpreted on any system that provides a Java Virtual Machine. This Bytecode is machine independent and can run on any machine that has a java interpreter. Usually a compiler translates a high level language program to machine code. The code can only run on the native machine. If you want this same program on other machine, the program has to be recompiled on native machine. For instance, if you compile C program in widows, the executable code generated by the compilers can only run on the windows platform.
With Java, you compile the source code once and the bytecode generated by Java compliers can run on any platform. The Java Program does not need to be recompiled on a target machine.

    Java is Robust:

Robust means reliable. Early checking for possible errors (mishandled exceptional conditions) during execution time with the help of object oriented exception handling construct. Java has a runtime exception handling feature to provide programming support for robustness. Java can catch and respond to an exceptional situation so that the program continues its normal execution and terminate gracefully when a runtime error occurs.
It does not support pointers which eliminate the possibility of overwriting memory and corrupting data. Java support automatic memory management by allocating memory to object if scope of object is over it automatically deallocate memory with help of Garbage Collection.

    Java is Secure

This required the elimination of many features of C and C++. Most notably there are no pointers in Java. Java programs cannot access arbitrary addresses in memory. All memory access is handled behind the scenes by the (presumably) trusted runtime environment. Furthermore Java has strong typing. Variables must be declared Casts are strictly limited to casts between types that make sense. Thus cast such as int to a long or a byte to a short can be done but not a long to a boolean or an int to a String.

Java implements a robust exception handling mechanism to deal with both expected and unexpected errors. The worst that an applet can do to a host system is bringing down the runtime environment.
Most importantly Java applets can be executed in an environment that prohibits them from introducing viruses, deleting or modifying files, or otherwise destroying data and crashing the host computer. A Java enabled web browser checks the byte codes of an applet to verify that it doesn’t do anything nasty before it will run the applet.
During runtime JVM only detect bytecode and any other are ignored that’s why there is no possibility of executing any other code. So no virus programs are executed. Hence Java code is bug free.

    Java is Architecture Neutral

The most remarkable feature of Java is that it is architecture neutral (platform independent). You can write one program that runs on any platform with JVM.

    Java is Portable

Java Program can run on any platform without having to be recompiled. In java language there is platform specific features in the Java Language Specification. For ex. In Ada language the largest integer varies on different platform. But in Java, the size of the integer is same on every platform. Having a fixed size for numbers makes the program portable. The Java environment itself is portable to new hardware and operating systems. In fact the Java compiler itself written in Java.

    Java is High Performance

Java byte codes can be compiled on the fly to code that rivals C++ in speed using a “just-in-time compiler.” Several companies are also working on native-machine-architecture compilers for Java. These will produce executable code that does not require a separate interpreter, and that is indistinguishable in speed from C++. The execution of the bytecode is never as fast as a complied language such as C++. Because Java is interpreted, the bytecode is not directly executed by the system. The bytecode is run through the interpreter.
It is certainly possible to write large programs in Java. The HotJava browser, the Java Workshop integrated development environment and the javac compiler are large programs that are written entirely in Java.

    Java is Multithreaded

Multithreading is the capability for a program to perform several tasks simultaneously within a program.
Java is inherently multi-threaded. A single Java program can have many different threads executing independently and continuously. Three Java applets on the same page can run together with each getting equal time from the CPU with very little extra effort on the part of the programmer.
Unfortunately multithreading is so tightly integrated with Java, that it makes Java rather difficult to port to architectures like Windows 3.1 or the PowerMac that don’t natively support preemptive multi-threading.
There is a cost associated with multi-threading. Multi-threading is to Java what pointer arithmetic is to C, that is, a source of devilishly hard to find bugs. Nonetheless, in simple programs it’s possible to leave multi-threading alone and normally be OK.

    Java is Dynamic

Java was designed to adapt to an evolving environment .Java Program carry with them substantial amounts of run time type information that is used to verify and resolve access to objects at run time. This makes it possible to dynamically link code in safe and expedient manner.
For Example : in the circle class you can add a new data property to indicate the color of the circle and a new method to obtain the circumference of the circle. The original client program that uses the Circle class remains the same. Also at runtime , Java loads classes as they are needed.
Java does not have an explicit link phase. Java source code is divided into .java files, roughly one per each class in the program. The compiler compiles these into .class files containing byte code. Each .java file generally produces exactly one .class file.
The compiler searches the current directory and directories specified in the CLASSPATH environment variable to find other classes explicitly referenced by name in each source code file. If the file that is compiled depends on other, non-compiled files the compiler will try to find them and compile them as well. The compiler is quite smart, and can handle circular dependencies as well as methods that are used before they’re declared. It also can determine whether a source code file has changed since the last time it was compiled.
More importantly, classes that were unknown to a program when it was compiled can still be loaded into it at runtime. For example, a web browser can load applets of differing classes that it’s never seen before without recompilation.
Furthermore, Java .class files tend to be quite small, a few kilobytes at most. It is not necessary to link in large runtime libraries to produce a (non-native) executable. Instead the necessary classes are loaded from the user’s CLASSPATH

    Java and Internet Programming (World Wide Web)

Java Program can run on from a Web Browser. Because Java is full blown programming language you can make the program responsive and interactive with the user. Java Program that run from Web page are called Applets.
Applets use a modern graphics user interface including button, text fields , text area , option buttons and so on. Applets can respond to user events such as mouse movements and keystrokes.

    Garbage Collection

There is no need to explicitly allocate or deallocate memory in Java. Memory is allocated as needed, both on the stack and the heap, and reclaimed by the garbage collector when it is no longer needed. There’s no malloc(), free(), or destructor methods.
There are constructors and these do allocate memory on the heap, but this is transparent to the programmer.
Most Java virtual machines use an inefficient, mark and sweep garbage collector.

Posted in - Java | Leave a Comment »

Flash Tweening

Posted by paragdongre on February 5, 2009

Tweening comes from the words “in between”.
With Tweening you can go from one keyframe to another and specify changes in the animation and let the Flash program create the frames in between.

Example

In this example we will learn how to make an object move across the screen.

<html><body>
<object width=”400″ height=”400″>
<param name=”movie” value=”ball.swf”>
<embed src=”ball.swf” width=”400″ height=”400″></embed>
</object>
</body></html>

Step 1
Create a small circle to the left in the Stage area. Do this by selecting the circle tool from the left toolbar. Draw the circle in the Stage area.
Step 2
Select the Arrow tool from the left toolbar. Double-click on the circle to select it.
Step 3
Now we have to convert the circle to a symbol. When the circle is converted to a symbol we can create instances of the circle. From the top menu choose Modify > Convert to Symbol. Name the symbol “Ball”, and select OK.
Step 4
Go to Frame 10 in the Timeline. Do this by clicking the gray field below 10. Then right click in this field. Choose Insert Keyframe. Keyframes appear as circles in a frame. This operation duplicates the image.
Note: A keyframe specifies changes in an animation. You create keyframes at important points in the Timeline and let Flash create the frames in between.
Step 5
Select the circle and move it to the right a couple of inches.
Step 6
Click on the Timeline any place between Frame 1 and Frame 10. Then right click and choose Create Motion Tween.
Step 7
Choose Control > Test Movie from the top menu to test your Flash movie.

    Flash Guide Tweening

With Motion Guide Tweening you can move an object from one location to another along a specified path.

Example
In this example you will learn how to draw a path an object should follow.

<html><body>
<object width=”400″ height=”400″>
<param name=”movie” value=”man.swf”>
<embed src=”man.swf” width=”400″ height=”400″></embed>
</object>
</body></html>

 

Step 1
Choose Window > Common Libraries > Graphics. Select the image you want to use. In this example we have used a Man.
Step 2
Click on the image and drag it outside the left edge of the Stage
Step 3
Go to Frame 40 in the Timeline. Do this by clicking the gray field below 40. Then right click in this field. Choose Insert Keyframe. Keyframes appear as circles in a frame. This operation duplicates the image.
Step 4
Click on the Timeline any place between Frame 1 and Frame 40. Then right click and choose Create Motion Tween.
Step 5
Right click on Layer 1 (Click on the layer name, where it says “Layer 1”). Choose Add Motion Guide in the pop-up menu. The Flash program will now insert a motion guide layer on top of layer 1. Motion guide layers are used to draw lines an animated symbol should follow.
Step 6
Click on the Motion Guide Layer to make sure it is the active layer (Click on the layer name, where it says “Guide: Layer 1”).
Step 7
Click on the Pencil tool in the left toolbox. Set the Pencil Mode to Smooth (in the Options section of the left toolbox).
Step 8
Draw a line. Begin on the image and draw a line to the other side of the Stage.
Step 9
Go back to Frame 1 in the Timeline. Click on the Arrow tool in the left toolbox. Select the “Snap to Objects” button in the Options section of the left toolbox.
Step 10
Place the image with its center on the beginning of the motion guide (the black line you have drawn with the Pencil). The center of the image shows as a +. A black circle appears when the image is snapped to the motion guide. Release the mouse button when the image is snapped to the guide.
Step 11
Go to Frame 40. Place the image with its center on the end of the motion guide.
Step 12
Choose Control > Test Movie from the top menu to test your Flash movie.

Is your Flash Movie Playing too Fast?

You can control this by selecting Modify > Movie from the top menu. A Movie Properties box will show. The Frame Rate field sets how many frames to display per second. Adjust the number to a lower number, and test your movie again.

 

    Flash Tint Tweening

With Tint Tweening you can change the color of an object.

Example
In this example you will learn how to change the color of an object.

<html><body>
<object width=”400″ height=”400″>
<param name=”movie” value=”changecolor.swf”>
<embed src=”changecolor.swf” width=”400″ height=”400″></embed>
</object>
</body></html>

Step 1
Choose Insert > New Symbol.
Note: To add Tint effects the object must be a symbol.
Step 2
Name the symbol “changecolor ” and select the Graphic option in Behavior. Click OK.
Note: You will now be taken to the symbol generator in the Flash program. Here you create symbols. Symbols can be dragged to the stage of your movie after you have created them. Step 3
Choose the Text tool in the left toolbox. Choose Text > Size > 36 from the top menu to make the text big. Choose Text > Style > Bold to make the text thick.
Step 4
Click in the work area and write “Demo: Color Changing Text”.
Step 5
Jump back to the movie. Do this by choosing Edit > Edit Movie.
Step 6
Insert the symbol you just created into the movie. Choose Window > Library. Select the “changecolor” symbol and drag it into the middle of the Stage.
Step 7
Insert a keyframe in Frame 15 and in Frame 30.
Step 8
Go to Frame 15. Right click on the text in the Stage. In the pop-up menu, choose Panels > Effect.
Step 9
Choose Tint from the drop down menu. A color map will show. Set the colors to: R=0, G=255, B=0.
Step 10
Click on the Timeline any place between Frame 1 and Frame 15. Then right click and choose Create Motion Tween.
Step 11
Click on the Timeline any place between Frame 15 and Frame 30. Then right click and choose Create Motion Tween.
Step 12
Choose Control > Test Movie from the top menu to test your Flash movie.

    Flash Shape Tweening

With Shape Tweening you can change one object into another.

Example
In this example you will learn how to change one object into another.

<html><body>
<object width=”400″ height=”400″>
<param name=”movie” value=”helloworld.swf”>
<embed src=”helloworld.swf” width=”400″ height=”400″></embed>
</object>
</body></html>

Step 1
Choose the Text tool in the left toolbox. Choose Text > Size > 48 from the top menu to make the text big. Choose Text > Style > Bold to make the text thick.
Step 2
Click in the work area and write “Learning”.
Step 3
Right click on the text you just wrote and choose Panels > Align from the pop-up menu.
Step 4
In the Align box select the “To Stage” button first. Then click on the “Align Horizontal Center” button and the “Align Vertical Center” button. Close the Align box.
Step 5
Select the Arrow Tool and click on the text. Choose Modify > Break Apart from the top menu.
Step 6
Insert keyframes at Frame 24, 50 and 51.
Step 7
Delete the text “Learning” in Frame 24. Select it and press the Delete button on your keyboard.
Step 8
Write a new text on the Stage. Write “Flash!” (Font size: 48, style: bold).
Step 9
Right click on the text you just wrote and choose Panels > Align from the pop-up menu. In the Align box select the “To Stage” button first. Then click on the “Align Horizontal Center” button and the “Align Vertical Center” button. Close the Align box.
Step 10
Select the Arrow Tool and click on the text. Choose Modify > Break Apart from the top menu.
Step 11
Insert a keyframe in Frame 26.
Step 12
Double click the keyframe in Frame 1. In the small pop-up box click on the Frame tab. Set Tweening to Shape. Close the pop-up box.
Step 13
Double click the keyframe in Frame 26. In the small pop-up box click on the Frame tab. Set Tweening to Shape. Close the pop-up box.
Step 14
Double click the keyframe in Frame 51. In the large pop-up box click on the Frame Actions tab. Click on the + sign. Choose Basic Actions > Go To. Close the pop-up boxes.
Step 15
Choose Control > Test Movie from the top menu to test your Flash movie.

Posted in - Flash | Leave a Comment »

Introduction to Flash

Posted by paragdongre on February 5, 2009

Flash is a tool for creating interactive and animated Web sites.

What you should already know ?
Before you continue you should have a basic understanding of the following:
• WWW, HTML and the basics of building Web pages

What is Flash?
• Flash is a multimedia graphics program specially for use on the Web
• Flash enables you to create interactive “movies” on the Web
• Flash uses vector graphics, which means that the graphics can be scaled to any size without losing clarity/quality
• Flash does not require programming skills and is easy to learn

Who can View Flash?
In September 2000, NPD Research, the parent company of MediaMetrix, conducted a study to determine what percentage of Web browsers have Flash preinstalled. The results show that 96.4% of Web users can experience Macromedia Flash content without having to download and install a player.
If you do not have the Shockwave Player installed you can download it for free from Adobe’s site.

Who can Create Flash Movies?
To create your own Flash movies you need to buy a Flash program.
The latest version from Adobe is Adobe Flash Lite (or Flash CS3 Pro).
If you do not have a Flash program, you can download a 30 days free trial version of Flash from Adobe.

Where to Start?
After you have installed Flash, you should go through the lessons that are included in the program. Start Adobe Flash, click Help in the menu and choose Lessons. These lessons will teach you the basics of Flash.

Flash Embedded in HTML

After creating a Flash movie you choose File > Save As from the top menu to save your movie. Save the file as “filename.fla”.

To embed the Flash movie you just made into an HTML page, you should go back to your Flash program and do the following steps:
Step 1
Choose File > Open. Open a Flash movie you have created.
Step 2
Choose File > Export Movie.
Step 3
Name the file “filename.swf”. Choose the location where the file is to be stored (in your Web folder). Click OK.
Step 4
Open the HTML page where you want to insert your Flash movie. Insert this code:

Note: This is the minimum code you need to embed a Flash movie in a browser. A broken icon will appear on the Web page if the user does not have the Flash plug-in installed.

Note: In the code above there is both an tag and an tag. This is because the tag is recognized by Internet Explorer, and Netscape recognizes the tag and ignores the tag.
Step 5
Type in the address of the HTML file in your browser and look at your first Flash movie.

Let the Flash Program do the Work
The code above is the absolute minimum code to embed Flash movies in HTML pages. It is not recommended to use the minimum code.
There should be a few more attributes added:
• classid is an attribute to the tag. It tells Internet Explorer to load the ActiveX plug-in if it is not installed
• pluginspage is an attribute to the tag. It displays a link to the Shockwave download page if Netscape does not have it
The Flash program can add these attributes for you:
Step 1
Choose File > Publish. Flash will now create the , , and tags for you. It will also create the classid and pluginspage attributes.
Step 2
Open the HTML document that Flash created, view the HTML source and copy the code into your HTML page where you want your Flash movie.
Step 3
Be sure that you have the “filename.swf” in your Web folder.
Step 4
Type in the address of the HTML file in your browser and look at your first Flash movie.

Posted in - Flash | Leave a Comment »

01- Introduction to VB.NET

Posted by paragdongre on June 4, 2008

What is VB.NET

Visual Basic .NET is Microsoft’s Visual Basic on their .NET framework. Visual Basic is an object oriented programming language. Any programmer can develop applications quickly with Visual Basic. It is a very user-friendly language. All you have to do is arrange components using visual tools and then write code for the components. Most programmers of Visual Basic use Visual Studio for their development needs. Moving forward, Microsoft’s .NET framework is composed of preprogrammed code that users can access anytime. This preprogrammed code is referred to as the class library. The programs in the class library can be combined or modified in order to suit the needs of programmers. Programs in .NET run on the CLR or the Common Language Runtime environment. Regardless of computer, as long as this environment is present, programs developed in a .NET language will run.

Evolution of VB.NET

Before VB .NET, there was VB and before there was VB, there was BASIC. BASIC stands for Beginner’s All-purpose Symbolic Instruction Code. It was developed in 1963 by computer scientists John Kemeny and Thomas Kurtz in Dartmouth College. It was a general purpose programming language that was intended for beginners. In 1975, when the MITS Altair 8800 Microcomputer was released, BASIC became Altair BASIC, developed by the computer heavyweights Bill Gates and Paul Allen. During the eighties, when the personal computer was starting to get into everyone’s homes, the BASIC computer language started to lose its hold on the market because more and more people and corporations were using computer programs for complex tasks rather than simple and “basic” tasks. In 1991, BASIC was infused with its Visual component and became Visual Basic. The new graphical user interface was pioneered by Alan Cooper. Visual Basic was not an instant hit at first due to compatibility issues but it began getting a solid following in the mid to late nineties when developers started becoming familiar with it. In the new millennium, the Visual Basic .NET became the successor of the Visual Basic programming languages.

Pros and Cons

Pros

  1. You can develop programs faster using the VB .NET programming language. You have so many resources in the .NET Class Library to take advantage of. VB .NET has full access to the .NET framework.
  2. It is easier to program using Microsoft development environments like Visual Studio.
  3. It is easier to organize your thoughts in an object-oriented programming language like VB .NET.
  4. There are a lot of books and tutorials to improve your skills in VB .NET.
  5. The VB language itself interfaces with Microsoft applications seamlessly (VBA).

Cons

  1. Debugging is very difficult on the VB .NET programming languages especially with long codes.
  2. You’ll spend hundreds of dollars purchasing development tools from Microsoft (Retail version of Visual Studio costs around $300).

Where is VB.NET Most Useful

The VB .NET programming language is most useful for rapid application development or RAD. If you want to get your programs up and running in a jiffy then you should use VB .NET. Since VB .NET is more suitable for quick and easy programming, it is not recommended for the large, enterprise-wide software development solutions. Debugging and finding your way through long and tangling lines of VB .NET code will simply give you headaches.

Getting Your Copy of VB.Net

Now that you understand what VB .NET is all about,you should get a copy of the programming language as soon as you can. You can either get a copy of Visual Basic at your local retailer or download a freeware version at the Microsoft website. If you want to get started right away, copy the following hyperlink to your browser’s address bar to download your freeware copy of Microsoft Visual Basic 2005 Express Edition – http://msdn.microsoft.com/vstudio/express/vb/you have to be patient because the file is quite large. If you have the time and the resources then you should get the latest versions of Visual Studio or Visual Basic. Once you have your own copy of Visual Basic, you will be on your way to learning one of the most powerful programming languages to date. Good luck in learning the VB .NET programming language!

 

Posted in - VB.Net | 1 Comment »

02- Microsoft Frameworks

Posted by paragdongre on June 4, 2008

.Net Framework

What is the Microsoft .NET framework?

You may be wondering why the .NET aspect of Visual Basic is so important in today’s times. In simple terms, .NET is a framework made by Microsoft so that developers can take advantage of code on the internet. Many developers through the years have developed code for their specific programming languages like C#, C++, Visual Basic, etcetera… Instead of making code over and over again, the .NET framework allows programmers and developers to use code on the .NET framework to aid in the development of their software programs. Imagine the .NET framework as sort of a file sharing program that benefits all the programmers across all the programming languages that use the .NET framework. When you program in Visual Basic .NET, you are taking advantage of a rich source of programming code that has been accumulated through the years.

What are the advantages of using the Microsoft .NET framework?

  • Code execution and deployment is made much simpler for developers.
  • Code execution and deployment is assured to be safe and free from viruses.
  • Programming models are now similar across different languages. Choosing a programming language is already up to you.
  • Programming models adhere consistently with object oriented styles.

Object Oriented Programming

Object oriented programming is a programming paradigm that makes use of objects to develop computer programs. When you objectify certain parts in a program or when you modularize it, you promote greater flexibility in overall programming. When you use object oriented programming languages, you can make objects interact with one another to accomplish goals. Instead of writing code one by one every time you make a program, you can use the previously designed objects to your advantage. The VB .NET language is one of the premiere object oriented programming languages in the market today.

In object oriented programming, objects interact with one another to produce the desired results from the programmer. This makes programming easier, less tedious, and more efficient.

Classes, Inheritance and Methods

Classes

Classes are used to describe objects. They are the overarching description of an object. For example, cat is a class that is used to describe an actual cat. If you have an actual cat named Garfield then it is an object. In the object oriented programming paradigm, it is important that you understand the difference between a class and an object. As you go on doing programming tasks, you need to understand these concepts in order to make your programming easier and much more effective.

Inheritance

Some classes will have subclasses. For example, if you mention the class cat then there can be a subclass lion, tiger, or cheetah. Subclasses are said to inherit the traits of its mother class. In the VB .NET programming language, objects inherit the properties of its mother objects.

Methods

Now that you are familiar with the essence of objects in object oriented programming, you should now familiarize yourself with what objects can do. The ability of an object to do something or perform a task is said to be its method or methods. If the object Garfield is of class dog and subclass house cat then it may have methods such as eating and meowing. An object in the VB .NET programming language may have one or more methods that you can take advantage of while developing your applications.

You will eventually learn how to use the several tools at your disposal in the later chapters. Once you are familiar with the core concepts of the VB .NET programming language, it will be easier for you to take advantage of the limitless possibilities before you. You will be using a lot of objects later on so make sure that you know what they are.

Microsoft SQL

Microsoft SQL stands for Microsoft Structured Query Language. The Microsoft SQL Server program uses the relational database management system. Microsoft SQL allows you to manipulate databases. Databases are basically repositories for data. If you want to store the grades of all the students in a university then you certainly need to have a database system around. Microsoft SQL also stores a lot of code that is available through the .NET platform. Stored procedures and several functions are made available for the programmer so that they could develop competitive applications quickly and efficiently. You will learn how to take advantage of the .NET codes available and the use of databases in the later chapters.

http://www.microsoft.com, Microsoft SQL Server is one of the premiere database management systems in the market today.

Getting your copy of Microsoft SQL

Now that you are familiar with the frameworks that are essential to run the VB .NET programming language, you may have to download them unless they are already installed on your computer. You can get a free copy of Microsoft SQL and the .NET framework at http://msdn.microsoft.com/vstudio/express/sql/download/. On the installation screen, you will be notified if there are already .NET frameworks installed on your computer. If there are no previously installed .NET programs then you may have to download the said files.

 

 

 

 

Posted in - VB.Net | Leave a Comment »

03- Forms

Posted by paragdongre on June 4, 2008

User Form and Toolbox

The User Form

The first thing that you should familiarize yourself with in the Visual Basic .NET programming language is the user form. The user form is the box where you can add all sorts of features. On older versions of Visual Basic, the user form has dots on it. The user form acts as a basic interactive tool between the programmer which is you and the one who will use the program.

 

 

You can add so many features and objects on your user form. These things are more commonly referred to as controls. Controls are such things like textboxes, comboboxes, option buttons, etcetera… You will learn more about certain controls in this chapter and the later chapters.

The Toolbox

Your Visual Basic program is equipped with a toolbox. You can access your toolbox anytime and manipulate your forms, controls, modules, etcetera… Simply click on a control and add it to your user form so that your user can access it when your program is run.

 

The controls that are going to be discussed in this chapter are the most basic. They are the label, the textbox, and the command button.

 

Just click on the corresponding buttons on your Toolbox to access the controls. Shown above are the respective buttons.

Labels, Textbox, Properties

The Label

The label is the way you put text on your user form. If you want your user to know what certain things are for then you have to use the label. Click on the label button and put a label on your user form.

The Textbox

The textbox is the way the user puts text on the user form. If you want an input in the form of text, number, or symbol, then you should simply put a textbox in your user form. Try putting a textbox on your user form now.

The Command Button

The command button is a control on the user form that is used to prompt action. Action can come in the form of running a code, closing an application, or simply clearing input made by a user. Click on the command button control on the toolbox and place one on your user form.

Properties

Every object that you have in your program will have properties. You can modify the properties of any object on the properties box. It is normally located in the lower right corner of your screen. You can modify attributes like the alignment, style, and labels. Modify the text that will appear on the first label that you created.

 

 

 

Posted in - VB.Net | Leave a Comment »

04- Basics of Programming

Posted by paragdongre on June 4, 2008

 

Variables

Variables are basically elements in a computer program that can take any assigned value. They can change from time to time, depending on the programmer and the user. For example, if a computer program requires a user to enter his or her name then the entity “name” will change from time to time depending on the user. The element “name” is considered a variable and can take on any value assigned to it. You will be using a lot of variables in your programming.

Data Types

Any kind of variable or element can take on a data type. There are several data types in Visual Basic. To name the most popular and the most useful are the following.

  1. String – this data type is made up of empty text, a single letter or several letters, or a group of words.
  2. Boolean – this data type is either True or False, or 1 or 0 representing the former and the latter, respectively.
  3. Byte – this data type can take on values from 0 to 255
  4. Integer – this data type can take on whole number values from -32,768 to 32,767
  5. Long – this data type can take on whole number values from -2,147,483,648 to 2,147,483,647
  6. Single – this data type can take on floating point numbers or numbers with decimals from -3.402823E38 to – 1.401298E(-45) and from 1.401298E(-45) to 3.402823E38
  7. Double – this data type can take on floating point numbers or numbers with decimals from – 1.79769313486231E308 to – 4.94065645841247E(–324) and from 4.94065645841247E(–324) to 1.79769313486231E308
  8. Variant – this data type can take on any kind of value. Use this data type sparingly because it takes up more than twice the memory of the other data types.

Declaring Variables

If you are ready to declare a variable in a program then you should use the following code:

 Dim X As Integer

Once a variable is declared in a program, you or the user can utilize it appropriately.

Memory Allocation for the Variables

Variables that have more complex data types take up more memory on the computer. Using too much memory can slow down a program or in some cases, may cause a computer to hang. Use your variables wisely and declare them appropriately. For example, if you have a variable that states the number of points of a basketball player in a game then it would be wise to declare “player_points” as byte instead of integer. No basketball player in history has scored more than 255 points in a single game and there is no such thing as a negative basketball point.

 

Operators

Operators are the basic way of manipulating data. The following operators are the most common operators that you will use in programming.

The “+” operator is used if you want to add elements together.

The “-” operator is used if you want to subtract one element from the other. The “-” operator is also used as a negative sign for negative values.

The “*” operator is used for multiplying elements.

The “/” operator is used if you want to divide an element with another element.

The “=” sign denotes that the values on the left side of the “=” sign are equal to the values on the right side.

A basic equation in a program may look like the code below.

 3 + x = 4<
 MsgBox (x) 

If this program is run, a message box will appear on the screen indicating the correct value of x, which is 1.

Writing and Running the Code

Interacting with the User

The intermediary between you, the programmer, and the users out there is the user form. You have learned how to put the textbox and the command button in the previous chapter. This time, you are going to use it. Make a user form with basic textboxes, labels, and a command button similar to the one below.

 

Writing the Code

Simply double click any element on your user form to begin writing code. To start off, double click “Button1” and see a code screen come up. When you type in the code for your program on this screen, make sure that you are referring to the right elements and variables all the time. You do not want to end up jumbling your data. If you are referring to data in Textbox1 then make sure that you don’t have the data of Textbox3 in mind. Once you get all things organized, your code may look like the one below.

Public Class Form1
 private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)  Handles Button1.Click

 TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)

 End Sub
End Class

 

Visual Basic is very user friendly. As you can see, simply double clicking a feature on your user form will automatically insert code. In the code above, take note that the “Val()” code is used to differentiate text from numerical value. Try removing the Val() code and see what happens to the result. You will learn little tidbits of coding as you go along this tutorial so pay attention and absorb all this knowledge.

Running the Program

Once you have the code in place, press F5 or the “play” button on the task bar. You will enter “debug” mode. Test your program and see if it works. If you want to exit debug mode, simply press the “X” button on the upper right corner of the user form or the “stop” button on the task bar.

 

Posted in - VB.Net | Leave a Comment »

05- Strings

Posted by paragdongre on June 4, 2008

 

Text Variables

String variables are an entirely different form of variables. As you may have noticed, all the other variables that were mentioned in the previous chapter have something to do with numbers. String variables deal with text. When you deal with text variables, the commands and the methods associated with them are entirely different. For example, when was the last time that you have heard someone multiply letters? What is the result when you multiply the letter “k” with the letter “n” ? When you work with text variables or string variables, make sure that you do not confuse the numerical manipulation commands with the string or textual manipulation commands.

Declaring the Text Variable or the String Variable

Simply type in the code below to declare a string variable in your program.

 

Dim Jordan as String

 

OR

 

Dim [name of variable] as String

 

Blanks

Sometimes you will encounter blanks with text variables. For example, if a user enters the name ” Jordan” instead of “Jordan,” there will be a space or a blank in front of it. If you want to rid the blanks at the start and at the end of text entered by the user then you can use the trim method. Simply use the code as illustrated below to trim any string variables.

 
        Dim Name As String
 
        Name = Trim(TextBox1.Text)
 
        MsgBox (Name)
               

As you can see, simply enter the text in the Trim() function and the spaces at the start and at the end of the text variable will be gone.

Note: Sometimes users will forget to put an entry in a textbox if you ask them to. In order to recognize blanks, simply use “”. Note that ” ” is different from “” because the former has a space bar entry while the latter has nothing in it. Visual Basic .NET recognizes the difference between the two.

String Position

With VB .NET, you can locate a string within a string. The command used to identify a string within a string is the InStr() command. See the code below and see how it works.

 
        Dim Result As Integer
 
        Result = InStr("Display", "p")
 
        MsgBox(Result)
 

The result returns a value of 4 because “p” is the fourth occurrence on the string. Try changing “p” to “isp” and see what happens. The general structure of the InStr() command is shown below.

 
Instr("[string to look at]","[string to be look for]")

 

Equal Command with Text

If you want text to be represented within a variable then you can use the equals command. See the code below and learn how the equals command is used.

 
        Dim Represent As String
 
        Represent = "This is the result."
 
        MsgBox(Represent)
               

The main structure when using the equals command is as follows.

 
[variable] = "[text]"
 

The variable will then obtain the value of the text.

Working with Text

Joining Text

Aside from using the “=” sign from numerical values, you can also use the “+” sign too. The “+” sign is used to join text together or to concatenate them. If you want to join text together, simply use the “+” sign as seen below.

 
Dim Result As String
 
Result = "Sun" + "day"
 
MsgBox(Result)
               

The result in the message box is the word “Sunday”. Try joining different kinds of texts together. The basic structure for joining text is as follows.

 [first string] + [second string] 

Replacing Text

If you want to replace a certain string or substring then you can use the Replace() command. See the code below and learn how it is used.

 
Dim Represent As String
 
Represent = "Display".Replace("Display", "Screen")
 
MsgBox(Represent)
 

The entire word “Display” is replaced with the word “Screen”. Try changing Replace(“Display”, “Screen”) with Replace(“ispl”,””) and see what happens. The general structure of the Replace command is as follows.

"[string to be looked at]".Replace("[string to be replaced]","[string to replace it]")
 

Inserting Text

If you wish to insert a string of text into an existing string then you can use the Insert() command. See the code below and learn how it is used.

 
        Dim Represent As String
 
        Represent = "Day".Insert(1, "ispl")
 
        MsgBox(Represent)
 

The result that is displayed in the message box is “Display”. Note that the first character in the String is “D” and that is why the “ispl” string was inserted after the character “D”. Try changing Insert(1, “ispl”) to Insert(2, “ispl”) and see what happens. The general structure of the Insert command is as follows.

“[string to be looked at]”.Insert([nth character where string will be inserted], “[string to be inserted]”)

Posted in - VB.Net | Leave a Comment »