Category Archives: JAVA

Best Programming Practices

Any code when written in a clean, easy to understand and formatted way is easily readable and accepted by everyone.

It is essential for everyone to easily understand the code one writes as same projects can involve participation of multiple programmers. For easy identification and understanding of the code and code flow by everyone involved, it is essential that the code is structured, clean, and easily maintainable.

Explained below are some of the practices to write clean and understandable code.

 

Commenting and Documentation

For any software project reliable documentation is crucial. Commenting and documentation helps one analyze what’s happening inside the code. This is very crucial for the one who is examining the code for the very first time. Writing comments for methods or functions is good for understanding its purpose. They can quickly show what a complex function is doing.

However, don’t write unnecessary comments as it would make your code messy. Obvious commenting does more harm than good. Comment should describe only what the method is doing or why it’s written. It can also describe the purpose of writing the program in a nutshell at the beginning of a class or module.

 

Naming Conventions

Adopting a consistent naming convention in your program is always a sensible and thoughtful practice.  It’s a set of rules for picking the character flow to be used for identifier, which signify variables, functions & methods. It makes it easier to understand the purpose of using that variable / function / method. If one’s a beginner, it’s a good practice to give meaningful names to your variables, methods, functions etc. instead of vague combinations of alphabets and numbers. Using camelCase and underscores is a widely popular approach. Use of camel case is to be preferred  as this does not create confusion between salesforce api names and variable names in case of apex code.

 

Consistent Indenting

There’s nothing worse than reading a piece of code that is poorly formatted. Indenting makes your code looks neat and clean. It is easy to understand the flow of program, the link between control flow constructs such as loops and codes written inside and outside of them.

 

Keeping it simple

One should keep their code as simple as possible. Avoid writing complex code for simple logic. Try breaking down your code in multiple methods if the logic is getting too complicated for a single module.

Ideally a method or a function should not have more than 40-50 lines of code, excluding comments.

Modules like servlets, triggers and callouts should not have any logic written in them. All the logical operations should be performed in a helper lass.

 

Portability

It is not advisable to use “hard-coded” values referring to environmental parameters, such as absolute file paths, file name, user name, host name, URLs etc. Else, the application might not run on a host with a different design. An efficient programmer should parametrize such variables and configure them as per the hosting environment outside of the application.

The best way to do it would be to maintain all the required constants in a single file which is easily configurable without making any code changes.

 

Loops and conditional statements

Beware of using loops and conditional statements in your code! Choose right loops at the right place in order to save code’s execution time.

Too many nested blocks of code can reduce code efficiency and readability drastically.

 

Omit unwanted code

It’s very common to find a block of code commented inside the program. It’s not going to do any harm to your program but bloats the code unnecessarily, so try not to keep such code. In addition, since this code is not going to be executed or compiled there is no difference between commenting out and deleting that code. Deleting commented codes makes your entire program looks cleaner.

In case of future necessity of the commented blocks, maintain additional backup along with the code repositories.

 

Do not just copy and paste code

If you have a snippet of, say, seven lines of code that do one thing, and you want to do it again for another module, don’t just copy and paste the code. Instead, make a function and to make it reusable. It’ll keep your code simple.

 

Code versioning

Code Versioning, popularly known as version control, is the management of the changes made to computer programs, documents and other collection of information.

In computer programming, it refers to the process of tracking & controlling the changes made to the source code.

Version control becomes very important especially when working in a big team as this saves additional time that one might require for code merging and also one can easily backtrack in case of errors.

 

Code versioning is to be done for every project using available resources like Gitlab, Github, Assembla, etc.

Posted in Agile, Apex Development, J2EE, JAVA, Organization Culture.

How To Create Your First Rest Web Service

What is web services?

mirketa-webservices1

 

web service is a piece of software that makes itself available over the internet and uses a standardized XML messaging system. XML is used to encode all communications to a web service. For example, a client invokes a web service by sending an XML message, then waits for the corresponding XML response.

There are mainly two types of web services.

    1. SOAP web services.
    2. RESTful web services.

 

Components of Web Services

    • SOAP (Simple Object Access Protocol)
    • UDDI (Universal Description, Discovery and Integration)
    • WSDL (Web Services Description Language)

 

Soap web services: – SOAP is XML based protocol. It is platform and language independent. By using SOAP, you will be able to interact with other applications designed in different programming languages.
Continue reading

Posted in Agile, AGILE Tools, HTML/CSS, HTTP, J2EE, JAVA, Java Script, REST API, WEB SERVICES, XML. Tagged with , , , , , , , , .

Programmatically Create Select Type Custom Field In Jira

In order to create a custom field type, you should be aware of basic plugin development.

Please follow the following steps to create an advanced custom field type in Jira.

    1. Create a basic Jira plugin skeleton. For creating Jira Plugin please refer to the given linkhttps://developer.atlassian.com/docs/getting-started/set-up-the-atlassian-plugin-sdk-and-build-a-project/create-a-helloworld-plugin-projectAfter creating a Basic plugin skeleton modify your atlassian-plugin.xml and add the following code in your atlassian-plugin.xml.
    2. After creating a Basic plugin skeleton modify your atlassian-plugin.xml and add the following code in your atlassian-plugin.xml. <customfield-type key=”Jira-Cf-Type-field” name=”Jira-Select CFType” class=”com.atlassian.jira.plugin.customfield.JiraCustomFieldType”><description>Create Your Own Advance Custom Field Type</description>                             <resource type=”velocity” name=”view” location=”templates/plugins/fields/view/view-basictext.vm”/><resource type=”velocity” name=”edit” location=”templates/edit- jiraselectcftype.vm”/><resource type=”velocity” name=”xml” location=”templates/plugins/fields/xml/xml-basictext.vm”/>

      </customfield-type>

                                          

      com.atlassian.jira.plugin.customfield.JiraCustomFieldType – class which extends an available CustomField Class to provide an entry point for the custom field.
      Continue reading

Posted in Agile, AGILE Tools, J2EE, JAVA, Java Script, JIRA, JIRA on Demand. Tagged with , , , .

Qualities of a Good Programmer

Programming is a very challenging domain as it requires a lots of patience and concentration. Before learning any programming language, one must have the attitude to not give up till one finds the solution. Programming language is just a way to solve a problem but logical skills and ability to solve the problem are the basic requirements of a good programmer.

Following are 7 essential qualities of a good programmer:
Continue reading

Posted in Agile, AGILE Tools, JAVA, salesforce administrator. Tagged with , , , .

OAUTH 2.0 AUTHENTICATION FOR THIRD PARTY APPLICATIONS

Most of the APIs now-a-days incorporate oauth 2.0 authentication. It is not as complicated as it may seem at times, provided the right links and documentation are found. Microsoft APIs are extremely helpful and useful, but to access them from a third party application is when its needed, for the entire process of registration and access token retrieval, to be followed; to comply with the oauth authentication in place.

For office365 (2016) APIs the links that would help access these APIs would be of the format https://outlook.office.com/api/{version}/me/

me – represents the logged in user
{version} – v2.0 or v1.0
/… – events (for outlook calendar API)

The first step, as hundreds of websites mentions, is to register the application. To be a little more comprehensive on this point, I would like to mention that it is not required to deploy any kind of code or application into the registration portal.

https://apps.dev.microsoft.com is free if you have access to a Microsoft office account.

The registration process is a way of letting Microsoft know that a particular app is going to access its APIs. It is a good practice to name the app appropriately as it will appear on the screen when the application, that is being developed, navigates to the login page.

mirketa_oAuthAppRegistration

Application id is the client id which is needed to be provided in the headers when requests are made for authorisation code and access token.
Continue reading

Posted in Agile, AGILE Tools, J2EE, JAVA, Java Script, JIRA, UI, WEB SERVICES. Tagged with , , , , .

Introduction to Version Control System

A version control system, to a great extent, is based around the concept of tracking changes that happen within a collection of directories or files.

A version control system (VCS) allows you to track the history of a collection of files. It supports creating different versions of this collection where each version captures a snapshot of the files at a certain point in time and the VCS allows you to switch between these versions as well. These versions are stored in a specific place, typically called a repository.

The process of creating different versions (snapshots) in the repository is depicted in the following infographic. Please note that this picture fits primarily to Git. Other version control systems like Concurrent Versions System (CVS) don’t create snapshots of the files but store file deltas.

mirketa-git-VCS

  Continue reading

Posted in Agile, AGILE Tools, Apache Ant, J2EE, JAVA, Java Script, JIRA, JIRA on Demand, MirketaInc. Tagged with , , , , , , .

How to programmatically move attachments from one JIRA issue to another JIRA issue?

The following piece of code when executed, helps us move attachments between two issues of same project or different projects in Jira.

Here I have two issues, one of them will be the source issue, where user adds an attachment and another issue will be the target issue, where the user want to move the attachment to.

This functionality is working fine in JIRA in its UI, however, I have tried to accomplish the same functionality through Java code. The following code executes the task of moving an attachment between the issues of both same or different projects.
  Continue reading

Posted in J2EE, JAVA, JIRA, JIRA on Demand. Tagged with , , , , .

SILVER BULLET

No matter how terrifying a monster is, humans always try to find the silver bullet, to bring the inexplicabilities of the monster to a level of comprehension. Software is referred to as such a monster because its ever expanding level of complexity brings with it, multifarious issues which themselves are monstrous in their own accord.

 

The inherent properties of a modern software system are conformity, changeability, complexity and invisibility. Conformity is a necessary evil and normally has no logic to it but, for organisational restrictions. Changeability again is a constant sword hanging over software systems. Complexity of software systems is rather interesting as it is desired and not accidental and yet constitutes most of the monstrosity of software systems. By invisibility I refer to the fact that that there isnt any tool that can physically and convincingly represent a software system and this limits us in ways nothing else does.

 

Lets backtrack to when abacus had just been invented, we thought this was definitely an answer to the egregious calculations. As calculations became more and more complicated, seeking an answer led us to the beautiful concept of object oriented programming. It was a moment of celebration for developers all over the world as they thought- finally we have our solution. OOP with its modularity, reusability, reliability, maintainability etc. definitely addressed a lot of issues. However, software is abstract and a conceptual entity and hence visualisation of its impact and its challenges is indefinitely and inherently complex. We have now come a long way and invented supercomputers like IBM,�Sequoia, Cray,�Titan, NUDT,�Tianhe-2, and yet we are not close to our silver bullet. OOP, however, many would argue, is the closest thing to a silver bullet in the software world.
Continue reading

Posted in Agile, JAVA, MirketaInc. Tagged with , , , , , , , , , .