Sunday, August 16, 2009
Exception Handling Basic Model
Exception handling overview in Java
- The file you try to open may not exist.
- The class file you want to load may be missing or in the wrong format.
- The other end of your network connection may be disrupted for some mysterious reason.
- An operand is not in the legal range prescribed for operations or methods.
If these abnormal conditions are not prevented or at least handled properly, either the program will be aborted abruptly or the incorrect results or status will be carried on, causing more and more abnormal conditions. Imagine a program that reads from an unopened file and does computations based on those input values.
Using Javac
javac FilledBox.java
Here are a few tips that may help you get started. First, applet classes must always be declared public or they will not get compiled. Also, remember that Java is case-sensitive; Filledbox.java is not the same as FilledBox.java and will not be compiled.
If the Java code is acceptable to the compiler, the only message you will see is about a deprecated API:
Note: FilledBox.java uses a deprecated API. Recompile with "-deprecation" for details. 1 warning.
For now ignore the warning. As long as there were no error messages, the file FilledBox.class will be created. If there were error messages, you need to go back and fix your code. There are many different types of error messages that the compiler may generate when given a source file. The simplest to fix are syntax errors, such as a missing semicolon or closing brace. Other messages will highlight incorrect use of variable types, invalid expressions, or violation access restrictions.
Getting your source code to compile is only the first part of the debugging process; error-free compilation does not guarantee that your program will do what you want.
Creating an HTML file to host your applet
<HTML> <HEAD> <TITLE>Sample HTML Document With Filled Box</TITLE> </HEAD> <BODY> <H1>FilledBox Demo</H1> <P> <APPLET CODE="FilledBox.class" WIDTH=50 HEIGHT=50> <PARAM NAME=color VALUE="red"></APPLET> </BODY> </HTML> You can create this file by simply typing it into a text editor. Save the file as FilledBox.html. HTML files can be named anything you like, although it is common practice to name them after the applets they host.
Saturday, August 15, 2009
Java Applet Source Code
public void init () Initializes the applet Called only once.
public void start () Called when the browser is ready to start executing the initialized applet. Can be called multiple times if user keeps leaving and returning to the Web page. Also called when browser deiconified.
public void stop () Called when the browser wishes to stop executing the applet. Called whenever the user leaves the Web page. Also called when browser iconified.
public void destroy () Called when the browser clears the applet out of memory.
public void paint(Graphics g) Called whenever the browser needs to redraw the applet.
If the applet does not implement any of these methods, the applet will have no functionality for the specific method not implemented. In the example, init and paint are implemented. The init function obtains the desired box color from a parameter in the host document. The paint method draws the filled box in the browser window.
Thursday, August 13, 2009
The Math Library Class (in Java)
- Absolute value, ceiling, floor, min and max functions. These are suitably overloaded so that you can pass in any numeric type without having your arguments automatically cast to different types, thereby possibly losing accuracy.
- Square root, power, logarithm, and exponential functions. All of these take and return double values only (double, not float, is the default floating point accuracy used by java). You do not need to use casts when passing other numeric types, like int or float, because Java's compiler will automatically convert (compatible) argument types for you. A constant for the natural logarithm base is defined as a double precision value in the constant Math. E.
- Trigonometric functions (sin, cos, tan, asin, acos, atan). All of these functions work with angles expressed in radians instead of degrees. A full circle in radians is 2*PI radians (as opposed to 360 degrees). Pi is conveniently defined to double precision as the Math class constant Math. PI.
- A pseudo-random number generator function. One method, random (), is provided as a basis for randomness in applications. Random numbers are very important in simulations, statistical analysis, and, of course, games.
Monday, August 10, 2009
Web Browser Applet processing
1. The browser reserves space in the document for displaying the applet. The WIDTH and HEIGHT parameters of the <APPLET> tag determine the amount of space used by the applet.
2. The browser reads the parameters from the <PARAM> tags.
3. The VM starts and is asked to load and initialize the applet. The applet has access to the names and values in the <PARAM> tags.
4. The VM creates a running copy of the applet based on the class file.
5. The browser calls the applet's init method, so the applet will initialize itself.
6. The VM calls the start method of the applet when it is ready for the applet to start processing. It also calls paint to draw the applet in the browser window.
7. Whenever the applet need to be redrawn (for example, when the user scrolls the applet into view), the browser calls the applet's paint method.
8. The browser calls the stop method when the user moves onto another HTML document.
9. The broswer calls the destroy method when it clears the applet out of memory.
HTML for Java Applets
Adding Java applet to HTML
< APPLET = "Clock.class" width="200" height="60">< / A P P L E T >
When a browser encounters these tagsm it will start the VM and ask it to load Clock.class. It also tells the VM that the applet may draw in a region that is 200 x 60 pixels. The location of the <APPLET> tag in the document determines the coordinate of the top left of the applet's display area.
< html>
< head>
< title> Sample HTML Document< /title>
< /head>
< body>
< img src="Twinkle.gif" />
< h1>HTML Demo</ h1>
This document is a sample of HTML.
< p>
Share your expertise< a href=">http://groups.google.com/group/nanonagle-tech">Join Techno Talk Group< /a>
<P>
< APPLET = "Clock.class" width="200" height="60">< / A P P L E T >
</ body>
</ html>
As you can see, embedding applets into Web pages is simple. Java is able to create plug-in components that can be used by novices as well as experts. For this component strategy to work, the HTML author must be able to customize the properties and behaviour of the applet via HTML. The Java programmer decides which parameters will have meaning for the applet, and the HTML author uses <PARAM> tags to pass initial parameters to the applet. The clock applet needs no parameters, telling the time is a universal function.
How Java works
Sunday, August 9, 2009
Fundamental concepts of boolean algebra
Indexed sequential files
Saturday, August 8, 2009
Direct files
- The access to, and retrieval of a record is quick and direct. Any record can be located and retrieved directly in a fraction of a second without the need for a sequential search of the file
- Transactions need not be stored and placed in sequence prior to processing
- Accumulation of transactions into batches is not required before processing them. They may be processed as and when generated
- It can also provide up-to-the-minute information in response to inquiries from simultaneously usable online stations
- If required, it is also possible to process direct file records sequentially in a record key sequence
- A direct file organization is most suitable for interactive online applications such as airline or railway reservation systems, teller facility in banking applications, etc.
Disadvantages of direct files
- These files must be stored on a direct-access storage device. Hence, relatively expensive hardware and software resources are required
- File updation (addition and deletion of records) is more difficult as compared to sequential files
- Address generation overhead is involved for accessing each record due to hashing function
- May be less efficient in the use of storage space than sequentially organized fields
- Special security measures are necessary for online files that are accessible from several stations
Sequential Files
- Easy to organize, maintain and understand
- There is no overhead in address generation. Locating a particular record requires only the specification of the key field
- Relatively inexpensive I/O Media and devices can be used for the storage and processing of such files
- It is the most efficient and economical file organization in case if applications in which there are large number of file records to be updated at regularly scheduled intervals.
Disadvantages of sequential files
- It proves to be very inefficient and uneconomical for applications in which the activity ratio is very low
- Since an entire sequential file may need to be read just to retrieve and update few records, accumulation of transactions into batches is required before processing them
- Transactions must be stored and placed in sequence prior to processing
- Timeliness of data in the file deteriorates while batches are being accumulated
- Data redundancy is typically high since the same data may be stored in several files sequenced on different keys
Friday, August 7, 2009
File Organizations
Wednesday, August 5, 2009
Glossary “B”
Tuesday, August 4, 2009
Glossary “A”
Monday, August 3, 2009
Java String Class
JAVA Libraries
Sorting in C++
The 7 Layers of the OSI Model
Database Introduction
Sunday, August 2, 2009
Javascript Introduction
Search Techno Talk
Subscribe to Techno Talk |
Visit this group |