2016-12-30

Litmus and epsilon harmony Testing Tutorial

In this blog we will learn

  •   How to do testing in Litmus.
  •   How to trigger mail / Prof
  •   How to do testing in epsilon


2016-12-26

How to get all red text from excel cell in vba string in a HTML format

Private Sub CommandButton1_Click()

Dim val As String
val = Cells(5, "G").Value

Dim fast As Boolean
fast = True
Dim last As Boolean
last = False
Dim values As String
values = ""
Dim lent As Integer
lent = Len(val)

Dim result As String
result = ""

For i = 1 To lent
   If Cells(5, "G").Characters(Start:=i, Length:=1).Font.Color = vbRed Then
      If fast Then
        values = "<span style='color:#dd0062;'>" & "" & Mid(val, i, 1)
        fast = False
        last = True
      Else
       last = True
       values = values & "" & Mid(val, i, 1)
      End If

2016-12-02

System.out.println short cut keys on different IDEs

Different IDEs short cut key for System.out.println() in Netbeans, Eclipse, JDeveloper and intellij

Short cut on Eclipse
Type syso and press Ctrl+space

Short cut on Netbeans
Type sout and press Tab key

Short cut on intellij
Type sout and  press Tab key

Short cut on JDeveloper
Type sop and press Ctrl+Enter


2016-11-10

Software development

Object oriented analysis (OOA)




Object oriented design (OOD)

1. Start with the simple object which can be abstracted into individual classes.
2. Identify all the classes in the requirement specification.
3. Identify the commonalities between all or small groups of classes. Do not force fit generalization where it doesn’t make sense.
4. Keep all the data members private or protected
5. Identify all the member variables and methods the class should have
6. Ensure that the class is fully independent of other classes and contains all the necessary attributes and methods.
7. The methods in the class should be abstract.
8. Don't use the procedural code into a class for the methods in the class.
9. Inherit and extend classes from the base classes when require.
10. Define the "Has-A" or "Uses-A" relationships among the classes



Object oriented programming (OOP)



Software development life cycles



Entity relationship model (ER model / ER diagrams)



2016-11-01

how to install apps in windows phone through pc

how to install apps in windows phone without internet
how to install xap file in windows phone
How to download apps without using the store

Solution:


Windows phone application extension type is .XAP files.

Download the application in your computer or create your won application with .xap file

Send it to phone or SD card via USB

Open your app store in your windows phone

Go to option in app store
Highlighted option 

2016-09-15

failed to lazily initialize a collection of role:  ---------  could not initialize proxy - no Session (through reference chain: java.util.ArrayList[0]-






2016-08-18

Java program to handle http request

Handle http request from web browser.  Creating own server like tomcat, No need to deploy the code .Program will run with out any server.
Getting url parameter and sending response.




  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.io.OutputStream;
  5. import java.net.InetSocketAddress;

  6. import com.sun.net.httpserver.HttpExchange;
  7. import com.sun.net.httpserver.HttpHandler;
  8. import com.sun.net.httpserver.HttpServer;

  9. public class Test {

  10.     public static void main(String[] args) throws Exception {
  11.         HttpServer server = HttpServer.create(new InetSocketAddress(8002), 0);
  12.         server.createContext("/test", new MyHandler());
  13.         server.setExecutor(null); // creates a default executor
  14.         server.start();
  15.         
  16.     }

2016-08-08

Java Thread

Understanding Threads

A thread is a single sequence of executable code within a larger program. All the programs shown so far in this book have used just one thread — the main thread that starts automatically when you run the program. However, Java lets you create programs that start additional threads to perform specific tasks.

Understanding the Thread class

The Thread class lets you create an object that can be run as a thread in a multi-threaded Java application. The Thread class has quite a few constructors and methods, but for most applications you only need to use the ones listed in Table.

 Constructors and Methods of the Thread Class
Constructor                        Explanation
Thread()                          The basic Thread constructor without
                                                 parameters. This constructor simply creates
                                                 an instance of the Thread class.

Thread(String name)         Creates a Thread object and assigns
                                                the specified name to the thread.

Thread(Runnable target) A more advanced constructor that lets
                                                 you turn any object that implements an
                                                API interface called Runnable into a
                                                thread. You see how this constructor is
                                                used later in this chapter.

Thread(Runnable target, Creates a thread from any object that
                  String name)   implements Runnable and assigns the
                                                specified name to the thread.

static int activeCount()         Returns the number of active threads.

static int enumerate         Fills the specified array with a copy of
(Thread[] t)                         each active thread. The return value is
                                                the number of threads added to the array.

String getName()                Returns the name of the thread.

int getPriority()        Returns the thread’s priority.

void interrupt()        Interrupts this thread.

boolean isInterrupted()       Checks to see if the thread has been
                                                interrupted.

2016-08-06

Write a Programs to Generate Maximum non-empty subarray of an array

Given Array A of size N  find those non-empty subarrays  (sequence of consecutive elements)

Sample:
Array    [ 1 ,1 ,3 ]

Output:
1
1
3
1  1
1  3
1  1  3

Solution:

  1. class TestClass {
  2.     public static void main(String args[] ) throws Exception {
  3.      int arr[] = {1 ,1 3};
  4.      subArray();
  5.     }
  6.     public static void subArray(int arr[], int n)

2016-08-02

Java program to parse xml file

Similar question:

  • How to read XML file in Java
  • java dom parser
  • java sax parser
  • listing all the files in a directory in java
Solution:

Config.xml
 <note>

  <id>1</id>
  <description>Files</description>
  <path>C://x</path>
  
    <id>2</id>
  <description>Files</description>
  <path>C://y</path>
</note>

2016-07-26

Java restful web services with Spring, jersey, JpaRepository, maven, angularjs and oracle

Create Web Project from Maven:

  Open CMD > Type the commend

mvn archetype:generate -DgroupId={project-packaging} -DartifactId={project-name} - DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false 

example :
 mvn archetype:generate -DgroupId=com.Webapp -DartifactId=WebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

2016-07-22

Hashmap capacity, load factor and fail-fast

Capacity :

  •     Capacity is the Number of element HashMap can contain. 
  •     initial capacity is the capacity at the time the hash table is created 
  •     default initial capacity (16) 
  •     capacity increased (2 power n) , where n- number of elements
load factor :

  • Defines threshold of HashMap. When re-sizing will occur of HashMap.
  • The load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased.
  • default load factor (.75)
fail-fast :


What is the difference between hashmap, hashtable and hashset

Hashmap:

  • Hash table implements Map interface
  • Hash table permits null values and the null key
  • HashMap class is equivalent to Hashtable, except that it is unsynchronized and permits nulls
  • It does not guarantee that the order will remain constant over time
  • constant-time performance for the operations (get, put and remove)
  •  Time complexity - O(1) for get, put and remove
                (Learn About capacity , load factor and fail-fast)
  • It is not synchronized
  • How to make Hashmap Synchronize
                 Map m = Collections.synchronizedMap(new HashMap(...));
  • Exapmle:
                   import java.util.*;
                   public class HashMapEx{

2016-07-19

Understanding final in java

Java has a final keyword that we can use it in three places.
Final variable
When you use final with a variable, it creates a constant whose value can’t be changed once it has been initialized. Similarly final can be used to  create final methods and final classes.
For Example:
final int i=10;
final File f=new File();
final ClassName;

Final methods
A final method is a method that can’t be overridden by a subclass. To  create a final method, you simply add the keyword final to the method declaration.
For example:
public class SpaceShip
{
public final int getVelocity()
{
return this.velocity;
}
}

Merge Sort Java Program


  1. import java.util.Scanner;
  2.  

  3. public class MergeSort 
  4. {
  5.     
  6.     public static void sort(int[] a, int low, int high) 
  7.     {
  8.         int N = high - low;         
  9.         if (N <= 1) 
  10.             return; 
  11.         int mid = low + N/2; 
  12.         // recursively sort 
  13.         sort(a, low, mid); 
  14.         sort(a, mid, high); 
  15.         // merging two sorted sub-arrays
  16.         int[] temp = new int[N];
  17.         int i = low, j = mid;
  18.         for (int k = 0; k < N; k++) 
  19.         {
  20.             if (i == mid)  
  21.                 temp[k] = a[j++];
  22.             else if (j == high) 
  23.                 temp[k] = a[i++];
  24.             else if (a[j]<a[i]) 
  25.                 temp[k] = a[j++];
  26.             else 
  27.                 temp[k] = a[i++];
  28.         }    
  29.         for (int k = 0; k < N; k++) 
  30.             a[low + k] = temp[k];         
  31.     }

2016-07-18

write a program to find sum of integers from a string


  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;


  3. public class GetSum {

  4. public static void main(String[] args) {
  5. String s = "1ima7 j1 1hh1  0ttr1dfg10";
  6. Pattern p = Pattern.compile("[0-9]");
  7. Matcher m = p.matcher(s);
  8. int sum = 0;

  9. while (m.find()) {
  10. sum += Integer.parseInt(m.group());
  11. }
  12. System.out.println(sum);
  13. }

Inheritance in java

Inheritance is a mechanism in which one object acquires all the properties and behaviors of parent object.
Benefits of inheritance

  • reuse of methods 
  • reuse of fields of parent class 
  • We can add new methods and fields
Syntax

  1. public class className extends ParentclassName  
  2. {  
  3.    //methods and fields  
  4. }  

Polymorphism in Java

Polymorphism (from the Greek meaning "having multiple forms")
Polymorphism means one thing in many form. an object to have more than one form. Polymorphism is capability of one object to behave in multiple ways.

There are following types of polymorphism :

Static polymorphism (compile time) function overloading :-
     Method Overloading is a feature that allows more than two methods having same name in a class with different parameters.

Example:

  1. public class Calculator{  
  2.   void add(int a,int b)
  3.   {
  4.   System.out.println(a+b);
  5.   }  
  6.   void add(int a,int b,int c)
  7.   {
  8.   System.out.println(a+b+c);
  9.   }  
  10.   

How to convert .class file to .java file

Step 1: Download Jad Link here JAD (UnZip it)

Step 2: Set environment variable.
           

Data abstraction

Abstraction is the process is used to hide certain details and only show the essential features of the object.
It is class level design that hiding the complexity of the implementation and offered by an API / design / system, in a sense simplifying the 'interface' to access the underlying implementation.


Example:


  1. public class Employee
  2. {
  3.    private String name;
  4.    private String address;
  5.    private int sal;
  6.    public Employee(String name, String address, int sal)
  7.    {
  8.       this.name = name;
  9.       this.address = address;
  10.       this.sal = sal;
  11.    }

Java Custom Exceptions

Creating Custom Exceptions
Here we are going to learn how to create your own exception.

The Throwable hierarchy
As you know, you use the try/catch statement to catch exceptions, and
the throw statement to throw exceptions. Each type of exception that can
be caught or thrown is represented by a different exception class. What you
might not have realized is that those exception classes use a fairly complex
inheritance chain, as shown in Figure :

Java Encapsulation

Encapsulation
       Encapsulation is a mechanism of binding the data and function into a single unit. Encapsulation essentially has both information hiding and implementation hiding. Encapsulation provides a way for abstraction.

Example:

class Encapsulation
{
    //Restrict direct access, hiding Data
    private int a;
    private int b;
    
    public void setA(int a){
     this.a=a;
   }
     public void setB(int b){
       this.b=b;
   }
    //hiding implementation
    public int sum(){
        int total=a+b;
        //  Other Implementation
        return total;
    }
}

Java Class concept

Class
       A class is a blueprint or prototype from which objects are created. Class that contains data type, Object, function methods, properties, Classes and constructor.
Example:
              For example our college, Our college contain different different classes and classes contain student.
Programming Language Example:

class MyClass{
    String name= "";
    String address= "";
    int age= 0;

    void setName(String name) {
         this.name = name;
    }

    void setAddress(String address) {
         this.address = address;
    }

    void setAge(int age) {
         this.age = age;
    }

    void print() {
         System.out.println(name +" "+Address+" "+age);
    }
}


Java Object Concept

 Object
       Object is representative of the class and is responsible for memory allocation of its data members and member functions.An object is a real world entity having attributes (State / data type) and behaviors (functions). An object can be considered a "thing" that can perform a set of related activities. The set of activities that the object performs defines the object behavior.
Example:
              In our class room, All students are an individual Object. They have different
              name and color.
Programming Language Example:  All are the Different different object
int a=10;
float b1=20.10f;
String s1="Name";
MyClass x;

2016-07-11

JavaScript Data Types

 JavaScript Data Types

Following are the javascript data type :
            String, Number, Boolean, Array, Object.

Example:

Number
var length = 10;            

String                                      
var Name = "Soma";    

Array                                    
var country = ["India", "China", "USA"];    

 
Object / JSON   
var name = {firstName:"Nikita", lastName:"Camon"};  

Object oriented programming concepts (OOPs)

Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects". Re-usability is the main concept of Oops. There are few major principles of object-oriented paradigm. If any programming Language supports this principles that programming language called Object-oriented programming.

Below are object oriented programming concepts :

1. Object
       Read More about Object  
 http://theprogrammersfirst.blogspot.in/2016/07/java-object-concept.html

2016-07-08

Java pagination Using webservices, Spring, JPARepository, jersey, Oracle and Angularjs Grid

Dijkstra's algorithm : graph Shortest Path implementation using java

Input Format

The first line contains T, denoting the number of test cases.
First line of each test case has two integers N, denoting the number of nodes in the graph and M, denoting the number of edges in the graph.

The next M  lines each consist of three space-separated integers x,y,r , where x and y denote the two nodes between which the undirected edge exists, r denotes the length of edge between these corresponding nodes.

The last line has an integer , S denoting the starting position.


Example:
1
4 4
1 2 24
1 4 20
3 1 3
4 3 12
1

2016-07-07

How to change jdk version in intellij

Open Iintellij


Goto >>   File > Project Structure

Binary Search Tree : Lowest Common Ancestor


  1.  /* Node is defined as :
  2.  class Node 
  3.     int data;
  4.     Node left;
  5.     Node right;
  6.     
  7.     */

  8. static Node lca(Node root,int v1,int v2)
  9.     {

  10.        //Decide if you have to call rekursively
  11.     //Samller than both
  12.     if(root.data < v1 && root.data < v2){
  13.         return lca(root.right,v1,v2);
  14.     }
  15.     //Bigger than both
  16.     if(root.data > v1 && root.data > v2){
  17.         return lca(root.left,v1,v2);
  18.     }

Swapping Nodes algorithm Implementation using java (binary tree)

Swapping subtrees of a node means that if initially node has left subtree L and right subtree R, then after swapping left subtree will be R and right subtree L.



  1. import java.io.*;
  2. import java.util.*;

  3. public class Solution {

2016-06-28

Java program to check given number is prime number or not

Similar Questions:

  • Prime Numbers Java Example
  • Print prime numbers between 1 and given number using for loop

  • //check to see if the number is prime
  • boolean isPrime = true;
  •                         for(int j=2; j < 10 ; j++){
  •                                
  •                                 if(10 % j == 0){
  •                                         isPrime = false;
  •                                         break;
  •                                 }
  •                         }
  •                         // print the number
  •                         if(isPrime)
  •                                 System.out.print(i + " ");


Binary search tree implementation using java


2016-06-24

Queue(FIFO) implementation using Java



A queue is a collection that is based on the first-in-first-out (FIFO) policy.

  • dequeue() - get an item from the queue.
  • enqueue() - insert item into the queue.

Stack(LIFO) implementation in java (linkedlist)


A stack is a collection that is based on the last-in-first-out (LIFO) policy.
  • push() -  push an item into stack.
  • pop() - get an item and remove it from the top.

2016-06-22

Java program to reverse number

Java programming source code


  1. class ReverseNumber
  2. {
  3.    public static void main(String args[])
  4.    {
  5.       System.out.println("Enter the number to reverse");
  6.       int n=54321,
  7.       int reverse = 0;

  8.       while( n != 0 )
  9.       {
  10.           reverse = reverse * 10;
  11.           reverse = reverse + n%10;
  12.           n = n/10;
  13.       }

  14.       System.out.println("Reverse number is "+reverse);
  15.    }
  16. }

2016-06-21

2016-06-15

Linked list java implementation

Definition: A linked list is a recursive data structure that is either empty (null) or a reference to a node having a generic item and a reference to a linked list.

Structure:

Node record:
class Node<Item>
{
Item item;
Node next;
}

Arithmetic expression evaluation in java


Computing the value of arithmetic expressions like this one:
                                               ( 1 + ( ( 2 + 3 ) * ( 4 * 5 )

Which means multiply 4 by 5, add 3 to 2, multiply the result, and then add 1, you get the value 101.
But how does the Java system do this calculation?

We can address the essential ideas by writing a Java program that can take a string as input (the expression) and produce the number represented by the expression as output.

Dijkstra's Two stack Algorithm for Expression Evaluation


public class ExpressionEvaluation
{
public static void main(String args[]){

Stack<String> ops = new Stack<String>();

Stack<Double> ops = new Stack<Double>();

Insert a node at the head of a linked list using Java

/*
  Insert Node at the beginning of a linked list
  head pointer input could be NULL as well for empty list
*/
/*
  Node is defined as
  class Node {
     int data;
     Node next;
  }
*/

Node Insert(Node head,int x) {
    Node node=new Node();
    node.data=x;
    node.next=head;
    return node;
}

2016-06-13

Java program to check if a number is armstrong or Not

Similar Question:

     Print List of Armstrong number.


Solution:


class armstrong
{
public static void main(String args[])
{
int s=0,n=153,m,d;
m=n;
while(n>0)

notepad application in java

Similar Question:

  • Notepad application using java source code
  • TextEditor java program

Complete Program:

import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.applet.*;
import java.io.*;
import javax.swing.*;
import javax.swing.undo.*;
import java.util.Hashtable;
class UndoableTextArea extends TextArea implements StateEditable
 {

Java command line arguments importing from a file

Similar Question:


  •        Exporting java output to a different file
  •       How to write console output to a file


Solution:

Syntex: 
 

2016-06-10

How to highlight a grid row or column in AngularJs

   

columnDefs: [
      { field: 'name',cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) {
           if (grid.getCellValue(row,col) === 'xyz') {
            return 'blue';
          }
        }},
      { field: 'address',
        cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) {
          if (rowRenderIndex===3) {
            return 'blue';
          }
        }
      }
    ]

GIT Commands Tutorial

  • Github Commands



  1.  How to get a local Copy
                               (Branch 
                                Name)
             git clone -b master <git master url )>

            (EXP-  git clone -b master https://github.com/xxx/xxx.git)



Java program to get class path file by name

           

URL resource = myClass.class.getResource("/PmlConfig.xml");          
System.out.println((new File(resource.toURI())).getAbsolutePath()));

Arraylist vs Linked list time complexity



  • Time complexity of Arraylist and  LinkedList 

Time comparison of add(), get(), and remove();


2016-06-09

How to download a file using a Java REST service ?

Related Question:
     How to zip a folder?
     AngularJs / JavaScript to download a file using web service.


Solution:

 @GET
    @Path("/report/download/file/{filename : .+}")
    @Produces(MediaType.APPLICATION_OCTET_STREAM)
    public Response downloadFilebyPath(@PathParam("filename")  String fileName) {

when to implement finalize method in java

Lot of time JVM takes care of all  garbage collector object.

If your java program hold any system resources like (Calendar, File, Thread, Display properties many more) that time you should implement finalize method.

java restful web services @path regular expression

1
         The following example shows how regular expression could be used with the @Path annotation.
       @Path("users/{username: regular expression}")

         Example:
        @Path("users/{username: [a-zA-Z][a-zA-Z_0-9]}")

        following URL:   http://example.com/users/hello

2
                 The @PathParam annotation example

        @Path("/users/{username}")
        public class User {

        @GET
         @Produces("text/xml")
         public String getUser(@PathParam("username") String              userName) {
        System.out.println(userName);
        }
        }

2016-06-08

Inserting a Node at the Tail of a Linked List

/*
  Insert Node at the end of a linked list
  head pointer input could be NULL as well for empty list
  Node is defined as


  class Node {
     int data;
     Node next;
  }


*/


How to Iterating all the Elements of a Linked List in java

/*
  Print elements of a linked list

  class Node {
     int data;
     Node next;
  }

 */
 
void Print(Node head) {
   while(head != null){
       System.out.println(head.data);
       head = head.next; 
   }
}

Java program to Search sub array inside an array

Same Problems:
       Java 2D array Grid Search
       Search sub array inside a array
       Grid Search
       multidimensional array search

Example:
  m1 = 1 2  5  5 6 5 0
           5 2 10 5 6 5 4
           9 2 34 0 2 9 6
           1 2  5  5 6 5 6
           8 2 11 5 6 1 3
           9 2 34 0 2 9 2

search array :
                m2 :  0 2 9
                         5 6 5
                         5 6 1

Solution:

Merging two Sorted Linked List using java

Merge two linked list that are aleady sorted and return a new sorted list.

Implement this method :

  1. Node MergeLists(Node list1, Node list2){
  2. // your code here
  3. }


Solution:

2016-06-05

java.lang.Exception: Error getting all Data! - No bean named 'transactionManager' is defined  com.Parameters(Resource.java:46)
 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  java.lang.reflect.Method.invoke(Method.java:601)  org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)  org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:151)  org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:172)  org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)  org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104)  org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:384)  org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:342)  org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:101)  org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:271)  org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)  org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)  org.glassfish.jersey.internal.Errors.process(Errors.java:315)  org.glassfish.jersey.internal.Errors.process(Errors.java:297)