Monday, February 1, 2010

Tables in HTML

Tags

In HTML, tables are designed with help of following set of tags:
  • <table></table>
  • <tr></tr> - divides the table into rows
  • <td></> - divides each row into data cells


Example:
<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>


Border Attribute
With the help of border attribute, you can specify the thickness of the border for the table.

Headings in a table

The table can contain headings in any place as you like. The headings are enclose between the <th> & </th> tags.


link

JS: Variables and Operators

Variables

JavaScript variables are used to hold values or expressions. A variable can have a short name, like x, or a more descriptive name, like carname.

Rules for JavaScript variable names:
  • Variable names are case sensitive(y ans Y are two different variables)
  • Variable names must begin with a letter or the underscore character.


Declaring(creating) JavaScript Varibales

Creating variables in JavaScript is most often referred to as "declaring" varibles. You can declare JavaScript variables with the var statement:
var x;
var carname;
After, the declaration shown above, the variables are empty(they have no values yet). Values can be assigned to variables at the time of declaration or even at a later point of time. If undeclared variables are assigned with some values, then the variables will automatically be declared.

Redeclaring JavaScript Variables

If by chance some already used variable names are redeclared, then it will not lose its original value.

Note: JavaScript allows you to perform arithmetic operations with JavaScript variables.

JavaScript Operators


JavaScript supports regular Arithmetic and Assignment operators that we see in Java. Below, we have a set of operators given in a table:

Arithmetic Operators

OperatorDescription
+Addition
-Subtraction
*Multiplication
/Divsion
%Modulus
++Increment
--Decrement


The + Operator Used on Strings


The + operator when used with two strings performs concatenation. When a + operator is used between a string and number, the result will be a string again.

Comparison Operators

All the comparison operators used in java are applied here, with the addition of one new operator:
===   -   is exactly equal to(both 'value' and 'type')
Example:
x===5 is true
x==="5" is false
Comparison operators are commonly used with conditional statements.

Other Operators

The remaining operators include the logical and conditional operators. &&, ||, ! are the three logical operators.


link

how & where

Tags


In order to use Javascript, the script code must be enclosed between the following two tags:
<script type="text/Javascript">
</script>


HTML tags inside JavaScript


JavaScript allows HTML tags to be added within it.
<html>
<body>
<script type="text/Javascript>
document.write("<h1>"Hello World!"</h1>");
</script>

</body>
</html>


Handling Simple Browsers


Browsers that do not support JavaScript, will display JavaScript as page content. To prevent them from doing this, and as part of the JavaScript standard, the HTML comment tag should be used to "hide" the Javascript as follows:
<html>
<body>
<script type="text/javascript">
<!--
document.write("Hello World!");
//-->
</script>

</body>
</html>


Where to Put the JavaScript

  • JavaScripts in the body section will be executed WHILE the page loads.
  • JavaScripts in the head section will be executed when CALLED.


Scripts in <head>

Scripts to be executed when they are called, or when an event is triggered, go in head section. Example:
<head>
<script type="text/javascript">
function message()
{
alert("This alert box was called with the onload event"):
}
</script>

</head>

<body onload="message()">
</body>
The alert() function will generate an alert box, when the html page is loaded.


Scripts in <body>

Scripts to be executed when the page loads go in the body section.

Unlimited Scripts

You can place an unlimited number of scripts in your document, so you can have scripts in both the body and the head section.

External JavaScript

If you want to run the same JavaScript on several pages, without having to write the same script on every page, you can write a JavaScript in an external file.

Save the external JavaScript file with a .js file extension. Example:
<head>
<script type="text/javascript" src="xxx.js"></script>
</head>



link

Javascript

What is JavaScript?
  • JavaScript was designed to add interactivity to HTML pages
  • Javascript is a scripting language
  • A scripting language is a lightweight programming language
  • JavaScript is usually embedded diretly into HTML pages
  • JavaScript is an interpreted language (means that scripts execute without preliminary compilation)
  • Everyone can use JavaScript without purchasing a license

What can a JavaScript do?
  • JavaScript gives HTML designers a programming tool
  • JavaScript can put dynamic text into an HTML page
  • JavaScript can react to events
  • JavaScript can read and write HTML elements
  • JavaScript can be used to validate data
  • JavaScript can be used to detect the visitor's browser
  • Javascript can be used to create cookies



link

Saturday, January 9, 2010

Regular Expressions

Regular Expressions are a way to describe a set of strings, in general terms, based on some common characteristics. It is supported by the java.util.regex package. This package primarily consists of three classes: Pattern, Matcher and PatternSyntaxException

Metacharacters
A metacharacter is a character with a special meaning interpreted by the matcher. Metacharacter are also used in Path class as Globs. ([{\^-$|]})?*+. this are the metacharacters supported by this package.

It is very interesting to use regular expressions in java programs. All the principles of Mathematical Sets such as Negation, Ranges, unions, Intersections etc are applied.

tutorials

Platform Environment

Properties
Properties are configuration values manages as key/value pairs. In each pair, the key and value are both String values. To manage properties, create instances of java.util.Properties. Properties extends java.util.Hashtable

Quering Environment Variables
On the Java platform, an application uses System.getEnv to retrieve environment varibale values. Without an argument, getEnv returns a read-only instance of java.util.Map.

Passing Environment Variables to new process
Environment variables can be passed to a new process by passing it to a Process Builder object

System Properties
The System class maintains a Properties object that describes the configuration of the current working environment. The system properties can be read and written as well

The Security ManageA security manager object can be defined on every application to have a security policy. If any action or event not allowed by security policy is performed, then the Security Exception is thrown.

Concurrency

Java supports concurrecy with the support of java.util.concurrency package.

Process and Threads


In concurrent programming, there are two basic units of execution: processes and threads. In Java programming language, concurrent programming is mostly concerned with threads.

Threads can exists in more than one number. Every applicatoin has at least one thread -- or several, if you count "system" threads that do things like memory management and signal handling

Each thread is associated with an instance of the class Thread.
Defining and Starting a Thread
An applicaiton that crates an instance of Thread must provide the code that will run in that thread. There are two ways to do this:
  • Provide a Runnable object: The Runnable interface defines a single method, run, meant to contain the code executed in the thread. The Runnable object is passed to the Thread, as shown below:
    public class HelloRunnable implements Runnable {

       public void run() {
          System.out.println("Hello from a thread!");
       }

       public static void main(String args[]) {
          (new Thread(new HelloRunnable())).start();
       }

    }
  • Subclass Thread. The Thread class itself implements Runnable, through its run method does nothing. An application can subclass Thread, providing its own implementation of run as follows:
    public class HelloThread extends Thread {

       public void run() {
          System.out.println("Hello from a thread!");
       }

       public static void main(String args[]) {
          (new HelloThread()).start();
       }

    }
Pausing Execution with Sleep
Thread.sleep causes the current thread to suspend execution for a specified period. This is an efficient means of making processor time available to the other threads of an application or other applications that might be running on a computer system. There are two overloaded methods of sleep.

It is important to declare that the main method throws an InterruptedException. This is an exception that sleep throws when another thread interrupts the current thread while sleep is active.

Interrupts
Interrupts are supported by threads with the help of interrupt method.

Joins
The join method allows one thread to wait for the completion of another.
Synchronization
Threads communicate by sharing access to fields and the objects reference fields refer to. This form of communication is extremely efficient, but makes two kinds of errors possible: thread interference and memory consistency errors.

Thread Interference
This is about how errors are introduced when multiple threads access shared data. This situation occurs when a single object is referenced by 2 or more threads.

Memory Consistency Errors
Memory consistency errors occur when differenct threads have inconsistent views of what should be the same data. The key to avoiding memory consistency errors is understanding the happens-before relationship. This relationship is simply a guarantee that memory writes by one specific statement are visible to another specific statement.

Two statements that we know, which create a happens-before relationships are:
  • Thread.start
  • Thread.join


Synchornized Methods and Statements
Synchronized methods allow only execution of a single object at a time while all other objects are blocked. Constructors cannot be synchronized. Methods and statements are declared as synchronized by having the keyword synchronized added in the declaration.

Some other important concepts that are part of this Concurrency section are given belows:

tutorials