Great Deals

Filter in AngularJs

12:51 Unknown 0 Comments


<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script>

var app=angular.module('myApp',[]);
app.controller('ct',function($scope){
$scope.arr=["Shiv","Jagan"];
});
</script>
</head>
<body>
<div ng-app="myApp" id="u" ng-controller="ct">
Name<input type="text" ng-model="userName"/>
<ul>
<li ng-repeat="x in arr|filter:userName">
User Name:{{x}}
</ul>

</div>

0 comments:

Exception Handling puzzle

14:43 Unknown 0 Comments


Hi please pay close attention to this small code snippette.
As our rule says exception handling mechanism
The finally block always gets executed even if we are using the return statements.

The code will return the OP as 30

public class TryCatchDemo {
static int giveInt()
{
     try
     {
           return 10;
     }
     catch(Exception e)
     {
           return 20;
     }
     finally
     {
           return 30;
     }
    
     }
     public static void main(String[] args) {
     System.out.println(""+giveInt());

     }

}


0 comments:

StringBuilder Demo

14:35 Unknown 0 Comments




public class StringBuilderDemo {

     public static void main(String[] args) {
            StringBuilder sb = new StringBuilder("Shiv");
          
               System.out.println("Original String " + sb);
            
               System.out.println("substring: " + sb.substring(0,2));
          
 //  StringBuilder java.lang.StringBuilder.replace(int start, int end, String str)
               sb = sb.replace(4,4,"!!!!");
               System.out.println("replace String from location 4 to 4 charecters from location 4  " + sb);
            
               System.out.println("indexOf() charecter S is   " + sb.indexOf("S"));
            
    //Syntax StringBuilder java.lang.StringBuilder.insert(int offset, String str)
               sb = sb.insert(5, "is");
               System.out.println("inserted String  " + sb);
              
              //Syntax StringBuilder java.lang.StringBuilder.append(String str)
               sb = sb.append(" lord");
               System.out.println("append: " + sb);
          
               System.out.println("lastIndexOf charecter i is  " + sb.lastIndexOf("i"));
               sb = sb.reverse();
               System.out.println("reverse: " + sb);
     }

}


0 comments:

String Demo

12:42 Unknown 0 Comments


public class StringDemo {

       public static void main(String[] args) {
       String s=new String("Shiv");
      
       char firstChar=s.charAt(0);
       System.out.println("First Charecter"+firstChar);
      
       boolean status=s.contains("i");
       if(status){
              System.out.println("i Found");
       }else{
              System.out.println("i Not Found");
       }

       status=s.endsWith("iv");
       if(status){
              System.out.println("ends with iv");
       }else{
              System.out.println(" Not ends with iv");
       }

       String newString=s.replace('v', 'V');
                     System.out.println("Replaced= "+newString);
      
       String name="Ajju";
       System.out.println("Last Occurance of J= "+name.lastIndexOf("j"));
       System.out.println("First Occurance of J= "+name.indexOf("j"));
       //**Substring starting from point 2*/
       System.out.println("SubString"+name.substring(2));
      
       name="Java is Great";
      
       String []words=name.split(" ");
      
       for(String oneWord:words)
       {
              System.out.println(""+oneWord);
       }
      
       }
      
      
}


0 comments:

Advertising