Tuesday, February 26, 2013

Multiple checkbox value using jquery

If you want to get multiple values of checkbox using jquery , Here is the code :


<html>
<head>
<style>
div { color:red; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<form>
<p>
<input type="checkbox" name="newsletter" value="Hourly" checked="checked">
<input type="checkbox" name="newsletter" value="Daily">
<input type="checkbox" name="newsletter" value="Weekly">
<input type="checkbox" name="newsletter" value="Monthly">
<input type="checkbox" name="newsletter" value="Yearly">
</p>
</form>
<div></div>
<script>
var checkedSiteValues = ""
var count = 0;

$("input[name ='newsletter']:checked").each(function() {
            var check = $(this).val();
            
            if (check != "true") {
                count++;
                if (count == 1) {
                    checkedSiteValues = $(this).val();
                } else {
                    checkedSiteValues = checkedSiteValues + "," + $(this).val();
                }
            }
            alert(checkedSiteValues);
        });      

</script>
</body>
</html>

Wednesday, January 30, 2013

Disable Copy Paste for publisher article


Hi Everyone,

If you want to sisable copy paste option for any of your published article,
Just use below code :

<!--Disable Copy And Paste-->
<script language='JavaScript1.2'>
function disableselect(e){
return false
}
function reEnable(){
return true
}
document.onselectstart=new Function ("return false")
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</script>

Disable Copy Paste for publisher article


Hi Everyone,

If you want to sisable copy paste option for any of your published article,
Just use below code :

<!--Disable Copy And Paste-->
<script language='JavaScript1.2'>
function disableselect(e){
return false
}
function reEnable(){
return true
}
document.onselectstart=new Function ("return false")
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</script>

Disable Copy Paste for publisher article


Hi Everyone,

If you want to sisable copy paste option for any of your published article,
Just use below code :

<!--Disable Copy And Paste-->
<script language='JavaScript1.2'>
function disableselect(e){
return false
}
function reEnable(){
return true
}
document.onselectstart=new Function ("return false")
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</script>

Thursday, January 24, 2013

Memory management tips for JAVA

1) Minimize scope of variables
2) Initialize When You Actually Need (Variable Or Object)
3) Allocate Only Required Memory
4) Do not Declare in Loops
5) Memory Leaks Possibilities Through Soft References in Collections
6) Mutating Operations on String
7) Clean up Heavy Objects
8) Simply Use finally Block
9) ‘finalize’ Method Call Has Advantages and Disadvantages
10) Design and Architecture requiring more Memory       

Encapsulation in Java

Encapsulation is very useful feature of OOP concept when we are talking about security in java.

As you aware that, if we declare any varibale or method as a private then it can't be accessible in  other class or packages.
But here java provides this features to get those values, you would be thinking how ?
Yes it can be achieved by declaring getter setter methods of those particulate private members.

Like ,

package com.jignesh.brainbench;

public class EncapTest {
    private String name;
    private String idNum;
    private int age;

public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getIdNum() {
        return idNum;
    }
    public void setIdNum(String idNum) {
        this.idNum = idNum;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }

}

Now you can access all the public getter methods to read the value of those private variables.
Here you would be clear that how it can be useful for security purpose.
you would not knowing that where exact it will be stored but you can achieve this values.

Benefits :
  • The fields of a class can be made read-only or write-only.
  • A class can have total control over what is stored in its fields.
  • The users of a class do not know how the class stores its data. A class can change the data type of a field, and users of the class do not need to change any of their code.

Abstraction in java

Abstraction is ability to make the class abstract in OOP.
As you know  abstract class we can not be instantiates so we can not instantiate object of that that class.
So her if class is not instantiated then its not much useful but to make it worth we must have to create subclass which makes this abstract class useful and where abstraction concepts comes into picture.

Lets say,

public abstract class Employee
{
      public String name = "Jignesh";
      private String salary = "1000";
}

So here we can instantiate object of this class like ,

Employee e = new Employee();

But we can create subclass like,

public class Salary extends Employee {

}

And can access particular variables and methods from abstract class.


 Abstract Method :

We can also declare abstract method which means we can put simply signature entry of that method in abstract class and can put real implementation in subclass which cause the abstraction concepts become true in programming world.

To make method abstract, you must have to declare that method as abstract in abstract class.

like,
public abstract class Employee
{
 public abstract int mySal(); 
}
 
and in subclass you can implement that method :
 
public class Salary extends Employee
{
   int salary =  1000;
  
   public double myPay()
   {
      System.out.println("Computing salary pay for " + salary);
     
   }

}