Saturday, 20 December 2014

Java: Type of applications

  1. Standalone applications
  2. Applets
  3. Web Applications
  4. Distributed Applications

1. Standalone applications: A standalone application is a program that runs on your computer. It is more or less like a C or C++ program.

2.  Applets: An applet is a application designed to travel over the internet and to be executed on the client machine by Java compatible web browser like Firefox or google chrome. Applets are also java programs but they reside on the servers. An applet can not be executed like standalone application. Applet can be executed only by embedding it into an HTML page like an image or sound file. To run an applet you need to access an HTML page which has applet embedded into it. When the web browser downloads such an HTML page, It subsequently loads the executable file, which contains Applet and then executes it on the local machine.

3. Web Applications: Web applications run on the web server. Web applications are accessed through web clients i.e. web browsers like firefox and google chrome. Whenever you access some web site by specifying the url, you are accessing some web application written in java.

Java servlets
Java server pages
HTML

Introduction to Java

Java is an object-oriented programming language developed by Sun Microsystems Inc in 1991.

Java has become the widely used programming language for the internet. Although while designing the language, the primary objective was to develop a programming language that is platform independent.

Sunday, 16 November 2014

Web SQL DB create, read, update and delete operations example

Here is the simplified example for web sql db create, read, update and delete operations:

<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
var db;
function createDatabase(dbName){
db = openDatabase(dbName, '1.0', 'Test DB', 2 * 1024 * 1024);
}

function createTable(tableName, arrFields){
db.transaction(function (tx) {
var fields = "";
for(f=0;f<arrFields.length;f++){
fields += arrFields[f] + ',';
}

fields = fields.substring(0, fields.length-1);

tx.executeSql('CREATE TABLE IF NOT EXISTS '+ tableName + ' (' + fields + ')');
});
}

function insertRecord(query){
db.transaction(function (tx) {
tx.executeSql(query);
});
}

function selectRecord(query, callBack){
var empArr = new Array();
db.transaction(function (tx) {
tx.executeSql(query, [], function (tx, results) {
var len = results.rows.length;

// Create the object of emp
for(i=0;i<len;i++){
var emp = {
id:results.rows.item(i).id,
name:results.rows.item(i).name,
salary:results.rows.item(i).salary
};

// Add objects to array
empArr[i] = emp;
}
callBack(empArr); // This is the callback
});
});
}

createDatabase('db_emp');
createTable('emp', ["id", "name", "salary"]);
insertRecord('INSERT INTO emp (id, name, salary) VALUES (1, "Rahul", 5000)');

// We are using callback in this method
selectRecord('select * from emp', function (results){
console.log(results);
});
</script>
</head>
<body>
</body>
</html>

Friday, 14 November 2014

Order by filter in js controller

Below code will sort the list listLeaves in the descending order of date field .

$scope.listLeaves = $filter('orderBy')($scope.listLeaves, "-date")

Friday, 10 October 2014

Simple Coding Rules

1. Code should be proper indented.
2. Meaning full name of variables and constants.
3. Meaning full name of methods and classes.
4. No duplicate code.
5. No inline css.
6. No inline java script.
7. Html, css and java script code also be indented.
8. No html code should come with java services.
9. If you find a code two times in a class than make a separate method using that code.
10. If you find same code in two or more classes than make a separate class using that code and use       that class.