Monday, January 1, 2018

few defensive coding techniques

Here is a guide to a few guarded (defensive) coding techniques:

(1) Guarding against string nulls

if (StringUtils.isNotBlank(inputString)) {
    // Process
}

Will return false if inputString is blank, spaces or null

(2) Guarding against empty List

A list may be not null, yet it can be empty – to check if the list does contain any elements

If (list != null && !list.isEmpty) {
        // Processing
}
Note: If an instanceof check is present, an extra null check is not required

(3) Boolean  can have 3 values (not 2) – true, false and null.

So, Boolean isVerified = getVerified(…)

Assume isVerified is null, in that case below would fail.

if (isVerified)  {
         // process
}


Instead:

BooleanUtils.isTrue(Boolean.TRUE)  = true
BooleanUtils.isTrue(Boolean.FALSE) = false
BooleanUtils.isTrue(null)          = false


if (BooleanUtils.isTrue(isVerified)) {
      // process
}

(4) A list contains different objects 

Say, List fruits = new ArrayList();
fruits.add(new Apple())
fruits.add(new Orange())

while (iterator.hasNext()) {
    Apple apple = (Apple) iterator.next() ; This code will fail with a classcast
}

Adding instanceof check:

while (iterator.hasNext()) {
            Object o = iterator.next() ;
            if (o instanceof Apple) {
                        Apple apple = (Apple) o;
            }
}


(5) Ensuring numeric checks are present

Backdrop: Say the following code can fail with a NumberFormat if the ageofdriver is not numeric

int driverAge = Integer.parseInt(ageOfDriver);

One of the defensive way of writing that would be as follows:

if (StringUtils.isNotBlank(ageOfDriver) && StringUtils.isNumeric(ageOfDriver)) {
      int driverAge = Integer.parseInt(ageOfDriver);

}

Tuesday, June 17, 2014

Openings in Infosys

Openings in Infosys for experienced professionals.
Please send your resumes to: sambasiva.bollam@gmail.com

SAP
ORACLE

         SAP FICO
         SAP ABAP HR/ABAP CRM
         SAP BO,BODS
         SAP BI/BW
         SAP BPC
         SAP Security/GRC
         SAP PP/QM/PM/EWM
         SAP CRM
         SAP SRM
         SAP SD/MM
         SAP HR
         SAP APO
         SAP CLM
         SAP BPM/BRM
         SAP EP
         SAP Project Manager/Solution Manager
         SAP Change and Release Manager
         SAP Global Convergence Manager 
         OBIEE
         Oracle E-biz (Technical)
         Oracle Financials (Functional and Technical)
         PeopleSoft HCM/Financials (Technical)
         Oracle SOA/Fusion Middleware
         Siebel (Technical)
         Hyperion
         OFSAA
         Oracle  SCM
         Oracle Apps DBA
         Oracle Retail/Retek
         OAF, ADF
         Oracle ASCP,VCP
         Oracle Fusion HCM/Financials
        Oracle Eloqua

Pre-requisites:
         3-12 years of relevant experience in any of the above mentioned skills
         Referrals must have excellent, consistent academic credentials and should be B.E / B.Tech / M.C.A / M.Sc / M.E / M.Tech / CA / MBA
         Relevant package / product experience mandatory

         Job Locations: Bangalore, Hyderabad, Pune, Chennai, Jaipur, Chandigarh, Mangalore



Thursday, May 15, 2014

Java Mail API example

package com.org.sbollam;



import java.util.Properties;

import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.swing.JOptionPane;

public class SendMailExample {
    public static void main(String[] args) {
        String msg = " Mail sent successfully (java mail service application)";
        Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.gmail.com");
        //props.put("mail.smtp.socketFactory.port", "465");
       // props.put("mail.smtp.socketFactory.class",
        //        "javax.net.ssl.SSLSocketFactory");
      //  props.put("mail.debug", "true");  // Debug the program
        props.put("mail.smtp.auth", "true");
        //props.put("mail.smtp.port", "465");
        props.put("mail.transport.protocol", "smtp");

        Session session = Session.getDefaultInstance(props,
          new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication("*****@gmail.com","*****@***");
                }
            });

        try {

            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("*****@gmail.com"));
            message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse("****@gmail.com"));
            message.setSubject(" **SAI HAI- ** ");
            // create the message part
            MimeBodyPart messageBodyPart = new MimeBodyPart();
            //message body
            messageBodyPart.setText("**************** SAY Hi TO,  How R U *************** ");
            Multipart multipart = new MimeMultipart();
            multipart.addBodyPart(messageBodyPart);
            //attachment
            messageBodyPart = new MimeBodyPart();
            DataSource source = new FileDataSource("C:\\Users\\demo\\Desktop\\hai.txt");
            messageBodyPart.setDataHandler(new DataHandler(source));
            messageBodyPart.setFileName("hai.txt");
            multipart.addBodyPart(messageBodyPart);
            message.setContent(multipart);
       
            Transport.send(message);

            //System.out.println("Email sent successfully using this java application");
        } catch (MessagingException e) {
            msg = "Error while sending";
            throw new RuntimeException(e);
        }
        JOptionPane.showMessageDialog(null, msg);
    }
}

Thursday, December 5, 2013

JDBC vs Hibernate

JDBC 
Hibernate 
With JDBC, developer has to write code to map an object model's data representation to a relational data model and its corresponding database schema.  
Hibernate is flexible and powerful ORM solution to map Java classes to database tables. Hibernate itself takes care of this mapping using XML files so developer does not need to write code for this. 
With JDBC, the automatic mapping of Java objects with database tables and vice versa conversion is to be taken care of by the developer manually with lines of code.  
Hibernate provides transparent persistence and developer does not need to write code explicitly to map database tables tuples to application objects during interaction with RDBMS.  
JDBC supports only native Structured Query Language (SQL). Developer has to find out the efficient way to access database, i.e. to select effective query from a number of queries to perform same task.  
Hibernate provides a powerful query language Hibernate Query Language (independent from type of database) that is expressed in a familiar SQL like syntax and includes full support for polymorphic queries. Hibernate also supports native SQL statements. It also selects an effective way to perform a database manipulation task for an application.  
Application using JDBC to handle persistent data (database tables) having database specific code in large amount. The code written to map table data to application objects and vice versa is actually to map table fields to object properties. As table changed or database changed then it’s essential to change object structure as well as to change code written to map table-to-object/object-to-table. 
Hibernate provides this mapping itself. The actual mapping between tables and application objects is done in XML files. If there is change in Database or in any table then the only need to change XML file properties.  
With JDBC, it is developer’s responsibility to handle JDBC result set and convert it to Java objects through code to use this persistent data in application. So with JDBC, mapping between Java objects and database tables is done manually.  
Hibernate reduces lines of code by maintaining object-table mapping itself and returns result to application in form of Java objects. It relieves programmer from manual handling of persistent data, hence reducing the development time and maintenance cost.  
With JDBC, caching is maintained by hand-coding.  
Hibernate, with Transparent Persistence, cache is set to application work space. Relational tuples are moved to this cache as a result of query. It improves performance if client application reads same data many times for same write. Automatic Transparent Persistence allows the developer to concentrate more on business logic rather than this application code.  
In JDBC there is no check that always every user has updated data. This check has to be added by the developer.  
Hibernate enables developer to define version type field to application, due to this defined field Hibernate updates version field of database table every time relational tuple is updated in form of Java class object to that table. So if two users retrieve same tuple and then modify it and one user save this modified tuple to database, version is automatically updated for this tuple by Hibernate. When other user tries to save updated tuple to database then it does not allow saving it because this user does not have updated data.  

Wednesday, August 7, 2013

JOBS AT INFOSYS

Hi All, 

Jobs in Infosys - for below requirements - Please send your resumes at


SAMBAMCA06@GMAIL.COM 



Skill sets we are looking for:
·         Java / J2EE
·         SharePoint
·         Oracle Pl/Sql


Pre-requisites:

·         2 to 8 years of relevant experience in any of the above mentioned skills
·         Referrals must have excellent, consistent academic credentials and should be B.E / B.Tech /        M.C.A / M.Sc / M.E / M.Tech

Wednesday, May 29, 2013

differences between a genuine note and a forged note?


i) Security thread: Rs.10, Rs.20 and Rs.50 notes contain a readable but fully embedded security windowed security thread. Rs.100, Rs.500 and Rs.1000 notes contain a readable windowed security thread. This thread is partially exposed and partially embedded. When held against light, this thread can be seen as one continuous line. Other than on Rs.1000 notes, this thread contains the words 'Bharat' in the devnagri script and 'RBI' appearing alternately. The security thread of the Rs.1000 note contains the inscription 'Bharat' in the devnagri script, '1000' and 'RBI'. Notes issued earlier have a plain, non-readable fully embedded security thread. ii) Latent Image: A vertical band behind on the right side of the Mahatma Gandhi’s portrait, which contains a latent image, showing the denominational value 20, 50, 100, 500 or 1000 as the case may be. The value can be seen only when the note is held on the palm and light allowed to fall on it at 45° ; otherwise this feature appears only as a vertical band.

 iii) Microletterings: This feature appears between the vertical band and Mahatma Gandhi portrait. It contains the word ‘RBI’ in Rs.10. Notes of Rs.20 and above also contain the denominational value of the notes. This feature can be seen better under a magnifying glass.

iv) Identification mark: A special intaglio feature has been introduced on the left of the watermark window on all notes except Rs.10/- note. This feature is in different shapes for various denominations (Rs.20-Vertical Rectangle, Rs.50-Square, Rs.100-Triangle, Rs.500-Circle, Rs.1000-Diamond) and helps the visually impaired to identify the denomination.

v) Intaglio Printing: The portrait of Mahatma Gandhi, Reserve Bank seal, guarantee and promise clause, Ashoka Pillar Emblem on the left, RBI Governor's signature are printed in intaglio i.e. in raised prints in Rs.20, Rs.50, Rs.100, Rs.500 and Rs.1000 notes. vi) Fluorescence: The number panels of the notes are printed in fluorescent ink. The notes also have optical fibres. Both can be seen when the notes are exposed to ultra-violet lamp.

vii) Optically Variable Ink: The numeral 500 & 1000 on the Rs.500 [revised colour scheme of mild yellow, mauve and brown] and Rs.1000 notes are printed in Optically Variable Ink viz., a colour-shifting ink. The colour of these numerals appear green when the notes are held flat but would change to blue when the notes are held at an angle.
Forgeries How does one differentiate between a genuine note and a forged note?
The notes on which the above features are not available can be suspected as forged notes and examined minutely.

New 100 Rupee Coin