Friday, July 17, 2009

CSS margin with example.

To understand margin let's start a general example and see how it display in the browser. Copy the following code and see from browser,

<html>
<body>
In this blog http://arjudba.blogspot.com you will
see there is some space (though a very little amount)
all around. But there is no space whenever you
will disply this html code inside your browser.
<blockquote>

But there will be some spaces all around this
blockquote. Both left, right, top, bottom side.

</blockquote>
You are recommended to join http://arju-on-it.com/forum
and discuss your problems there
</body>
</html>


If you run above html code, you will see all around of blockquote text there is space. But don't have control how much space will be all around. In CSS, this space is called "margins" and margins are controlled by four properties, margin-left, margin-right, margin-top and margin-bottom. We can minimize space around blockquote by following css code,

blockquote {
margin-top: 1em;
margin-right: 0em;
margin-bottom: 1em;
margin-left: 0em;
}

We can shorthand margin property by setting all margin properties using,

blockquote{
margin: 1em 0em 1em 0em;
}

The first part 1em is for margin-top and then it goes clockwise, second part is margin-right, then margin-bottom and then margin-left.

Let's assign some background colour all around blockquote. We can do this simply by background. Like,

blockquote{
margin: 1em 0em 1em 0em;
background: #AAA;
}

We will see that the background color barely covers the quoted text. But the margin area is not affected. However if we want that background color will be there will some amount of space around quote text(element) then we have to use another property of CSS called padding.

With usage of padding css code will look like,

blockquote{
margin: 1em 0em 1em 0em;
background: #AAA;
padding:.5em .5em .5em .5em;
}

Similar to margin padding can be padding-top, padding-right, padding-bottom, padding-left.

So, our final code will look like,

<html>
<style type="text/css">
blockquote{
margin: 1em 0em 1em 0em;
background: #AAA;
padding:.5em .5em .5em .5em;
}
</style>
<body>
In this blog http://arjudba.blogspot.com you will
see there is some space (though a very little amount)
all around. But there is no space whenever you
will disply this html code inside your browser.
<blockquote>
But there will be some spaces all around this
blockquote. Both left, right, top, bottom side.
</blockquote>
You are recommended to join http://arju-on-it.com/forum
and discuss your problems there
</body>
</html>

Final output is in,




Wednesday, July 15, 2009

Exception in thread "main" java.lang.NoClassDefFoundError

For newbie, this problem is almost common in java. While compile java using javac it was successful. But whenever you execute the compiled file it fails with "Exception in thread "main" java.lang.NoClassDefFoundError". as below.

E:\Documents and Settings\Arju\Desktop\Rotimi New\Java>java Palindrome.class
Exception in thread "main" java.lang.NoClassDefFoundError: Palindrome/class
Caused by: java.lang.ClassNotFoundException: Palindrome.class
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: Palindrome.class. Program will exit.

The solution is add -classpath and a dot (.) which means, that it will search for classes bytecode in the current directory. Like below.
E:\Documents and Settings\Arju\Desktop\Rotimi New\Java>java -classpath . Palindrome
Enter number
345
Number:
345
After reversing the number:
543
Number is not palindrome!

Also note that, while executing if you add .class extension then similar error will throw. So while executing simply write,
E:\Documents and Settings\Arju\Desktop\Rotimi New\Java>java Palindrome
Enter number
3
Number:
3
After reversing the number:
3
Number is palindrome!

And adding .class will throw exception as below.
E:\Documents and Settings\Arju\Desktop\Rotimi New\Java>java Palindrome.class
Exception in thread "main" java.lang.NoClassDefFoundError: Palindrome/class
Caused by: java.lang.ClassNotFoundException: Palindrome.class
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: Palindrome.class. Program will exit.

Test speed to find a reliable hosting provider

There are many sites over the internet that make speed tests but most of them work on the same principle:
1) visit a web site
2) select a location with which you'll be making the speed test
3) start the test and check out the results

OR the more advanced option is to
1) visit a website
2) automaticall load in your page a Flash script
3) start the script which will then download and sometimes upload a file from/to a certain destination

While this approach is generally good enough it is completely useless when you need to check the speed between your computer and any website in the world.
"Why would I want to do that?" you may ask yourself.

Well, here's one of the reasons: you want to find a reliable hosting provider and the provider you just found advertise they have fast Internet connectivity. This may be true but what about if they host the site in US and your target audience is in Australia?

If that's the case use this http://tools.geek-tools.org/en/speedtest speed test tool, it is not yet perfect but it may help you make some real life tests on with different sites hosted by the same provider.

Related Documents

Monday, July 13, 2009

CSS Tutorial- Starting with CSS, how to use and integrate it.

CSS stands for Cascading Style Sheets. CSS is the very simple mechanism for adding style (this is fonts, colors, spacing) to Web pages. This post is about how to use css into an html documents and how these two can be work together. Step by step it is discussed of using css into html documents.

Step 1: Create a Html file.
Simply you can use notepad on windows or vi on unix to write a simple html file. You can use third party open source program like notepad++. But never use wordprocessor, such as Microsoft Word or OpenOffice. Because their outcome comes in different format and browser can't read it.

Note that in html comment starts with <!-- and ends with -->
My content of index.html is below.

<html>
<head>
<title>My first styled page</title>
</head>

<body>

<!-- Site navigation menu -->
<ul class="navigation_bar">
<li><a href="index.html">Home page</a>
<li><a href="products.html">Our Products</a>
<li><a href="contact_us.html">Contact us</a>
<li><a href="about_us.html">About us</a>
</ul>

<!-- Main content -->
<h1>This topic is one is for learning css</h1>

<p>Welcome to http://arjudba.blogspot.com

<p>It is just an example.
You can enhance it as you go on.
The style does not look so good.

<p>More learning materials
are coming soon.

<!-- Just publishing today's date with signature -->
<address>14th July, 2009.<br>
by Mohammad Abdul Momin Arju.</address>

</body>
</html>

In the example the tag <ul> introduces an "Unordered List", which means a list in which the items are not numbered. The <li> is the start of a "List Item." Note that <ul>, <p> does not need closing tags.

Step 2: Add some colours:
If you run codes of step1 you will see black text within white background. So with css we want to add some colours to background as well as to text. For css style we should make another file named style.css so that we can use that style for another html file. But in this post to make it easier, I am placing css styles in the same html file index.html. To do it we need to add a <style> element to the HTML file.

Let's see my style looks like,

<html>
<head>
<title>My first styled page</title>
<style type="text/css">
body {
color: green;
background-color: #ededed
}
</style>
</head>

<body>
etc...

Note that in case of adding css element there is followed by rules and each rule contains three part..

selector{
property:value;
}

1. The selector (in the example: "body"), which tells the browser which section of the web page will be affected by css style.

2. The property (in the example, 'color' and 'background-color' are both properties), which tells the browser what aspect of the layout is being set.

3. And the third one is value (in the example 'green' and '#ededed'), which gives the value for the style property.

Step 3: Add fonts
For good design and good look and feel you can add different fonts to different section of the page. For body Georgia font is used, if it is not available, Times New Roman or Times will be there, and if all else fails, the browser may use any other font with serifs.

For heading section Helvetica will be used. If not available Arial will be there, if both unavailable any fonts with sans-serif.

<html>
<head>
<title>My first styled page</title>
<style type="text/css">
body {
font-family: Georgia, "Times New Roman",
Times, serif;
color: purple;
background-color: #d8da3d }
h1 {
font-family: Helvetica, Arial, sans-serif }

</style>
</head>

Step 4: Add a navigation bar
We already have navigation menu at top of the page. But we want to move menu bar on left. This is done by css position property with a value of absolute. Also we need to position of body to the right so that menu and body does not overlap. We can move the body to the right by using padding-left property. So our css code now stands,

<html>
<head>
<title>My first styled page</title>
<style type="text/css">
body {
padding-left:14em;
font-family: Georgia, "Times New Roman",
Times, serif;
color: purple;
background-color: #d8da3d }
h1 {
font-family: Helvetica, Arial, sans-serif }
ul.navigation_bar{
position: absolute;
top: 2em;
left: 1em;
width: 9em }

</style>
</head>
<body>

Here measure 2em means 2 times the size of the current font. E.g., if the menu is displayed with a font of 14 points, then '2em' is 24 points. The 'em' is a very useful unit in CSS, since it can adapt automatically to the font that the reader happens to use.

Step 5: Style the links
Still now navigation menu looks like list. Using list-style-type property we will remove bullet. And we will make background as green of all menu items so that it looks like menu. To make each menu separate margin property would have a value. Also we will change the colours of the links. If user has not visited yet then make it blue and if user has visited link then we will make it purple.

Now it looks,

<html>
<head>
<title>My first styled page</title>
<style type="text/css">
body {
padding-left:14em;
font-family: Georgia, "Times New Roman",
Times, serif;
color: purple;
background-color: #d8da3d }
h1 {
font-family: Helvetica, Arial, sans-serif }
ul.navigation_bar{
list-style-type: none;
position: absolute;
top: 2em;
left: 1em;
width: 9em }
li{
background:green;
border:0;
padding:.5em;
margin:.3em;
}
a {
text-decoration: none }
a:link {
color: blue }
a:visited {
color: purple }

</style>
</head>

Step 6: Add a horizontal line
To make separate address from main page I am adding a horizontal line after body.
So just adding this line within style sheet.

address {
margin-top: 1em;
padding-top: 1em;
border-top: thin dotted }

Step 7: Put the style sheet in a separate file.
Now we are separating the syle sheet in another file so that we can use this style in many other web pages. Let's name this as style.css which looks like,

body {
padding-left:14em;
font-family: Georgia, "Times New Roman",
Times, serif;
color: purple;
background-color: #d8da3d }
h1 {
font-family: Helvetica, Arial, sans-serif }
ul.navigation_bar{
list-style-type: none;
position: absolute;
top: 2em;
left: 1em;
width: 9em }
li{
background:green;
border:0;
padding:.5em;
margin:.3em;
}
a {
text-decoration: none }
a:link {
color: blue }
a:visited {
color: purple }
address {
margin-top: 1em;
padding-top: 1em;
border-top: thin dotted }

Now from html file index.html reference it as,
<link rel="stylesheet" href="mystyle.css">
Our index.html looks like,

<html>
<head>
<title>My first styled page</title>
<link rel="stylesheet" href="style.css">

</style>
</head>


<body>

<!-- Site navigation menu -->
<ul class="navigation_bar">
<li><a href="index.html">Home page</a>
<li><a href="products.html">Our Products</a>
<li><a href="contact_us.html">Contact us</a>
<li><a href="about_us.html">About us</a>
</ul>

<!-- Main content -->
<h1>This topic is one is for learning css</h1>

<p>Welcome to http://arjudba.blogspot.com

<p>It is just an example.
You can enhance it as you go on.
The style does not look so good.

<p>More learning materials
are coming soon.

<!-- Just publishing today's date with signature -->
<address>14th July, 2009.<br>
by Mohammad Abdul Momin Arju.</address>

</body>
</html>

The output will be,







Sunday, July 12, 2009

SQL Decode

Syntax of SQL function Decode
The syntax of sql decode function is,

DECODE (expression,search,result[,default])
where search, result can be repeated many times as needed.
And default is optional.

How Decode Works
DECODE compares expression to each search value one by one. If expression is equal to a search, then corresponding result is returned. If expression does not match with search then Oracle returns default. As default is optional so it can be omitted and if omitted, then Oracle returns null.

Always remember that in a DECODE function, Oracle considers two nulls to be equivalent. So, if expression is null, then Oracle returns the result of the first search that is also null.

The maximum number of components in the DECODE function, including expression, searches, results, and default, is 255.

Data Conversion
- Oracle automatically converts expression and each search value to the datatype of the first search value before comparing. So the datatype of the first search value is a key role in decode.

- Oracle automatically converts the return value to the same datatype as the first result. So the first result plays a key role here.

- If the first result has the datatype CHAR or if the first result is null, then Oracle converts the return value to the datatype VARCHAR2. Again for the result it depends on the first datatype.

An example that demonstrate DECODE:
With an example below I will demonstrate DECODE, about how it works.
1)Create a table named country_list and insert data into it.

SQL> create table country_list(country_name varchar2(100));

Table created.

SQL> insert into country_list values('UK');

1 row created.

SQL> insert into country_list values('USA');

1 row created.

SQL> insert into country_list values('BAN');

1 row created.

SQL> insert into country_list values('PAK');

1 row created.

SQL> insert into country_list values('IND');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from country_list;

COUNTRY_NAME
----------------------------------
UK
USA
BAN
PAK
IND

2)Now use DECODE function.
If the column value is UK then it will show United Kingdom.
If value is USA then it will show United States of America.
If value is BAN then it will show Bangladesh.
If value is PAK then it will show Pakistan.
If neither one matches then it will show default value OTHERS.

SQL> col country_name for a10
SQL> select country_name,
2 decode(country_name,'UK','United Kingdom',
3 'USA','United States of America',
4 'BAN','Bangladesh',
5 'PAK','PAKISTAN',
6 'OTHERS') from country_list;

COUNTRY_NA DECODE(COUNTRY_NAME,'UK'
---------- ------------------------
UK United Kingdom
USA United States of America
BAN Bangladesh
PAK PAKISTAN
IND OTHERS


You can also implement greater than or less than inside sql decode function. In case of number you can achieve that using SIGN function and in case of character you can achieve that using GREATEST function. Below is an example of using greatest function which will display whether name started less than M character or not.

SQL> select country_name, decode(
2 greatest(substr(country_name,1,1),'M'),'M'
3 ,'Name is between A to M','Name is between N to Z') from country_list;

COUNTRY_NA DECODE(GREATEST(SUBSTR
---------- ----------------------
UK Name is between N to Z
USA Name is between N to Z
BAN Name is between A to M
PAK Name is between N to Z
IND Name is between A to M

Related Documents