It's all about Java: software Tools
Showing posts with label software Tools. Show all posts
Showing posts with label software Tools. Show all posts

Sunday, 11 April 2021

Agile Methodology with SCRUM Framework Basics

Software development activities can be managed and taken care with different life cycle models. These life cycle models has became legacy since few years. Few of the available Software Development Life Cycle Models in short SDLC are Win-Win Model and Waterfall Model etc.

These traditional models has different phases of development. 
       1. Requirements 
       2. Analysis 
       3. Design 
       4. Implementation 
       5. Test 
       6. Documentation 
and 7. Maintenance 

In SDLC, the above stages are freezed one after the other. If developer is in Design phase and realized that there could be a possibility of change in requirements, then it is not possible to go back one phase and fix in Requirement phase. 
These scenarios and use cases has brought Agility in to existence in software development activities.  


Agility in English: 


Agility means "able to move quickly and easily".  Being agile in software development makes the development move or progressed quick enough and flexible to go back and forth through out the development phases and complete the activities on time.


Agile Methodology:



"Agility is the ability that gives better productivity..."


Agile is the ability to create and respond to change. It is a way of dealing with and ultimately succesing in an uncertain environment. Agile methodology has different subsets also called as frameworks. 
SCRUM and Kanban are few among others. These frameworks can be adapted as process solutions based upon different development needs.


SCRUM Framework:

Scrum is a process framework used to manage product development and other knowledge work.

SCRUM framework manages the development activities biweekly, 3 weeks or 4 weeks. This duration is called as Sprint. Usually it is not recommended to have more than 6 members or developers in a team.


Sprint:

Sprint is a duration of time where few backlogs are realized as tasks and completed by development team. Once the Sprint is completed these software changesets goes into release version of the application software.
Based on the need Sprint duration can be 2 or 3 or 4 weeks. But most of the Scrum experts suggest Biweekly sprints.


SCRUM and Meetings:


    1. Standup call
    2. Review Meeting
    3. Grooming Session
    4. Retrospective

Standup calls are held everyday morning that lasts for 15 minutes. And following are discussed:

    1. What is done yesterday?
    2. What is planned today?
    3. Any Roadblocks?

NOTE: It is not recommended to consider more than 15 minutes for Standup meeting

Review Meeting is held at the end of the Sprint showing different works and demos of Sprint's development activites.

Grooming Session lasts for one and half hours. During this session tasks are pulled from backlogs and discussed the following:

    1. Estimations for the Tasks
    2. Deciding the priorities
    3. Severity levels
    4. Assignments


Retrospective meetings are held after the end of Sprint and discussed about:

    What went correct..?
    What went wrong..?
And Appreciations if any...
     

Scrum framework and few notable points:

  1. All requirements are consolidated as backlogs along with its descriptions and other details.
  2. Estimations of backlogs are done with the Poker Cards
  3. Poker cards are numbered in a Fibonacci order
  4. SCRUM is managed by Certified SCRUM Master or SCRUM Coach
  5. If Standups are not held with in 15 minutes, can be considered as limitation.
  6. Virtual Boards are considered over Physical boards, if members are in remote locations 

SCRUM and Agile Supporting Tools:

  1. Microsoft Azure Boards
  2. Atlassian JIRA
  3. IBM - Rational Team Concert 


SCRUM Limitations:

  • Geographically if team members are located in different places, Agile may not be effective


Sunday, 28 January 2018

Java desktop GUI.

Graphical user interface in short GUI makes computer users easy to understand and use the application software comfortably. Almost all modern programming languages allows application developers to develop GUIs.

Java has AWT/Swing as default API as part of Java Foundation classes in short JFC which are shipped with JDK. Hence these toolkits can be used directly in our applications with out adding external libraries like jars to our application's class path. But there are some other toolkits which found useful and industry endorsed in developing GUI.

    •      SWT 
    •      JFaces [Framework for SWT]
    •      Java FX
    •      Swing
    •      AWT

AWT:

Abstract window toolkit is available since java first version. AWT uses native operating system resources like Fonts, colors and components like table, tree, dialogues, windows etc.

Few notable points about AWT:
  • AWT is heavy weight. It uses OS resources
  • There are limited components in AWT precisely only components which are available in native OS. 
  • We can not have a new component according to our business logic need. ex: Tri state checkbox or treetable  
  • AWT behaves differently on different platforms
  • Hence it violates the java Platform independence rule
  • The program GUI developed with AWT looks differently on different OSs. Means on linux it renders linux graphics look and feel and on windows platform it renders windows graphics look and feel.   
  • Provides event model API which also used by Swing toolkit

Swing:

  • Swing was designed and developed keeping all cons in mind that are caused due to using AWT toolkit.
  • First of all "Swing is pure java hence it is platform independent." This statement made many good things possible:
Few notable points about Swing:
  •  Swing is light weight. It does not depend on native OS resources 
  •  Unlike AWT, it is extensible. New custom components can be developed according to program  requirement. 
   NOTE: See swingx library in it's official site.
  •  Swing has Pluggable look-and-feel support in short PLAF.
  •  Drag and Drop api, 2D api, internationalization are few among other included in Swing toolkit.
  •  Netbeans IDE itself is a good example for swing based application used allot now a days.
  •  Few GUI experts noticed that Swing is slow and not quite professional for commercial applications

SWT:

Standard Widget toolkit in short SWT is another toolkit for developing Java Desktop GUI based applications.
Compared to Swing it is faster and consistent in performance and Eclipse IDE itself is an example for SWT based applications.
Eclipse is industry endorsed IDE specifically for java based software development.
This is not shipped with JDK. Please see eclipse.org [official site] for more details.
And there are Integrated development environments in short IDE which provides Drag and Drop [DAD] palettes also known as GUI Builders for above toolkits for programmer's convenience.
Mostly used IDEs are:
It is advised to code manually to develop the GUI rather using GUI builders provided by different IDEs. And for beginners.  


Saturday, 27 January 2018

Java Multi threaded programming basics


All modern computer hardware architectures and operating systems are capable and optimized for multi processor system and multi threaded system. 

Process Vrs Thread:

Process is heavy weight where as Thread is light weight. Thread is light weight because process uses it's own address space and thread shares the Process's address space. So Threads are considered to be subset of a process. more over threads consumes less OS resources in terms of physical memory and uses CPU time at most.

Junior programmers think concurrency is hard. 
Experienced programmers think concurrency is easy. 
Senior programmers think concurrency is hard. 
                                                                                  _Java Concurrency Essentials by Martin

                                                                                  

Java supports implementing multi threaded applications using java core API and keywords.
Java Run time in short JRE closely works with native operating system at run time to run applications in multi threaded environment.

Java Support for Thread:

Keywords: synchronized, volatile

API support: Basically Runnable Interface, Thread class, Object class and java.util.concurrency package [> java 5] and few other API

Java categorizes Threads into 2 types.

1. Daemon Threads

Daemon threads mostly runs with less priority to compute some not so important task quickly. periodically. [EX: finalize() of Object class (Not advised to override at all. instead use finally block)] and JVM itself starts few daemon threads internally.
These Threads are active until all normal threads are terminated. The main thread is the last normal thread that gets terminated when the application is closed. Hence once this main thread is terminated all daemon threads are terminated subsequently and application is closed.

NOTE: Any threads can be marked as daemon thread using Thread class setDaemon().

2. User Threads
           
User threads are any threads that programmer creates using java api to compute some tasks concurrently which executes concurrently with other threads.


Advantages of Multi thread Programming:


     Let's consider a use case which demonstrates multi threaded environment.
  1. Simple buffer which stores data temporarily while computing some task.
  2. Buffer size is 10 and dynamically can not be changed.
  3. Producer algorithm: Sequence of instructions which produces data for this buffer.
  4. Consumer algorithm: Sequence of instructions which consumes data from this buffer.
  5. Once buffer is full, delete all elements so that producer algorithm starts producing new feed.
  6. Consumer not allowed to consume data unless buffer is full and empties the buffer
  7. Once it consumes all elements then, let's producer know that it can start producing elements.


This above problem can be considered as a producer and consumer problem which can be solved in number of ways. But it is always good idea to use multiple threads.

How Multi threaded environment enhances the application performance?

Multi threaded programs uses the modern computers operating system resources at maximum, hence gives       
      1. High throughput,
      2. Faster execution,
      3. Quick responsiveness are few among others

Let's see how producer and consumer problem in short PC Problem can be solved using Java:



import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * 
 * Buffer implementation with ArrayList and with Producer consumer problem impl
 * using traditional synchronization or implicit lock
 * 
 * @author Nagasharath
 *
 */
public class BufferImpl {

    private CopyOnWriteArrayList<String> buffer;

    private final short SIZE = 10;

    private boolean isBufferFull = false;

    public BufferImpl() {
        buffer = new CopyOnWriteArrayList<String>();
    }

/**
* @throws InterruptedException
*/
private void producesFeed() throws InterruptedException {
    synchronized (this) {

        while (true) {
            if (isBufferFull) {
                System.out.println("Started Consuming!....\n");
                notify();
                wait();
            }

        buffer.add(String.valueOf(System.nanoTime()));
        if (SIZE <= buffer.size()) {
            isBufferFull = true;
            Thread.sleep(10000);
            System.out.println("Buffer full. Production halts...\n");
        }
       }
    }
   }

/**
* @throws InterruptedException
*/
private void consumesFeed() throws InterruptedException {
        synchronized (this) {
            while (true) {
                Iterator<String> iter = buffer.iterator();
                while (iter.hasNext()) {
                    String next = iter.next();
                    System.out.println("Consuming element: " + next);
                    buffer.remove(buffer.indexOf(next));
                }
                isBufferFull = false;
                System.out.println("Started producing!....");
                notify();
                wait();
            }
        }
    }

/**
* @author Nagasharath
*
*/
class ProducerThread extends Thread {
    @Override
    public void run() {
           try {
               producesFeed();
            } catch (InterruptedException e) {

            }
    }
}

/**
* @author Nagasharath
*
*/
class ConsumerThread extends Thread {
     @Override
    public void run() {
        try {
        consumesFeed();
        } catch (InterruptedException e) {

        }
    }
  }

    public static void main(String[] args) {
    BufferImpl impl = new BufferImpl();
    ProducerThread producerThread = impl.new ProducerThread();
    ConsumerThread consumerThread = impl.new ConsumerThread();

    producerThread.start();
    consumerThread.start();
    }
}

Let us simplify the above program

Variables used in the program:

        private CopyOnWriteArrayList<String> buffer;

       private final short SIZE = 10;


        private boolean isBufferFull = false;




buffer is of type CopyOnWriteArrayList [COWA] to store elements. CopyOnWriteArrayList is fail safe data structure which is suitable for concurrent programs. 
Do not forget to run the same program by replacing CopyOnArrayList with ArrayList. If this is the case the program throws ConcurrentModificationException as a result as ArrayList Iterator is fail fast behavior.   


SIZE is a constant of type short which holds the size of COWA data structure

isBufferFull is a switch which holds whether the buffer size is full or not. 


Method to implement Producer algorithm:

 1     /**
 2        * @throws InterruptedException
 3        */
 4     private void producesFeed() throws InterruptedException {
 5         synchronized (this) {
 6
 7             while (true) {
 8                 if (isBufferFull) {
 9                     System.out.println("Started Consuming!....\n");
10                     notify();
11                     wait();
12                 }
13
14             buffer.add(String.valueOf(System.nanoTime()));
15              if (SIZE <= buffer.size()) {
16                 isBufferFull = true;
17                 Thread.sleep(10000);
18                 System.out.println("Buffer full. Production halts...\n");
19             }
20             }
21         }
22     }

producesFeed() uses java keyword synchronized, Object class notify(), Object class wait() and Thread class sleep() to get the job done.

Line 5: keyword synchronized is used to gain the monitor lock on this object. Here this  refers to the    PCProblem object. Lock ensures mutual exclusion. These are of 2 types Implicit locks and reentrent locks. 

synchronized key word is of type implicit lock also known as intrincic lock.

NOTE: Use synchronization judicially because it influences the performance of application. [Slows down the speed of program]   

Let's see more about synchronization and monitor locks in upcoming posts.

Line 7: Initiates the infinite while loop which runs continuously.

Line 10: calls notify() which is one of the inter thread communication Object class api to tell next waiting thread to start it's communication

Line 11: calls wait() which is again one of the inter thread communication Object class api to tell current thread to wait until next running thread notifies.

Line 14: buffer starts holding current time in nano seconds as element of String type. This will be continues till the size reaches 10.
Line 15: checks the above condition

Line 17: Once the SIZE reaches limit to 10 calls Thread.sleep() to make the current running thread to sleep for 10 seconds. [Used here only for demo sake and to simulate the processing behavior]


 1     /**
 2      * @throws InterruptedException
 3      */
 4     private void consumesFeed() throws InterruptedException {
 5         synchronized (this) {
 6             while (true) {
 7                 Iterator<String> iter = buffer.iterator();
 8                 while (iter.hasNext()) {
 9                         String next = iter.next();
10                         System.out.println("Consuming element: " + next);
11                         buffer.remove(buffer.indexOf(next));
12                   }
13                 isBufferFull = false;
14                 System.out.println("Started producing!....");
15                 notify();
16                 wait();
17             }
18         }
19     }

Line 5: Acquires lock on PCProblem Object 

Line 7: Iterator of CopyOnWrireArrayList to iterate over List for processing it. The basic difference between ArrayList and COWA is Fail fast behavior. ArrayList is fail fast and COWA is Fail safe suitable for cuncurrent behavior. 

Note: Never use for (string ele : listObj) { .... } to modify elements in a list. Instead use Iterator.

Line 11: Once element is consumed remove the element from list.

Line 13: Make flag isBufferFull false once all data is consumed.

Line 15 and Line 16: Call to notify() and wait() to tell the producer thread to start it's execution and the latter one to make current thread to wait respectively.

     


 1     /**
 2      * @author Nagasharath
 3      *
 4      */
 5     class ProducerThread extends Thread {
 6         @Override
 7         public void run() {
 8               try {
 9                 producesFeed();
10             } catch (InterruptedException e) {
11
12             }
13         }
14       }
15
16     /**
17      * @author Nagasharath
18      *
19      */
20     class ConsumerThread extends Thread {
21         @Override
22         public void run() {
23             try {
24                 consumesFeed();
25              } catch (InterruptedException e) {
26
27             }
28         }
29       }

The above snippet creates 2 Threads one is Producer thread and the other is Consumer thread. 

Line 1 to Line 16: ProducerThread extends Thead class [part of java core API] then at run time JVM considers closely works with operating system to run this producesFeed() as a separate thread. 

Line 16 to Line 29: ConsumerThread extends Thread class which runs consumerThread() as a seperate thread. In our use case Producer and Consumer executes simultaneously.

 1        public static void main(String[] args) {
 2             BufferImpl impl = new BufferImpl();
 3             ProducerThread producerThread = impl.new ProducerThread();
 4             ConsumerThread consumerThread = impl.new ConsumerThread();
 5
 6             producerThread.start();
 7             consumerThread.start();
 8         }

Line 1: creates main(). Java run time first executes this method as an initial thread. This thread is responsible for creating all other threads. in our case ProducerThread and ConsumerThread.

Line 6 and Line 7: Call to the start() starts producer and consumer threads.

Note: always prefer start() to run() of Thread class to initiate and start new Thread.

 Output:

Buffer full. Production halts...

Started Consuming!....

Consuming element: 2747727445120473
Consuming element: 2747727445291566
Consuming element: 2747727445310340
Consuming element: 2747727445349593
Consuming element: 2747727445369646
Consuming element: 2747727445377753
Consuming element: 2747727445384153
Consuming element: 2747727445390126
Consuming element: 2747727445395673
Consuming element: 2747727445400793
Started producing!....
Buffer full. Production halts...

Started Consuming!....

Consuming element: 2747737453672999
Consuming element: 2747737453761319
Consuming element: 2747737453798013
Consuming element: 2747737453825319
Consuming element: 2747737453849639
Consuming element: 2747737453871826
Consuming element: 2747737453893159
Consuming element: 2747737453914919
Consuming element: 2747737453936679
Consuming element: 2747737453957586
Started producing!....





That's all for now. Next post explains solution to the same PC problem using concurrency utility classes introduced in Java 1.5.

Happy coding! :)

Sunday, 29 October 2017

Eclipse Java Editor Shortcuts

Eclipse Oxygen Java editor Shortcuts helps in editing source code more comfortably. Frequently used default shortcuts are listed below. 




Description
Shortcut
Delete Line
CTRL + D
Copy Line
CTRL + ALT + Down Arrow
Add method level, class level, member level Comments
SHIFT + ALT + J
Format Java Source code
CTRL + SHIFT + F
Make line commented
CTRL + /
Make multiple lines [block] commented  
CTRL + SHIFT + /
Search selected similar word within the source document
CTRL + K
Select line from beginning to end
SHIFT + End key
Select line from end to beginning
SHIFT + Home key
Select Word by word in same line
CTRL + SHIFT + Right Arrow
Move line above
ALT + Up Arrow
Move line below
ALT + Down Arrow

Shortcuts can be customized and new shortcuts can be created through Keys Page in Preferences wizard.


  1.  Window menu > Go To Preferences 
  2.  Type Keys as the "filter text"
  3.  Please find the image below for reference.


Example:
Add new Shortcut for cut whole line command.

  1.  In Keys page type filter text -- Cut line
  2.  Type your convenient key. In my case I added SHIFT + X
  3.  Finally, Click Apply and Click Apply and Close.
  4.  That's it. Now Test your new Shortcut. 

Happy Coding :)

Tuesday, 27 December 2016

WMI - Windows Management Instrumentaion

WMI is a windows Library used to get the information like no of processes running currently in the computer and their event notifications like process creation modification and deletion notifications, cumputer's name, version, Win32 processes list etc

The information above mentioned can be fetched not only from local PC but also the remote machine too..

WMI can be accessed through a query langauge in two ways they are:

1. WBEMTEST.exe [GUI Tool]
2  WMIC- stands for WMI Commandline tool
3. Programatically [using Powershell and VBScript]


1. wbemtest.exe:



      How to start

         1. go to start
     
         2.  go to Run
       
         3. Type wbemtest.exe
       
         4.  the following window opens up.



Queries that can be run with this tool

1. Usual queries
2. Notification queries

Usual queries are used to query the processes and other system information etc. the query fetches the information from repository and ends the task.

Example Query:

SELECT * From Win32_Process

the above syntax fetches the current running Win32 process.




Notification queries are those which runs continuously and gives the notification of Process creation, modification and deletion and returns the object through which process information can be fetched accordingly.

Example Query:

SELECT * FROM __InstanceDeletionEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process'

the above query notifies us whenever an existing process is deleted. WITHIN clause checks the condition for every 1 second. this query needs to be executed in Notification Query window. please refer the above figure.

 SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process'

This above query notifies when new process is created


2. WMIC.exe

The second approach for accessing WMI is WMIC.exe which is a command line tool.

1. goto start
2. goto Run
3. open the CMD.exe
4. type wmic.exe



the above steps opens up the wmic command line tool where we can fetch OS, Processes, memory information and many more :) details of a PC.



Example command

 Process List

the Process list command lists the all the processes running currently in local machine.


Apart of these tools we can access the WMI through programs too using VBScript and Powershell.


Happy Coding! :)





Monday, 26 December 2016

Apache Commons Exec API for executing exe files from java program

In my previous post http://java-gui.blogspot.in/2016/12/api-for-executing-exe-files-from-java.html    you have seen using traditional java API to execute exe files from java program.

but it is proved that it is not an ideal solution for  programs which handles IO operations and for async executables. you can find more advantages of Apache Commons Exec library over traditional API in the below link.

              http://commons.apache.org/proper/commons-exec/index.html


Simple example that uses the Exec library:

// class to pass the command ex: cmd.exe and its arguments...

CommandLine command = new CommandLine("ping");

// arguments to the command object can be passed in 2 ways...

command.addArguments("localhost") ;
command.addArguments("-t") ;
command.addArguments("-count");

   or

command.addArguments(new String[]{"-t", "-count"});


//handling the IO operations gracefully using LogOutputStream abstract class


LogOutputStream in = new LogOutputStream() {

@Override
protected void processLine(String line, int exitvalue) {

                       //handle the output which was produced by the process....
                      System.out.println(line);
               }
};
PumpStreamHandler streamHandler = new PumpStreamHandler(in, in);

// Executing the command along with its arguments

DefaultExecutor executor = new DefaultExecutor();

//attaching the created shreamhandler to the executor...

executor.setStreamHandler(streamHandler);

// execution...
executor.execute(command);


the above program executes the ping command and displays the output using the standard out.

Executing the interactive executables can be found in the below link...


link


API for executing exe files from java program.

The traditional API for calling the executable in java program is using the Runtime, Process and their methods like exec(command), waitFor() methods respectively.

a simple example to execute a notepad.exe from java program using the above API is given below.

Process process = Runtime.getRuntime().exec("notepad.exe");

the above code is used to launch the notepad.exe executable from java program.


if there are multiple commands needs to be passed then the code would be....

String[] command = {"cmd.exe", "/C", "echo ", "%TEMP%"}; 
Process process = Runtime.getRuntime().exec(command);

the above snippet is used to execute multiple commands in a java program. this code prints the environment variable TEMP on to the console.


Handling standard output produced by the above code:

BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
String output = "";
String line = "";

while((line = input.readLine()) != null){

System.out.println(line);

}

This Procedure is ideal when there is an executable to run without waiting for its completion of execution. despite the a method called p.waitFor() which waits until the process execution is completed, it is difficult to handle the process's standard Outputs and Inputs gracefully. and the no of lines of code also increases drastically.

the alternative to this traditional API is Apache Commons Exec  library.




Monday, 4 July 2011

Java IDE for Learners:


           Simple editors like Notepad, Gedit, edit+  definitely allows us to write a program, but it is always difficult to code, debug and manage even smaller applications. and profession IDEs like Eclipse, Netbeans JDeveloper are definitely not suitable for beginners.[They are pretty advanced to students]

           What if we have an IDE which allows the learners to understand the basic coding principles of java, Fundamentals of Object Oriented Programming[OOP] with the pictorial representation along with syntax highlighting, scope highlighting and other cool features?.. sounds good right.
         
                   
           BlueJ is a simple Java based IDE developed by Kent university for the beginners and students of Java programming language. The coolest thing about BlueJ is it not only allows us to interact[compile, execute] with complete application or program but also single objects.Hence we can create Objects and execute its methods graphically.

Important features are:
  • Create classes and interfaces through wizards and diagrams
  • Create directly object of a class and execute its methods rather than executing complete application.
  • Debugger, Terminal etc
Editor Features:
  •      Syntax Highlighting
  •      Scope Highlighting
  •      Code completion
  •      Navigation View
  •      Switch between source code and Documentation 




Popular posts

Atomicity with Java Programming Language

 Atomicity with Java What is Atomicity Atomicity, in computer science, is considered to be a property [ALL-OR-NOTHING], that the state of a ...