Wednesday, 1 December 2010

7 most important things HTML beginners must consider

When you start learning coding and web designing in HTML, you basically begin with normal HTML markup. Laying out a page, adding colors, buttons, images etc are just the basic part you never skip to design your page.


But being a beginner you must know that no matter how basic your code is it can still have some uninvited errors. There are certain important things that you must consider to make your coding valid and capable to view in any browser window.

Let’s discuss what those 7 things are.

Make your code human readable
Because you are a HTML beginner, you are never going to use any HTML editing software like Dreamweaver, FrontPage, etc. are you? You literally start with a NOTEPAD or similar text editor and start coding but have you ever thought that you need revise your HTML markup sometime?

In the image below can you easily find the parent tag or its order?



The answer to the question is probably no if you are a beginner. Because such type of coding is just easily readable by the browser not the user. You must make it clearly readable by yourself so that you can easily find the section you are looking for in future modification.

Though the HTML tags are enclosed in “<” and “>” our brain cannot easily distinguish it from other character easily in such a huge crowd. Instead you can use CAPITAL LETTERS to rectify the HTML tag out of the web contents.


Look how the tags are distinguishable from the text contents.

Other thing you can do is make a tree order so that you can easily find the parent or child of the tag easily. This can be done by leaving some space from the right. See the example image below for more clarification.


This trick will make you easy to edit and look for the exact tag when necessary.

Using of HTML comments wisely
It is not much necessary to use HTML comments because, HTML comments are for users and browser doesn’t render it in its window. The necessity of HTML comments rises when your HTML markup goes more complex and complex. In such case using of HTML comments is necessary. As we’ve already discussed about human readability of the code in first step.


The HTML comments start with “” everything between the start and end code is not rendered in browser screen but you can easily find the it in it’s source.


Always close the tag
I understand you know this fact, but when the codes get complicated with larger contents and lots of inner divisions and blocks you’ll get confused in the middle of the path. Basically, when you view the HTML page that have unknown incomplete tags, the contents will be visible with no errors. But incase if you have added some CSS styling and tables to your web design layout you’ll probably have lots of error and fault in proper rendering in such unknown incomplete tags. Therefore ending a tag is most important thing.

Even though you are aware about it you miss to close the tag because we cannot always remember which tag was opened first and which was at last. But there is a trick (or say tips) that you can apply to have your HTML tags complete one.

Whenever you begin for a new HTML tag, close it immediately after the opening of tag.

For example, look at the sample coding below. The tag is closed instantly after it’s opening.


Then you can start filling the contents and other sub tags inside it.


Always provide alternate text for the image
This trick though won’t affect your coding, user readability or browser render-ability, it is recommended that you use alternate tags.



The above tag renders a image file named image.jpg from the specified source. But incase if you don’t have the image in specified location or mistakenly deleted the image file it will render nothing (in some browser it will show image icon or red cross icon).


Remember how important the image can be to the web page visitor. To understand your contents, S/he must know what the image was about. You must use alternet text what will show up when browser is unable to locate your image file. This will at least give the imaginative picture of the unknown image.

”Image


Proper sequence of Headers
H1 is the first and largest header of your HTML document. If you use header (H1, H2, H3) tags you must use it in sequence. For example,

must be preceeded by

or

or

but they must not be parented under smaller header see the image below.




But this one is not right because, lower header must not parent larger header. Though this won’t show any error it is not considered as good method.

Moreover parenting headers is not recommended even it is acceptable and can be rendered properly.

Use of block and inline HTML elements
You must understand the meaning of block and inline HTML elements. Usually a HTML element can be a block or inline element. The block element is like a box that can contain other contents inside it. The inline elements doesn’t have box wrapped around it and only occupies the space that its contents have. While block element occupies as much space as it is capable of until the size or width is specified.

is literally a block element while , , , , etc are inline elements.
inside is not recommended but you can use as many as you can inside
.

Java JFrame class example(1)

JFrame

Java Swing Tutorial Explaining the JFrame class. The components added to the frame are referred to as its contents; these are managed by the contentPane. To add a component to a JFrame, we must use its contentPane instead.JFrame is a Window with border, title and buttons. When JFrame is set visible, an event dispatching thread is started. JFrame objects store several objects including a Container object known as the content pane. To add a component to a JFrame, add it to the content pane.
JFrame Features
It’s a window with title, border, (optional) menu bar and user-specified components.
It can be moved, resized, iconified.
It is not a subclass of JComponent.
Delegates responsibility of managing user-specified components to a content pane, an instance of JPanel.
Centering JFrame’s
By default, a Jframe is displayed in the upper-left corner of the screen. To display a frame
at a specified location, you can use the setLocation(x, y) method in the JFrame class. This
method places the upper-left corner of a frame at location (x, y).
The Swing API keeps improving with abstractions such as the setDefaultCloseOperation method
for the JFrame
Crating a JFrame Window
Step 1: Construct an object of the JFrame class.
Step 2: Set the size of the Jframe.
Step 3: Set the title of the Jframe to appear in the title bar (title bar will be blank if no title is set).
<br /><font size=-1>
Step 4: Set the default close operation. When the user clicks the close button, the program stops running.
Step 5: Make the Jframe visible.
How to position JFrame on Screen?
frame.setLocationRelativeTo( null );

JFrame Source Code

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class JFrameDemo {

public static void main(String s[]) {
JFrame frame = new JFrame("JFrame Source Demo");
// Add a window listner for close button
frame.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
// This is an empty content area in the frame
JLabel jlbempty = new JLabel("");
jlbempty.setPreferredSize(new Dimension(175, 100));
frame.getContentPane().add(jlbempty, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
}
Output
Download jFrame Source Code

Java JFrame Hierarchy

javax.swing
Class JFrame
java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Window
java.awt.Frame
javax.swing.JFrame
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, RootPaneContainer, Serializable, WindowConstants

JFrame Constructor

JFrame()
Constructs a new frame that is initially invisible.
JFrame(GraphicsConfiguration gc)
Creates a Frame in the specified GraphicsConfiguration of a screen device and a blank title.
JFrame(String title)
Creates a new, initially invisible Frame with the specified title.
JFrame(String title, GraphicsConfiguration gc)
Creates a JFrame with the specified title and the specified GraphicsConfiguration of a screen device.