switching to KDM ..! :)
Sunday, 4 November 2012
Thursday, 18 October 2012
why java is more secure
Java's security model is focused on protecting users from programs downloaded from sources across a network. Java programs run in Java Runtime Environment. Java Programs can't take any action outside those boundaries. For example, Programms are prohibited from many activities, including:
* Reading or writing to the local disk
* Making a network connection to any host, except the host from which the applet came
* Creating a new process
* Loading a new dynamic library and directly calling a native method
* Reading or writing to the local disk
* Making a network connection to any host, except the host from which the applet came
* Creating a new process
* Loading a new dynamic library and directly calling a native method
Wednesday, 17 October 2012
Delete vs Truncate in SQL
Truncate | Delete |
TRUNCATE is a DDL command | DELETE is a DML command |
TRUNCATE TABLE always locks the table and page but not each row | DELETE statement is executed using a row lock, each row in the table is locked for deletion |
Cannot use Where Condition | We can specify filters in where clause |
It Removes all the data | It deletes specified data if where condition exists. |
TRUNCATE TABLE cannot activate a trigger because the operation does not log individual row deletions. | Delete activates a trigger because the operation are logged individually. |
Faster in performance wise, because it is minimally logged in transaction log. | Slower than truncate because, it maintain logs for every record |
Drop all object’s statistics and marks like High Water Mark free extents and leave the object really empty with the first extent. zero pages are left in the table | keeps object’s statistics and all allocated space. After a DELETE statement is executed,the table can still contain empty pages. |
TRUNCATE TABLE removes the data by deallocating the data pages used to store the table data and records only the page deallocations in the transaction lo | The DELETE statement removes rows one at a time and records an entry in the transaction log for each deleted row |
If the table contains an identity column, the counter for that column is reset to the seed value that is defined for the column | DELETE retain the identity |
Restrictions on using Truncate Statement 1. Are referenced by a FOREIGN KEY constraint. 2. Participate in an indexed view. 3. Are published by using transactional replication or merge replication. | Delete works at row level, thus row level constrains apply |
Wednesday, 10 October 2012
String Handling in JAVA
String Handling is an important part of any programming language.- Strings are widely used in JAVA Programming, are a sequence of characters. String Class is defined in java.lang package so it is implicitly available for all programs
String class has following features:-
- It is Final class
- Due to Final, String class can not be inherited.
- It Extends object class.
- It implements Serializable, Comparable and CharSequence interfaces.
- It is immutable.
- It is also a datatype in java
String Example 1:Creating new String
String a=”Ashish”;
String b=new String();
String c=new String(“Ashish”);
String Example 2:Comparing String
String a=”Ashish”;
String b=”Ashish”;
String c=new String(“Ashish”);
if(a==b) System.out.println(“Same reference “);
if(a==c) System.out.println(“Same Reference of A and C “);
else System.out.println(“Not Same Reference “);
There are two ways to create a String object in Java-
1.Using the new operator. For example,
String str1 = new String("Ashish");.
2.Using a string literal. For example,
String str2="Ashish"; (string literal)
But these both "Ashish" have different reference. So if we compare str1 & str2, this is not equal. because str1 is created using new operator.
This diagram show the difference-
String Class Methods & Example
Click here
StringBuffer Class in JAVA
The java.lang.StringBuffer classes should be used when you have to make a lot of modifications to strings of characters. As,String objects are immutable , so if you choose to do a lot of manipulations with String Objects, you will end up with a lot of abandoned String objects in the String pool.
StringBuffer Example
StringBuffer sb=new StringBuffer(“Hiiii”);
sb.append(“Javacup”);
System.out.println(sb); //HiiiiJavacup
Example for Thread Priorities in Java
class MyThread1 extends Thread{
MyThread1(String s){
super(s);
start();
}
public void run(){
for(int i=0;i<3;i++){
Thread cur=Thread.currentThread();
cur.setPriority(Thread.MAX_PRIORITY);
int p=cur.getPriority();
System.out.println("Thread Name :"+Thread.currentThread().getName());
System.out.println("Thread Priority :"+cur);
}
}
}
class MyThread2 extends Thread{
MyThread2(String s){
super(s);
start();
}
public void run(){
for(int i=0;i<3;i++){
Thread cur=Thread.currentThread();
cur.setPriority(Thread.MIN_PRIORITY);
int p=cur.getPriority();
System.out.println("Thread Name :"+Thread.currentThread().getName());
System.out.println("Thread Priority :"+cur);
}
}
}
public class ThreadPriority{
public static void main(String args[]){
MyThread1 m1=new MyThread1("My Thread 1");
MyThread2 m2=new MyThread2("My Thread 2");
}
}
Tuesday, 9 October 2012
Date validation in lex
%{
#include<stdio.h>
int i=0,yr=0,valid=0;
%}
%%
([0-2][0-9]|[3][0-1])\/(([0]?(1|3|5|7|8))|(10|12))\/([1-2][0-9][0-9][-0-9]) {valid=1;}
([0-2][0-9]|30)\/((0(4|6|9))|11)\/([1-2][0-9][0-9][0-9]) {valid=1;}
([0-1][0-9]|2[0-8])\/[0]?2\/([1-2][0-9][0-9][0-9]) {valid=1;}
29\/[0]?2\/([1-2][0-9][0-9][0-9]) { while(yytext[i]!='/')i++; i++;while(yytext[i]!='/')i++;i++;while(i<yyleng)yr=(10*yr)+(yytext[i++]-'0'); if(yr%4==0||(yr%100==0&&yr%400!=0))valid=1;}
%%
main()
{
printf("Enter the Date(DD-MM-YY");
yylex();
if(valid==1) printf("It is a valid date\n");
else printf("It is not a valid date\n");
}
#include<stdio.h>
int i=0,yr=0,valid=0;
%}
%%
([0-2][0-9]|[3][0-1])\/(([0]?(1|3|5|7|8))|(10|12))\/([1-2][0-9][0-9][-0-9]) {valid=1;}
([0-2][0-9]|30)\/((0(4|6|9))|11)\/([1-2][0-9][0-9][0-9]) {valid=1;}
([0-1][0-9]|2[0-8])\/[0]?2\/([1-2][0-9][0-9][0-9]) {valid=1;}
29\/[0]?2\/([1-2][0-9][0-9][0-9]) { while(yytext[i]!='/')i++; i++;while(yytext[i]!='/')i++;i++;while(i<yyleng)yr=(10*yr)+(yytext[i++]-'0'); if(yr%4==0||(yr%100==0&&yr%400!=0))valid=1;}
%%
main()
{
printf("Enter the Date(DD-MM-YY");
yylex();
if(valid==1) printf("It is a valid date\n");
else printf("It is not a valid date\n");
}
Sunday, 7 October 2012
Subscribe to:
Posts (Atom)