class Welcome { public static void main(String args[]) { B b = new B(); b.callme(); } } abstract class A { abstract void callme(); } class B extends A { void callme() { System.out.println("B's implementation of callme."); } }
Author Archives: admin
How to Switch States Jquery
How to Switch States in Jquery Between Yes or No
.CrossMe { background : url(CrossMe.gif) no-repeat; cursor : pointer; float : left; height : 44px; width : 51px; } .TickMe { background : url(TickMe.gif) no-repeat; cursor : pointer; float : left; height : 44px; width : 49px; } .NotInterested { background : url(NotInterested.gif) no-repeat; cursor : pointer; float : left; height : 44px; width : 241px; } .Interested { background : url(IamInterested.gif) no-repeat; cursor : pointer; float : left; height : 44px; width : 243px; }
Jquery to Change Class
$('document').ready(function(){ $('.CrossMe').click(function(){ $(this).toggleClass('TickMe'); var prevClass = $(this).prev().attr('class'); if(prevClass=='Interested') { $(this).prev().removeClass('Interested').addClass('NotInterested'); } else { $(this).prev().removeClass('NotInterested').addClass('Interested'); } }); });
HTML to create divs
Linux Basics
What is Shell?
Computer understand the language of 0’s and 1’s called binary language.In eaarly days of computing, instruction are provided using binary language, which is difficult for all of us, to read and write. So in Os there is special program called Shell. Shell accepts your instruction or commands in English (mostly) and if its a valid command, it is pass to kernel.
Shell is a user program or it’s environment provided for user interaction. Shell is an command language interpreter that executes commands read from the standard input device (keyboard) or from a file.
Shell is not part of system kernel, but uses the system kernel to execute programs, create files etc.
Several shell available with Linux including:Bash, CSH, KSH, TCSH
To Find the list of Shells available in your system Type the below in your terminal
cat /etc/shells
Any of the above shell reads command from user (via Keyboard or Mouse) and tells Linux Os what users want.
To find the current shell you are using now use the below command
echo $SHELL
what is Shell script?
“Shell Script is series of command written in plain text file. Shell script is just like batch file is MS-DOS but have more power than the MS-DOS batch file.”
How to create password for root User in ubuntu
mugil@metro:~$ sudo passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
How to create a folder shortcut key windows XP
For Creating new Folder in windows use the following Key Combination
alt + F + W + F
You should hold the alt key and Press F and with out releasing the alt key press W and F.
Alternate Method
You Can also do this by Right Click in Mouse followed by W and F
Left Outer Join Query
Two tables
CREATE TABLE tblEatables ( `EatId` int UNSIGNED PRIMARY AUTO_INCREMENT, `Fruits` varchar(9) NOT NULL ) Engine=InnoDB; CREATE TABLE tblConfirm_Eatables ( Eatables_Id INT UNSIGNED, Edible_Status INT, FOREIGN KEY Eatables_Id REFERENCES tblEatables (EatId) ) Engine=InnoDB;
Rows in Tables
INSERT INTO tblEatables(`EatId`, `Fruits`) VALUES(1, 'Apples'), (2, 'Oranges'), (3, 'Papaya'), (4, 'Jackfruit'), (5, 'Pineapple'), (6, 'Mango'); INSERT INTO tblConfirm_Eatables VALUES(1,0), (2,1), (3,0), (4,0);
The Result Should be
Fruits Apple Papaya Jackfruit Pineapple Mango
Query1
SELECT Fruits FROM tblEatables AS E LEFT JOIN tblConfirm_Eatables AS CE ON E.EatID = CE.Eatables_ID WHERE CE.Edible_Status = 0 OR CE.Edible_Status IS NULL
Query 2
SELECT e.EatId,e.Fruits FROM @tblEatables e LEFT JOIN @tblConfirm_Eatables ce ON e.EatId = ce.Eatbles_Id WHERE ce.Edible_Status = 0 OR ce.Edible_Status IS Null
Query 3
SELECT fruits FROM tblEatables WHERE EatID NOT IN (SELECT Eatables_Id FROM tblConfirm_Eatables WHERE Edible_Status = 1)
Unary Operator in PHP
How to use Urnary operator in PHP
$ConfirmStatus = $lngConfirmSiteVisit == 1?1:0; $ConfirmStatus = $lngConfirmSiteVisit == 1?'Confirmed':'Pending';
String Functions
How to Reverse a String
strName = 'Michael'; alert(reverse(strName)); function reverse(s) { return s.split("").reverse().join(""); }
Output
leahciM
Split function Splits the String By Taking “” as Delimiter and Puts in a array.
The Reverse function reverses the array
The join function Joins the array(Character in each cell) again
How to Check if it is Numeric
function isNumber(n) { return !isNaN(parseFloat(n)) && isFinite(n); }
Java Basics Part1
Welcome to Java
public class Sample { public static void main(String args[]) { System.out.println("Welcome Back to Java"); } }
Assigning Variables
public class Sample { public String strName; public static void main(String args[]) { Sample1 objSample1 = new Sample1(); objSample1.strName = "MugilVannan"; System.out.println(objSample1.strName); } }
A Class with default access can be seen by class in same package.If classA and classB are in different package and classA has default access classA wont be visible to class B
Class Sample1.java has a class sample3 with default access applied to it.
Sample1.java
package pkgSampler; public class Sample1 { public static void main(String[] args) { SampleA objSampleA = new SampleA(); System.out.println(objSampleB.strName); } } class SampleA { public String strName; SampleA() { this.strName = "Mugil"; } }
Some Other Class in Same Package Accessing Variable with in Class with Default Access
SampleB.java
package pkgSampler; public class SampleB { public static void main(String[] args) { SampleA objSampleA = new SampleA(); System.out.println(objSampleA.strName); } }
The Methods in Class SampleA with default access in one package will only be visible to SampleB when it is Declared as Public.Otherwise it will compilation error.
Package1 with Class SampleA
package Package1; class SampleA{}
Package2 with Class SampleB
package Package2; import Package1.SampleA; class SampleB extends SampleA{}
Classes Declared as Final cannot be inherited.Nor its methods and variable can be overridden or extended.
package Pack1; public final class SampleA { public void Sampler(){} }
Now ClassB tries to access classA
package Pack2; import Pack1; public class SamplerNew extends Sampler{}
The above code will result in error
Abstract Classes
1.Abstract classes cant be instantiated.It could be only extended.
2.Methods marked as abstract should end with semicolon at its end.
eg:
abstract class absFood { public abstract void SouthIndianThali(); public abstract void Chinese(); }
3.Even if Single method is Abstract the whole class must be Abstract.You can put non abstract method in abstract class.
4.A Class can’t be abstract and Final
Interface
1.Interface is like contract which says what a class can do without telling how the class is going to do that.
2.Interface are like abstract class but abstract class can have both abstract and non abstract methods whereas interface can have only abstract methods.
3.Other Rules for Interfaces are
a.Interface Methods Must not be Final
b.Interface Methods Must not be Static
c.Variables in Interface should be public, Static and Final.
d.Methods in Interface are Implicitly Public and Abstract
e.Interface can only extend other interface
f.Interface cannot implement another interface.
4.Public modifier is required if you want teh interface to have public rather than default access.
5.All Interfaces methods are Implicitly public and abstract
e.g
public interface bounceable { void Running(); void setRunningSpeed(int Speed); }
The Interface methods above are public and abstract as it used to be by default.The following applies the same for the below method.
void runnable(); //Public public void runnable(); //Abstract abstract void runnable(); //Public abstract public void runnable(); public abstract void runnable();
The following interface method declaration wont compile
final void runnable() //Interface shld nt be final static void runnable() //Interface define instance Methods protected void runnable() //Interface methods are public private void runnable()
Interface constants are public static final.But there is no need to declare them.
Assigning Constant in Interface
interface Run { int BAR = 42; //Public final and Static by Default void go(); } class Marathon implements Run { public void go() { BAR = 27; //Not Allowed Interface //Constant value should not be changed } }
Access Modifiers
A class can use only two(public, default) of four modifiers.The four modifiers are
1.Public
2.protected
3.default
4.static
Class Zoo
class Zoo { public string coolMethod() { return "I am Cool"; } }
Class Animal
class Animal extends coolMethod { public void coolAnimalList() { //The below code works because of inheritance System.out.println(this.coolMethod()); //The below code works because of Instance Objects coolMethod objcoolMethod = new coolMethod(); System.out.println(objcoolMethod.coolMethod()); } }
Note
Always look for Access level of Class.If the class itself is not accessible no wonder the methods would be.
Protected vs Default
Protected and default access control levels are almost identical.A default member may be accessed only if the class accessing the member belongs to the same package, whereas a protected member can be accessed(through inheritance) by a subclass even if subclass in different package.
Class declared as protected in one package can be accessed only through inheritance in another class in other package
Default Access
Default members are visible to subclasses only if those subclasses are in same package as the superclass.
Note : Access modifiers can’t be applied to local variables
Local Variable can take only one modifier – final
Final Methods
Final methods prevents methods being overridden in a subclass and is often used to enforce the API functionality of method
Abstract Methods
An abstract method is a method that’s been declared but not implemented.The method contains no functional code.When a method is marked abstract the subclasses should provide the implementation.
If you declare a abstract method in class then the class should also be abstract.
There are three ways you could tell whether the method is abstract or not.
- The method is not marked abstract
- The method declaration includes curly braces
- The method provides actual implementation code.
The First Concrete method of an abstract class must implement all abstract methods of the superclass
Concrete means Nonabstract class
eg.
public abstract class Vehicle { public abstract goUpHill(); } public abstract class car extends Vehicle { public abstract goUpHill(); public void dpThings() { ... ... } } //First Concrete class since the above two classes are abstract public class Mini extends Car { public void goUpHill() { } }
A Abstract Method can Never be marked as both abstract and Final or both abstract and Private
Abstract Modifier can never be combined with Static modifier
Abstract means the super class does not know anything about how the subclasses should behave in that method where as final means the super class knows every things about the subclasses.
Constructors
Every Class has a Constructor, although if you don’t create one explicitly, the compiler will build one for you.
1.Constructor can’t ever, ever have return type.
2.Constructors can’t be marked static, they can’t be marked final or abstract.
Primitives
Eight Types – int, float, long, char, boolean, double, short, byte
For the Integers Small to Big Would be
byte, short, int, long, and doubles, floats
Instance Variables can be any of four access levels, final and transient
Instance Variables can’t be abstract, synchronized, strictfp, native and static
Local Variables
Local Variables are variables declared within a method.Local Variables life begins and Ends within a method.
Local variables are always on the stack and not on the heap
Local Variables cannot be public, transient, volatile, abstract, or static but local variables are final.
Shadowing:Declaring a local variable with the same name as instance variable
How to Declare a Array in Java
e.g
int[] key; //Recommended
int key []; //Legal but less readable
It is not legal to add size of array in your declaration
int[5] names; //The code wont compile
Final Object Reference
An object marked as final can never be reassigned to different object.The data within the object can be modified but the reference variable cannot be changed.
There are no final objects but only final references.
1.Final Class Cannot be Subclassed
2.Final Method Cannot be Overridden
3.Final Variable Cannot be assigned a new value.
Transient Variable Skip the variable when you attempt to serialize it.
Volatile Variable Tells the JVM that a thread accessing the variable must always reconcile its private copy of the variable with the master copy in memory.
Static methods and members
Static members exists even before you ever make a new instance of a class and there will be only one copy of static member regardless of number of instances of that class.In other words all instances of the class share the same value for the given static variable.
Classes, Constructors, Interfaces, Method, inner class methods and instances variables, local variables cannot be Static.
Working With Arrays
How to Convert an Multidimensional Array to One Dimensional Array
//First Method with No Argument
$this->RestructArray($arrTempCounts) //Second Method with Column Name as Argument $this->RestructArray($arrTemp, 'UserNums'); function RestructArray($parrInput, $pArg1 = 0) { $arrTemp = $parrInput; for($i=0;$i<count($parrInput);$i++) { $arrNames[$i] = $parrInput[$i][$pArg1]; } return $arrNames; }
How to Convert an One Dimensional Array to Multidimensional Array
$k = 0; for($j=0;$j<$lngCols;$j++) { for($i=0;$i<$lngRows-1;$i++) { $arrTemp[$j][$i] = $arrIndividualCounts[$k]; $k = $k+1; } }