2018-05-29

RTC java client developments Environment setup

RTC java client developments Environment setup


List of jar required to setup development evn.

link for documents and jars
https://jazz.net/downloads/rational-team-concert/releases/6.0.5?p=allDownloads 

1. Download rtc jaav client
https://jazz.net/downloads/rational-team-concert/releases/6.0.5/RTC-Client-plainJavaLib-6.0.5.zip

https://jazz.net/downloads/rational-team-concert/releases/6.0.5/RTC-SDK-Client-6.0.5.zip 
(This jar required when any class in not present in RTC-Client-plainJavaLib)

2. Download Docs
https://jazz.net/downloads/rational-team-concert/releases/6.0.5/RTC-Client-plainJavaLib-API-javadoc-6.0.5.zip

 Extract the zip and keep it into a location


Step to setup Evn

1. Open eclipse
2. Create a java project
3. Right click on the project go to Build path>configure build path>Libraries>Add eternal jars.
4. Go to the folder where your have extracted the RTC-client-plainJavaLib
5. Select all and click OK.

Environment setup is Done.

You may need to add some other jar in your development time. If any class in not present in RTC-Client-plainJavaLib package then use jar from RTC-SDK-Client package


RTC java Client api developments

1. RTC java client developments Environment setup
2. RTC java client Login to Server
3. RTC java client required services and Client classes initialization
4. RTC java client Connect to project area by project area name
5. RTC java client get all team area of project area
6. RTC java client get development line of the project area
7. RTC java client current iterations of the project area
8. RTC java client get members from team area
9. RTC java client get associated  team area from category
10. RTC java client get all category from project area
11. RTC java client get list of work item filed against category
12. RTC java client get work item attribute value by attribute id
13. RTC java client user profile information
14. RTC java client user work environment
15. RTC java client user work resource allocation
16. RTC java client get user absence
17. RTC java client get work item estimate hours 

2018-05-09

How do you deal with StackOverflowError in java ?

Problem statement: what is StackOverflowError and how do you deal with this ?
  • Constructor of StackOverflowError class:
  1. StackOverflowError():creates an object of StackOverflowError class, with no details message.
  2. StackOverflowError(String s):creates an object of StackOverflowError class, with the specified detail message.
  • Hierarchies of StackOverflowError class: 
  1. StackOverflowError extends VirtualMachineError: it indicates JVM is broken
  2. VirtualMachineError extends Error: it indicates serious problem that an application should not catch.
  3. Error extends Throwable and furthermore Throwable extends Object.
  • What is StackOverflowError: Stack overflow means exactly - a stack overflows. Usually there's a one stack in the program that contains local-scope variables and addresses where to return when execution of a programs ends. That stack tends to be a fixed memory range somewhere in the memory, therefore it's limited how much it can contain values.
  • If the stack is empty you can't pop, if you do you'll get stack underflow error.
  • If the stack is full you can't push, if you do you'll get stack overflow error.
  • So stack overflow appears where you allocate too much into the stack.
  • what is the cause of StackOverflowError ?
  1. when recursive function does not have the correct termination condition, then it ends up calling itself forever and leads to StackOverflowError.
  2. If you are calling library function that indirectly cause function to be called.
  • How do you deal with StackOverflowError?
  1. Inspect the stack trace and detect the repeating pattern of line numbers. 
  2. these line numbers indicates code being recursively called.
  3. once you detect these lines, inspect your code and understand why recursion never terminates.
  4. if code is terminating the recursion correctly, then increase the thread stack's size, in order to allow large number of invocations.
  5. default thread stack size is equal to 1MB.
  6. thread stack size can be increase using -Xss flag
  7. -Xss flag can be specified either via project's configuration, or via command line.
  8. value can be set like -Xss2048k or -Xss2M don't use = operator like -Xss=2048k
  1. public class StackOverFlowErrorExe {
  2. public static void recursiveCall(int num) {

  3. System.out.println("Number: " + num);

  4. if (num == 0) {
  5. return;
  6. }else {
  7. recursiveCall(++num);
  8. }
  9. }

  10. public static void main(String[] args) {
  11. StackOverFlowErrorExe.recursiveCall(1);
  12. }
  13. }
Output: Exception in thread "main" java.lang.StackOverflowError.
  • How to configure -Xss flag in eclipse:


2018-05-08

Java VisualVM [ Heap Dump, Thread Dump, Memory Dump, CPU Dump ]?

Java VisualVM is a tool that provides a visual interface for viewing detailed information about Java applications while they are running on a Java Virtual Machine (JVM), and for troubleshooting and profiling these applications. 

Tools:



click oracle doc for more details

2018-05-07

Tree data structure Implementation


class Node {

int data;
Node left;
Node right;

Node(int data) {
this.data = data;

}
}

public class BaseTree {
public static void main(String[] args) {
Node root=new Node(1);

Node a1=new Node(2);
Node a2=new Node(3);
Node a3=new Node(4);
Node a4=new Node(5);
Node a5=new Node(6);
Node a6=new Node(7);


root.left=a1;
root.right=a2;

a1.left=a3;
a1.right=a4;

a2.left=a5;
a2.right=a6;


System.out.println(height(root)-1);
//preOrder(root);
//inOrder(root);
//postOrder(root);
//System.out.println(root.left.right.data);
//System.out.println(root.data);
//System.out.println(root.left.data);
//System.out.println(root.left.left.data);
//System.out.println(root.left.right.data);
//System.out.println(root.right.left.data);
//System.out.println(root.right.right.data);
}

public static void preOrder(Node root){
if(root==null){
return;
}
System.out.println(root.data);
preOrder(root.left);// root=root.left;root=root.left.left;
preOrder(root.right);
}
public static void inOrder(Node root){
if(root==null){
return;
}
preOrder(root.left);
System.out.println(root.data);
preOrder(root.right);
}
public static void postOrder(Node root){
if(root==null){
return;
}
preOrder(root.left);
preOrder(root.right);
System.out.println(root.data);
}


public static int height(Node root){
if(root==null){
return 0;
}
else
    {
        int lDepth = height(root.left);
        int rDepth = height(root.right);

        if (lDepth > rDepth)
            return (lDepth + 1);
         else
            return (rDepth + 1);
    }
}
}

2018-05-06

Spring Boot with REST API implementations !!

Problem statement: Implementation of Spring boot rest api web application

How to create Spring Boot Project for Rest API web service own implementation
Method-I: 
step-1: go to eclipse / sts ide menu bar
step-2: select File --> New --> Spring Starter Project
step-3: by default pom.xml will add required spring boot dependency
step-4: create your own controller class and enjoy.

Method-II:
step-1: go to eclipse / sts ide menu bar
step-2: select File --> New --> Maven Project
step-3: add the <spring-boot-starter-parent >
step-4: add <spring-boot-starter-web> dependency and enjoy

  • Required code implementations:

[1]- pom.xml:
<project xmlns="http...>

        <groupId>com.ishaan</groupId>
<artifactId>maven_projects</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
       
        <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>

        <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>

<dependencies>
<!-- This is a web application -->
<!-- Adds Tomcat and Spring MVC, along others, jackson-databind included
transitively -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Tomcat embedded container -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Package as an executable jar/war -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

[2] - SpringBootWebApplication .java:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

//Create an Application class
@SpringBootApplication(scanBasePackages={"com.ishaan.springboot"})
// same as @Configuration @EnableAutoConfiguration @ComponentScan
public class SpringBootWebApplication {

public static void main(String[] args) {
SpringApplication.run(SpringBootWebApplication.class, args);
System.out.println("Hello Spring Boot !!");
}
}

// @SpringBootApplication  add
// @Configuration -tags the class as a source of bean definitions for the application context.

// @EnableAutoConfiguration tells Spring Boot to start adding beans based on classpath settings, //other beans, and various property settings.

[3] - WebServiceRestController .java:

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

//Create a simple web application
@RestController
@RequestMapping("/api")
public class WebServiceRestController {

@RequestMapping(value = "/ping/", method = RequestMethod.GET)
public String ping() {
return "Ping success !!";
}
}

[4] - application.properties : (under src/main/resources)
# port number used for spring boot
server.port = 8090

[5] - application.yml: (under src/main/resources)                                        
        server:
            port: 8090
Note: Point [4] and point [5] are same thing, with different way of representation.

URL request to access resources: http://localhost:8090/api/ping/
Response from the TOMCAT server USING POSTMAN: Ping success !!


Why Microservices ?

Problem statement: What is microservices?

1. Microservices is a method of developing software applications as a unit of independently deployablesmallmodular services in which each service runs a unique process and communicates through a well defined, light weight mechanism to serve a business goal.

2. microservice gives developer the freedom to independently develop and deploy services.

3. microservices is a variant/type of Service Oriented Architecture (SOA) that structures an application as collection (group of individual service) of loosely coupled services.


4. Easy integration and automatic deployment (using open source continuous integration tools like Jenkins, Hudson)

5. When change is required in a certain part of the application, only the related service can be modified and redeployed — no need to modify and redeploy the entire application

6. Better fault isolation: If one microservice fails, the other will continue to work.

7. Easy to scale & integrate with third-party services.

8. Simple to understand & modify the service for developers, thus can help a new team member become productive quickly.

  • How the microservice communicates with each other ?
It uses HTTP / REST Webserives with JSON. REST(Representational State Transfer) is useful integration method
  • How Microservice Architecture Works?
  1. Object Oriented Programming (OOP)a modern programming paradigm (see also SOLID)
  2. Web service / APIa way to expose the functionality of your application to others, without a user interface
  3. Service Oriented Architecture (SOA)a way of structuring many related applications to work together, rather than trying to solve all problems in one application
  4. Systemsin the general sense, meaning any collection of parts that can work together for a wider purpose
  5. Single Responsibility Principle (SRP)the idea of code with one focus
  6. Interface Segregation Principle (ISP)the idea of code with defined boundaries.

2018-05-03

Chocolate distribution

There are N people in a row with some count number of chocolate in there hands. You have to select range of people to distribute those chocolate equally among them.

Write a program to determine Maximum number chocolate that can be placed in Box.
T - Test cases
N - Number of chocolate
M - Box

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class MaxChocolateDistribution {

public static void main(String[] args) throws NumberFormatException, IOException {
// TODO Auto-generated method stub

BufferedReader b=new BufferedReader(new InputStreamReader(System.in));

int T=Integer.parseInt(b.readLine());

for(int i=0;i<T;i++){
String line1[]=b.readLine().split(" ");


int M=Integer.parseInt(line1[1]);

String line2[]=b.readLine().split(" ");
int[] sum = new int[line2.length];
int j = Integer.parseInt(line2[0]);
sum[0] = j;
for (int i1 = 1; i1 < line2.length; i1++) {
sum[i1] = sum[i1 - 1] + Integer.parseInt(line2[i1]);
}
int max = 0;
for (int i1 = sum.length - 1; i1 >= 0; i1--) {
for (int p = i1 - 1; p >= 0; p--) {
if ((sum[i1] - sum[p]) % M == 0 && (sum[i1] - sum[p]) > max) {
max = (sum[i1] - sum[p]);
}
}
}
System.out.println(max / M);
}
}

}



Input
-------
3
5 3
1 2 3 4 5
5 4
1 2 3 4 5
5 8
1 2 3 4 5

Output
---------
5
3
0



2018-05-01

LinkedList high level implementation [i]

Problem statement: LinkedList high level implementation in java !
  1. class Node4 {
  2. Node4 next;
  3. int data;

  4. Node4(int data) {
  5. this.data = data;
  6. }
  7. }
  8. public class LinkedListHighLevelExe1 {
  9. Node4 head;

  10. public static void main(String[] args) {
  11. LinkedListHighLevelExe1 l = new LinkedListHighLevelExe1();
  12. l.add(3);
  13. l.add(5);
  14. l.add(8);
  15. l.add(9);
  16. l.print(l.head);
  17. }

  18. // add the element in LinkedList
  19. public void add(int data) {
  20. Node4 next = new Node4(data);
  21. if (head == null) {
  22. head = next;
  23. return;
  24. }
  25. Node4 last = head;
  26. while (last.next != null) {
  27. last = last.next;
  28. }
  29. last.next = next;
  30. }
  31. // print the LinkedList
  32. void print(Node4 next) {
  33. Node4 temp = next;
  34. while (temp != null) {
  35. System.out.print(temp.data + "-->");
  36. temp = temp.next;
  37. }
  38. }
  39. }
Output:
3-->5-->8-->9-->

LinkedList low level implementation [v]

Problem statement: LinkedList low level implementation in java !
  1. class Node3 {
  2. Node3 next;
  3. int data;

  4. Node3(int data) {
  5. this.data = data;
  6. }
  7. }

  8. public class LinkedListLowLevelExe5 {
  9. public static void main(String[] args) {

  10. Node3 head = new Node3(9);
  11. Node3 h2 = new Node3(2);
  12. Node3 h3 = new Node3(4);
  13. Node3 h4 = new Node3(5);
  14. Node3 h5 = new Node3(8);
  15. Node3 h6 = new Node3(9);

  16. // linking the obj reference with the next
  17. head.next = h2;
  18. h2.next = h3;
  19. h3.next = h4;
  20. h4.next = h5;
  21. h5.next = h6;
  22. // h6.next = null;

  23. print(head);

  24. }

  25. static void print(Node3 next) {
  26. Node3 temp = next;
  27. while (temp != null) {
  28. System.out.print(temp.data + "-->");
  29. temp = temp.next;
  30. }
  31. }
  32. }
Output:
9-->2-->4-->5-->8-->9-->

LinkedList low level implementation [iv]

Problem statement: LinkedList low level implementation in java !

  1. class Node2 {
  2. Node2 next;
  3. int data;

  4. Node2(int data) {
  5. this.data = data;
  6. }
  7. }

  8. public class LinkedListLowLevelExe4 {
  9. public static void main(String[] args) {
  10. Node2 head = new Node2(4);
  11. Node2 h2 = new Node2(5);
  12. Node2 h3 = new Node2(6);
  13. Node2 h4 = new Node2(8);

  14. head.next = h2;
  15. h2.next = h3;
  16. h3.next = h4;
  17. h4.next = null;
  18. print(head);
  19. }

  20. public static void print(Node2 next) {
  21. Node2 temp = next;
  22. while (temp != null) {
  23. System.out.print(temp.data + "-->");
  24. temp = temp.next;
  25. }
  26. }
  27. }

Output:
4-->5-->6-->8-->

LinkedList low level implementation [iii]

Problem statement: LinkedList low level implementation in java !
  1. class Node1 {
  2. Node1 next;
  3. int data;

  4. Node1(int data) {
  5. this.data = data;
  6. }
  7. }

  8. public class LinkedListLowLevelExe3 {
  9. public static void main(String[] args) {
  10. Node1 head = new Node1(2);
  11. Node1 h2 = new Node1(5);
  12. Node1 h3 = new Node1(6);
  13. Node1 h4 = new Node1(3);
  14. Node1 h5 = new Node1(9);

  15. head.next = h2;
  16. h2.next = h3;
  17. h3.next = h4;
  18. h4.next = h5;
  19. h5.next = null;

  20. System.out.print(head.data + "-->");
  21. System.out.print(head.next.data + "-->");
  22. System.out.print(head.next.next.data + "-->");
  23. System.out.print(head.next.next.next.data + "-->");
  24. System.out.print(head.next.next.next.next.data+"-->NULL");
  25. }
  26. }

Output:
2-->5-->6-->3-->9-->NULL

LinkedList low level implementaion [ii]

Problem statement: LinkedList low level implementation in java !
  1. class Node {
  2. Node next;
  3. int data;
  4. }

  5. public class LinkedListLowLevelExe2 {
  6. public static void main(String[] args) {

  7. Node head = new Node();
  8. head.next = null;
  9. head.data = 1;

  10. Node h2 = new Node();
  11. h2.next = null;
  12. h2.data = 2;

  13. Node h3 = new Node();
  14. h3.next = null;
  15. h3.data = 5;

  16. Node h4 = new Node();
  17. h4.next = null;
  18. h4.data = 8;

  19. Node h5 = new Node();
  20. h5.next = null;
  21. h5.data = 9;

  22. head.next = h2;
  23. h2.next = h3;
  24. h3.next = h4;
  25. h4.next = h5;
  26. h5.next = null;

  27. System.out.print(head.data + "-->"); // head.data
  28. System.out.print(head.next.data + "-->"); // head = head.next; head.data
  29. System.out.print(head.next.next.data + "-->"); // head = head.next.next; head.data
  30. System.out.print(head.next.next.next.data+"-->"); // head = head.next.next.next; head.data
  31. System.out.print(head.next.next.next.next.data); // head = head.next.next..next.next; head.data
  32. }
  33. }
Output:
1-->2-->5-->8-->9

LinkedList low level implementation [i]

Problem statement: LinkedList low level implementation in java !
  1. class A1 {
  2. A1 n;
  3. int data;
  4. }

  5. public class LinkedListLowLevelExe1 {
  6. A head;

  7. public static void main(String[] args) {

  8. A1 head = new A1();
  9. head.data = 1;
  10. head.n = null;

  11. A1 h1 = new A1();
  12. h1.data = 2;
  13. h1.n = null;

  14. head.n = h1;

  15. A1 h2 = new A1();
  16. h2.data = 3;
  17. h2.n = null;

  18. h1.n = h2;

  19. A1 h3 = new A1();
  20. h3.data = 4;
  21. h3.n = null;

  22. h2.n = h3;

  23. A1 h4 = new A1();
  24. h4.data = 5;
  25. h4.n = null;

  26. h3.n = h4;
  27. System.out.println(head.data); // h.data;
  28. System.out.println(head.n.data); // h=h.n; h.data;
  29. System.out.println(head.n.n.data); // h=h.n.n;h.data;
  30. System.out.println(head.n.n.n.data); // h=h.n.n.n;h.data;
  31. System.out.println(head.n.n.n.n.data); // h=h.n.n.n.n;h.data;
  32. }
  33. }
Output:
1
2
3
4
5

LinkedList implementation


public class MyLinkedList {

public static void main(String[] args) {
// TODO Auto-generated method stub
LinkedList l=new LinkedList();
l.add(1);
l.add(2);

l.print(l.head);
}

}


class A{
A n;
int data;
A(int data){
this.data=data;
}


}
public class LinkedList {
A head;
/*public static void main(String[] args) {


add(1);
add(2);

print(head);
*/




/*
A head = new A(1);
A h1 = new A(2);
A h2 = new A(3);
A h3 = new A(4);
A h4 = new A(5);
A h5 = new A(6);

head.n=h1; h1.n=h2; h2.n=h3;h3.n=h4;h4.n=h5;//h5.n=null;

print(head);


/*A head = new A();
head.data=1;
head.n=null;

A h1 = new A();
h1.data=2;
h1.n=null;

head.n=h1;


A h2 = new A();
h2.data=3;
h2.n=null;

h1.n=h2;

A h3 = new A();
h3.data=4;
h3.n=null;

h2.n=h3;

A h4 = new A();
h4.data=5;
h4.n=null;

h3.n=h4;
*/
/* System.out.println(head.data); h.data;
System.out.println(head.n.data);h=h.n; h.data;
System.out.println(head.n.n.data); h=h.n.n;h.data;
System.out.println(head.n.n.n.data);h=h.n.n.n;h.data;
System.out.println(head.n.n.n.n.data);h=h.n.n.n.n;h.data;

print(head);
*/





//}

public  void print(A head){
A temp=head;
while(temp!=null){
System.out.println(temp.data);
temp=temp.n;
}
}

public void add(int data){
    A new_node = new A(data);

    if (head == null)
    {
        head = new_node;
        return;
    }
    
    A last = head; 
    while (last.n != null)
    {
        last = last.n;
    }
    last.n = new_node;
}
 
}