Gadgets

Monday, 2 February 2015

Java Language Fundamentals

1. Language Fundamentals:-

·        Identifiers
·        Reserved words
·        Datatypes
·        Literals
·        Arrays
·        Types of variables
·        Var-arg methods
·        Main method
·        Command line argument
·        Java coding standards


Identifiers:

           A name in java program is called identifier, which can use for identification purpose. It can be class name, method name, variable name or label name.
Example:-
class Student
{
public static void main(String arg[])
{
int a=10;
}
}
In the above program we have 5 identifiers (Student, main, String, arg, a)

Rules for java identifiers:-

·         The only allowed characters in java identifiers are 
A to Z, a to z, 0 to 9, $, _
By mistake if we use other character, we will get an error at compile time

·         Identifier should not start with digit(0-9)
Example:-  int name123=10;     //Correct
                   int 123name=10;    //wrong

·         Java identifiers are case sensitive
Example:-
class Student
{
int number=10;       //Correct
int Number=10;      //Correct
int NUMBER=10;     //Correct
int total=number+Number+NUMBER;    // Correct
}
In the above program that three variables are different
·         There is no length limit for identifiers but it is not good programming
                     int a=10;      //Correct
                     int aaaaaaaabbbbbbbbcccccccccc=10;     //Correct but not good programming

·         we can’t use a java reserved word as an identifier. If we use java reserved keyword as an identifier, we will get an error at compile time.
                    int a=10;        //Correct
                    int while=10;     //wrong(while is reserved keyword)
“while” is java reserved keyword.

·         All predefine java classes or interfaces can be used as identifiers.
Example:-
class Text
{
public static void main(String arg[])
{
int String=10;
int Runnable=20;
System.out.println(String+” “+Runnable);
}
}
Output:- 10 20
In the above example program String is class and Runnable is interface but we used as identifiers.

Examples of valid and invalid identifiers

student_name      Correct
Name#        wrong
student@name
number123name     Correct
name$         Correct
_$name     Correct
int      wrong(int is a data type)
Int     Correct
Integer     Correct

Reserved Words:-

In java some words are reserved to represent some meaning or functionalities, such type of words are called reserved words.





Keywords for data types (8):-
byte, short, int, long, float, double, boolean, char
Keywords for flow control (11):-
if, else, switch, case, default, for, while, do, break, continue, return
Keywords for modifiers (11):-
public, private, protected, final, abstract, synchronized, native, static, strictfp (jdk1.2 keyword), transient, volatile
Keywords for exception handling (6):-
try, catch, finally, throw, thrown, assert(jdk1.4 keyword)
Class related keywords (6):-
class, interface, package, import, extends, implements
Object related keywords (4):-
new, super, this, instanceof
void return type keyword:-
In java return type is mandatory, method should be declare with void return type
Note:- In “C” language return type is optional and default return type is “int”.
Unused Keywords:-
goto, const.
Usage of goto keyword creates several problems in old languages and hence sun engineers ban this keyword in java.
We use “final”  keyword instead of “const”.
Note:- goto and const are unused keywords in java and we are not allowed to use these keywords in our program. If we are trying to use then we will get compile time error.
Reserved Literals:-
True,false --- these keywords values for Boolean type.
 Null --- this keyword default value for any object reference.
enum keyword (jdk1.5 keyword):-
If we want to define a group of named constants then we should go for enum.

Note***:-
·         All 53 reserved keywords in java contain only lower case of alphabets.
·         Newly added keywords are strictfp(jdk1.2 version), assert(jdk1.4 version), enum(jdk1.5 version).
·         In java we have “new” keyword for create object but we don’t have “delete” keyword for delete useless object because distraction of useless object is the responsibility of garbage collector.

Common mistakes:-

Correct                                          wrong
const                                          constant
instanceof                                  instanceOf
strictfp                                       strictFp
synchronized                            synchronize 
 extends                                     extend
 implements                               implement
import                                       imports








Monday, 29 December 2014

Conform Password with client side validation



Conform Password with client side validation

In this article I explained that, HTML Conform password with client side validation. Here in this form I taken password and conform password, here I taken password pattern, that password should be  a-z,A-Z,0-9 and password length is between 8 to 30 letters.




<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<form action=""method="post">
<table align="center">
<tr><td>Password :</td><td><input type="password" name="psw"  pattern="[a-zA-Z0-9 ]{8,30}"tabindex="1"class="input-box"onchange="this.setCustomValidity(this.validity.patternMismatch ? 'Password contain at least 8 charecters':'');if(this.checkValidity())form.cpsw.pattern=this.value"required/></td></tr>
<tr><td>Conform Password :</td><td><input type="password" pattern="[a-zA-Z0-9 ]{8,30}"name="cpsw"  tabindex="2"class="input-box"onchange="this.setCustomValidity(this.validity.patternMismatch ? 'Please enter same password as above':'');"required/></td></tr>
<tr><td></td><td><input type="submit" value="SignUp" tabindex="3"/></td></tr>
</table>
</form>
</body>
</html>


HTML Login form with validation

Password :
Conform Password :

HTML Login form with validation



HTML Login form with validation
In this article I explained that, HTML Login form with client side validation. Here in this form I taken email id and password, in this form we should give the correct email id pattern otherwise it will not take wrong email id pattern and here I taken password pattern, that password should be  a-z,A-Z,0-9 and password length is between 8 to 30 letters.



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<form action="" method="post">
<table align="center">
<tr><td>Email id :</td><td><input type="email"name="eid" pattern="^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$" tabindex="1"required /></td></tr>
<tr><td>Password :</td><td><input type="password"name="psw" tabindex="2" pattern="[a-zA-Z0-9 ]{8,30}"required/></td></tr>
<tr><td></td><td><input type="submit" value="SignIn"tabindex="3"/></td></tr>
</table>
</form>
</body>
</html>
Email id :
Password :

Get the check box values from database in php


Get the check box values from database in php

This program teaches you how to get the multiple checkbox values, dropdown select option values and radio button values from database using PHP. By using this program we can get the values into HTML Form from Database. This article is easy to understand and I hope it will help you.



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
include “database_connection.php”;
$sql= mysql_query("select * from studentinfo where studentname”narendar”");
$row = mysql_fetch_array($sql);
$sname=$row[“studentname”];
$fname=$row[“fathername”];
$gender=$row[“gender”];
$sub  = explode(“,”,$row[“subjects”]);
$country=$row[“country”];
?>
<form action=""method="post">
<h3 align="center">Edit Information</h3>
<table border="1" cellpadding="2" cellspacing="2" align="center"><tr>
<td>Student Name :</td><td><input type="text" name="sname" value="<?echo $sname;?>"></td></tr>
<tr><td>Father Name:</td><td><input type="text" name="fname" value="<?echo $fname;?>"></td></tr>
<tr><td>Gender:</td><td><input type="radio" name="gender" value="male"
<?php echo ($gender==”male”)?"checked":"" ;?>>Male &nbsp;
<input type="radio" name="gender" value="female"
<?php echo ($gender==”female”)?"checked":"" ;?>>Female</td></tr>
<tr><td>Subjects:</td><td>
<?
if(in_array("maths",$sub))
echo “<input type="checkbox" name="subjects[]" value="maths" checked>Maths <br>”;
else
echo “<input type="checkbox" name="subjects[]" value="maths">Maths <br>”;
if(in_array("science",$sub))
echo “<input type="checkbox" name="subjects[]" value="science"checked>Science <br>”;
else
echo “<input type="checkbox" name="subjects[]" value="science">Science <br>”;
if(in_array("computers",$sub))
echo “<input type="checkbox" name="subjects[]" value="computers"checked>Computers <br>”;
else
echo “<input type="checkbox" name="subjects[]" value="computers">Computers <br>”;
if(in_array("english",$sub))
echo “<input type="checkbox" name="subjects[]" value="english"checked>English “;
else
echo “<input type="checkbox" name="subjects[]" value="english">English”;
?>
</td></tr>
<tr>
<td>Country:</td>
<td>
<select name="country">
<option disabled selected><?echo $country;?></option>
<option  >----select----</option>
<option>India</option>
<option>Japan</option>
<option>USA</option>
</select>
</td>
</tr>
<tr><td></td>
<td><input type="submit" name="submit" value="Update"></td>
</tr>
</table>
</form>
</body>
</html>