Tuesday, January 13, 2009

Tutorials on php:Day 2


A variable is a special container that you can define, which will then contain a value you specify. For example a number, string, object, array or boolean.

If you want to work with a value that needs to remain unchanged, you can define and use a constant variable. This isdifferent to a variable as variables offer a flexible way of storing data as you can change their values and type of data they hold.

Globals and Superglobals
In addition to global declerations aof your own, PHP has built in predefined variables called superglobals. These are always present and the value they hold can be available in all your scripts.

Predefined Constants
PHP provides some built in constants for you. For example __FILE__ returns the name of the file that PHP is using. __LINE__ returns the line number that php is running and PHP_VERSION returns what php version your script is being run on.

Data types
Different types of data will take up different amounts of memory and may then be treated different in the script that you write. PHP will automatically determine the data type for the variable the time data is assigned to it. Some examples of data types are boolean, integer, float, string, object, array, resource, null (an uninitialized value).

The Assignment operator
The equals sign (=) is an assignment operator and will put the value on the right hand site and assign it to the left hand side.

Arithmetic Operators
Arithmetic operators perform mathematic operations on the values you want them to (providing they are a number). Some examples are addition (+), subtraction (-), division (/), multiplication (*), modulus (%). You can increment numbers by putting two addition operators nxet to eachother like so: (++). PHP provides combined operators which allow you to transform the left hand operand and return a result, while also modifying the original value of the variable. To return 'x' and and 5 to 'x' on the same line you would use '$x +=5.'

The Concatanation Operator
The concatanation operator allows you to join strings together. It is represented by a single period (.). Expressions, calculations and variables can also be concataned and the data type returned will aloways be that of a string.

The Comparison Operator
Comparison operators perform comparative tests using their operands and return the boolean value true if the test is succesful and false if it false. Some examples are Equivalence (==), Non-equivalence (!=), greater than (>), less than or equal to (<=). You can use logical operators such as Or (||), and (&&) and Not (!) to extend comparisons using the if() statement.

Tuesday, January 6, 2009

Tutorials on php:Day 1

Hi guys, writing after couple of months.This time i am learning php and would like to share what i am learning right now.

What is PHP? and why PHP?

*PHP (recursive acronym for "PHP: Hypertext Preprocessor") is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

*PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies.

*PHP can be used on all major operating systems, including Linux, many Unix variants (including HP-UX, Solaris and OpenBSD), Microsoft Windows, Mac OS X, RISC OS, and probably others.

*PHP has also support for most of the web servers today. This includes Apache, Microsoft Internet Information Server, Personal Web Server, Netscape and iPlanet servers, Oreilly Website Pro server, Caudium, Xitami, OmniHTTPd, and many others.

*PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)
*PHP is free to download and use

What is a PHP File?

*PHP files can contain text, HTML tags and scripts
* PHP files are returned to the browser as plain HTML
* PHP files have a file extension of ".php", ".php3", or ".phtml"

What is MySQL?

* MySQL is a database server
* MySQL is ideal for both small and large applications
* MySQL supports standard SQL
* MySQL compiles on a number of platforms
* MySQL is free to download and use


* PHP combined with MySQL are cross-platform (you can develop in Windows and serve on a Unix platform)

Where to Start?

To get access to a web server with PHP support, you can:

* Install Apache (or IIS) on your own server, install PHP, and MySQL
* Or find a web hosting plan with PHP and MySQL support

PHP - What's it do?

It is also helpful to think of PHP in terms of what it can do for you. PHP will allow you to:

* Reduce the time to create large websites.
* Create a customized user experience for visitors based on information that you have gathered from them.
* Open up thousands of possibilities for online tools.
* Allow creation of shopping carts for e-commerce websites.

What You Should Know

Before starting this tutorial it is important that you have a basic understanding and experience in the following:

* HTML - Know the syntax and especially HTML Forms.
* Basic programming knowledge - This isn't required, but if you have any traditional programming experience it will make learning PHP a great deal easier.

Wednesday, October 15, 2008

how to change windows command prompt background color

Left click on the Windows start button. Click "Run." Type in the letters "cmd." Right click on the blue bar on the top of the prompt. Click "Properties." To customize a DOS batch file instead of the general command prompt, open the batch file.
Choose the "Options" tab. Change the cursor size by selecting the button next to "Small," "Medium" or "Large."
Hit the "ALT" key and "U" to display the command prompt in full screen mode. When in full screen mode, hit "ALT," "P" and the spacebar at the same time to bring up the command prompt's properties.
Select the "Font" tab. In the "Size" box, choose the characters' pixel width and height Under "Font," choose from available fonts.
Change screen buffer and window size on the "Layout" tab. To change the position of the window, uncheck the "Let system position window" box, and select the left and top values. The value "0" displays the window in the top left corner.
Move on to the "Colors" tab. Choose colors for screen text, background, popup text and popup background. Customize colors by changing the color values manually, or select from the color palette to choose a standard color.
Click "OK" at the bottom of the window. You will be prompted to save properties for all future command prompts. Choose this option to keep the values each time you open a command prompt. For individual batch files that open a DOS prompt, you can choose "Apply properties to current window only."

Java: Coding Guidelines

A good start would be to use the following.

  • Readability - Make your program as readable as possible ( good names, spacing, ...).
  • Simplicity - Don't add unnecessary complication and duplication. KISS.
  • Convention - Use standard conventions and good practices as much as possible
  1. Comments, indentation, spacing, braces, ...
    • Comments
      • Header comments at front of each file with purpose, author, date ...
      • "Paragraph" comments at beginning of each group of code.
      • Document "tricks" -- anything unobvious.
      • Avoid useless comments. Don't comment code that is already clear.
      • Using javadoc is essential for larger projects.
    • Indentation
      • Use either K&R or Allman indentation style. Don't use others.
      • Indent size 4 spaces
      • Blanks, not tabs
      • Use your IDE's indentation tool.
      • Continued statements should be indented two indentation levels.
    • Spaces and blank lines - Use them to make the source more readable
      • No space between method name and the left parenthesis. f(x), not f (x).
      • One space between keywords (if, while, for, switch, ...) and the left parenthesis.
      • Spaces around assignment and many other operators.
      • Space after comma. f(a, b).
      • Put blank lines between elements - methods, inner classes, ....
  2. Variable (local, instance, class) Declarations
    • One per line. Declare more than one only when there are very closely related (eg, x and y).
    • Add // comment if meaning of variable isn't completely clear or if has special range, values, etc.
    • Don't reuse variable name for more than one purpose. Variables are cheap.
    • Local variables (declared in method)
      • Declare at first use is preferred to declaring at front.
      • Give variable the least required scope (without adding extra blocks).
      • Declare within for loop header if possible.
      • Don't hesitate to create extra local variable if it improved readability.
    • Instance variables (fields)
      • Declare them private.
    • Static (class) variables
      • Use static final for named constants.
      • Static (class) variables are rare.
  3. Braces
    • Use them, even for single statements.
    • K&R or Allman style
  4. Naming conventions
    • Names must be meaningful if possible.
    • Conventional names can be used: i, j, iter.
    • Case rules should be followed. class - start upper, vars - start lower, const - all upper).
    • Instance variables (fields) may start with prefix (eg, "_", "m", ...).
    • Use plural names of mass nouns for arrays and data structures.
    • Avoid confusing name duplicates (method same as field, differing only by case, ...).
    • Don't use a $ in an identifier name.
  5. Error Handling
    • "Happy Trails" programming allowed for most student programs.
    • Recover from user input errors.
    • Crash on programming errors is acceptable. Debugging output is useful.
    • Catching exceptions
      • Don't catch an exception if you can't handle it.
      • Don't use exceptions to handle normal flow (eg, ArrayIndexOutOfBoundsException).
      • Don't use exceptions to hide program errors; fix them.
      • Don't silently ignore exceptions, except in those few cases where you can't do anything anyway.
    • Throwing exceptions
      • Don't throw Exception - make it more specific.
      • Put informative message in exception constructor.
      • If you're supplying a class for someone, throw meaningful exceptions.
  6. Visibility
    • General rule: make data private, methods public.
    • Protected - Use only when designing for inheritance.
  7. Miscellaneous
    • DRY - Don't Repeat Yourself. Repeated code should be replaced with loop/method/...
    • No magic numbers - use named constants.
    • Avoid premature optimization. Don't worry about optimization unless there's a problem.
    • KISS. Keep It Simple, Stupid. Always prefer a simple to a complicated solution.
    • Methods
      • Don't assign to parameters; it makes code more difficult to read.
      • Consider declaring parameters final to assure the reader they aren't changed.
      • Use multiple returns only if it makes the code clearer, otherwise return only at the end.
      • Methods should fit on one page/screen. If they're bigger, consider splitting them.
      • Avoid recursion unless it's a situation where it's much better (eg, traversing trees).
    • Loops
      • Use for instead of while if it groups everything in one statement.
      • For loop clauses should be coherent -- all related.
      • Use the enhanced for (foreach) when possible.
      • Don't change a for loop iteration variable in the body of the loop.
      • Use break to exit early or to terminate an "infinite" loop.
      • The continue statement is rarely used.
    • Switch
      • Switch statements should include a default clause.
      • Make default the last clause in a switch.
    • If
      • Do not write an empty true or else clause.
      • Writing positive logical expressions is more readable then negative. Change if easy.
    • Data structures
      • Use the generic forms of Java Collections data structures.
      • Use newer rather than older versions: HashMap<...> instead of HashTable, ArrayList<...> rather than Vector.
    • Methods
      • A method should be small and focused on one task.
      • Split a method into several methods if it operates on different levels of data.
      • Split a method if it becomes too large (longer than one screen is a common guideline).
      • Split a method which does different things.
      • Smaller methods are easier to understand, use, and debug.
      • It's OK to have utility methods that are only called from one place.

Running a Java Program from Command Prompt

  • Create a temporary folder C:\mywork. Using Notepad or another text editor, create a small Java file Hello.java with the following text:
     class Hello
    public static void main(String[] args)
    System.out.println("Hello, World!");

    Save your file as Hello.java in C:\mywork. To make sure your file name is Hello.java, (not Hello.java.txt), first choose "Save as file type:" All files, then type in the file name Hello.java.

  • Run Command Prompt (found under All Programs/Accessories in the Start menu). Type
    C:\> cd \javaprog
    This makes C:\mywork the current directory.
    C:\javaprog> dir
    This displays the directory contents. You should see HelloWorld.java among the files.
    C:\javaprog> set path=%path%;C:\Program Files\Java\jdk1.5.0_09\bin
    This tells the system where to find JDK programs.
    C:\javaprog> javac Hello.java
    This runs javac.exe, the compiler. You should see nothing but the next system prompt...
    C:\javaprog> dir
    javac has created the Hello.class file. You should see Hello.java and HelloWorld.class among the files.
    C:\javaprog> java Hello
    This runs the Java interpreter. You should see the program output:
    Hello, World!

    If the system cannot find javac, check the set path command. If javac runs but you get errors, check your Java text. If the program compiles but you get an exception, check the spelling and capitalization in the file name and the class name and the java Hello command. Java is case-sensitive!

  • It is possible to make the path setting permanent but you have to be very careful because your system might crash if you make a mistake.

Click "Edit" and at the end append

;C:\Program Files\Java\jdk1.5.0_09\bin

(or the path to the appropriate folder where the latest version of JDK is installed). Do not put spaces before the appended path string.

Click OK on the path edit box and OK on the Ennvironment Variables box. The new setting will go into effect next time you run Command Prompt.

Saturday, September 27, 2008

Differences Between XHTML and HTML

Differences Between XHTML and HTML
Both HTML 4 and XHTML use precisely the same elements, attributes, and values. The difference between HTML and XHTML is in their respective syntax - the main differences are discussed in this section.
• XHTML requires that all Webpages contain the html, head, and body elements, as well as the DOCTYPE declaration, where as in HTML they are not required.
• XHTML insists on having closing tags for every element, even empty ones, where as HTML often lets you omit them.
• HTML requires that all attributes be enclosed by quotation marks, where as HTML lets you omit quotation marks, but only around attribute values which consist of only letters, numbers and these characters: - (dash), . (period), _ (underscore) and : (colon).
• XHTML is case sensitive, where as HTML is not case sensitive. Furthermore XHTML requires that all enumerated attribute values be lower case.

The question is why we should use xhtml??
By using xhtml ,it has various advantages.Firstly it becomes more consistant ,well structured format, pages can be easily parsed and can be processed by software applications.It helps website much easy to maintain, edit etc.
XHTML adopts official XML standards.The best thing about xhtml is that you can view on pda ,computers ,laptops etc with well structured view without any issue.

Friday, August 29, 2008

Web Standard Checklist

Web standards checklist
The term web standards can mean different things to different people. For some, it is 'table-free sites', for others it is 'using valid code'. However, web standards are much broader than that. A site built to web standards should adhere to standards (HTML, XHTML, XML, CSS, XSLT, DOM etc) and pursue best practices (valid code, accessible code, semantically correct code, user-friendly URLs etc).
In other words, a site built to web standards should ideally be lean, clean, CSS-based, accessible, usable and search engine friendly.
• Quality of code
1. Does the site use a correct Doctype?
A doctype (short for 'document type declaration') informs the validator which version of (X)HTML you're using, and must appear at the very top of every web page. Doctypes are a key component of compliant web pages: your markup and CSS won't validate without them
2. Does the site use a Character set?
If a user agent (eg. a browser) is unable to detect the character encoding used in a Web document, the user may be presented with unreadable text. This information is particularly important for those maintaining and extending a multilingual site, but declaring the character encoding of the document is important for anyone producing XHTML/HTML or CSS.

3. Does the site use Valid (X)HTML?
Valid code will render faster than code with errors. Valid code will render better than invalid code. Browsers are becoming more standards compliant, and it is becoming increasingly necessary to write valid and standards compliant HTML.

4. Does the site use Valid CSS?
You need to make sure that there aren't any errors in either your HTML or your CSS, since mistakes in either place can result in botched document appearance.
5. Does the site use unnecessary classes or ids?

6. Is the code well structured?
Semantically correct markup uses html elements for their given purpose. Well structured HTML has semantic meaning for a wide range of user agents (browsers without style sheets, text browsers, PDAs, search engines etc.)

7. Does the site have any broken links?
Broken links can frustrate users and potentially drive customers away. Broken links can also keep search engines from properly indexing your site.

8. How does the site perform in terms of speed/page size?

9. Does the site have JavaScript errors?
Internet Explore for Windows allows you to turn on a debugger that will pop up a new window and let you know there are javascript errors on your site. This is available under 'Internet Options' on the Advanced tab. Uncheck 'Disable script debugging'.
• Degree of separation between content and presentation
1. Does the site use CSS for all presentation aspects (fonts, colour, padding, borders etc)?
2. Are all decorative images in the CSS, or do they appear in the (X)HTML?
The aim for web developers is to remove all presentation from the html code, leaving it clean and semantically correct.

• Accessibility for users
1. Are "alt" attributes used for all descriptive images?
2. Does the site use relative units rather than absolute units for text size?
3. Do any aspects of the layout break if font size is increased?
4. Does the site use visible skip menus?
5. Does the site use accessible forms?
6. Does the site use accessible tables?
For data tables, identify row and column headers... For data tables that have two or more logical levels of row or column headers, use markup to associate data cells and header cells.
7. Is there sufficient colour brightness/contrasts?
8. Is colour alone used for critical information?
9. Is there delayed responsiveness for dropdown menus (for users with reduced motor skills)?
10. Are all links descriptive (for blind users)?

• Accessibility for devices
1. Does the site work acceptably across modern and older browsers?
2. Is the content accessible with CSS switched off or not supported?
3. Is the content accessible with images switched off or not supported?
4. Does the site work in text browsers such as Lynx?
5. Does the site work well when printed?
6. Does the site work well in Hand Held devices?
7. Does the site include detailed metadata?
8. Does the site work well in a range of browser window sizes?
• Basic Usability
1. Is there a clear visual hierarchy?
2. Are heading levels easy to distinguish?
3. Is the site's navigation easy to understand?
4. Is the site's navigation consistent?
5. Does the site use consistent and appropriate language?
6. Does the site have a sitemap page and contact page? Are they easy to find?
7. For large sites, is there a search tool?
8. Is there a link to the home page on every page in the site?
9. Are links underlined?
10. Are visited links clearly defined?
• Site management
1. Does the site have a meaningful and helpful 404 error page that works from any depth in the site?
2. Does the site use friendly URLs?

3. Do your URLs work without "www"?
While this is not critical, and in some cases is not even possible, it is always good to give people the choice of both options. If a user types your domain name without the www and gets no site, this could disadvantage both the user and you.

Benefits of valid XHTML & CSS
• Increased interoperability. XHTML pages can easily be viewed on wireless devices like PDA's and cell phones.
• Cleaner, more logical markup adding better integration in older existing systems.
• Future transition to more advanced technology. Allows future XML technology to be easily integrated in to an existing site.
• Greater accessibility, broadening your potential customer base. Pages will work with screen readers for the visually impaired.
• Bandwith conservation. Pages are smaller than old HTML designs and will load much faster for slower internet connections.
• Increased readability by search engines