Working with ENUM
ENUM is just a list of set of value which are static and final.Executing the below code will have a output like one below

public class Test {
	public enum Company {
		EBAY, PAYPAL, GOOGLE, YAHOO, ATT
	}

	public static void main(String[] args) {
                System.out.println(Company.EBAY);
	}
}

Output

  EBAY

Now what you can do is to make this constant (static and final) to have further attributes like one below.

public enum Company {
EBAY(30), PAYPAL(10), GOOGLE(15), YAHOO(20), ATT(25);
private int value;
 
private Company(int value) {
this.value = value;
}
}

and more Values with overloaded constructor

public class Test1 {

	public enum JobStatus {
		OPEN("Open", "Its Open", "1"), ERROR("Error", "Its a Error", "2"), WORKING(
				"Working", "Its Working", "3"), CLOSED("Closed", "Its Closed");
		private String	value;
		private String	label;
		private String	order;

		private JobStatus(String label, String value, String order) {
			this.label = label;
			this.value = value;
			this.order = order;
		}

		private JobStatus(String label, String value) {
			this.label = label;
			this.value = value;
		}

		public String getValue() {
			return this.value;
		}

		public String getLabel() {
			return this.label;
		}
	}

	public static void main(String[] args) {
		System.out.println(JobStatus.OPEN.value);
		System.out.println(JobStatus.OPEN.label);
		System.out.println(JobStatus.OPEN.order);
		System.out.println(JobStatus.CLOSED.order);
	}
}

Output

Its Open
Open
1
null

When you need a predefined list of values which do not represent some kind of numeric or textual data, you should use an enum. For instance, in a chess game you could represent the different types of pieces as an enum

enum ChessPiece {
PAWN,
ROOK,
KNIGHT,
BISHOP,
QUEEN,
KING;
}

Assigning Values to ENUM

public enum Company {
EBAY(30), PAYPAL(10), GOOGLE(15), YAHOO(20), ATT(25);
private int value;
 
private Company(int value) {
this.value = value;
}
}
  • All enums implicitly extend java.lang.Enum.
  • MyEnum.values() returns an array of MyEnum’s values.
  • Enum constants are implicitly static and final and can not be changed once created.
  • Enum can be safely compare using “==” equality operator
  • An enum can be declared outside or inside a class, but NOT in a method.
  • An enum declared outside a class must NOT be marked static, final , abstract, protected , or private
  • Enums can contain constructors, methods, variables, and constant class bodies.
  • enum constructors can have arguments, and can be overloaded.

Simple Search based on Three Parameters

The Search should happen even when one element of the form is not Empty.


isParamNotEmpty = false;

if(param1.isNotEmpty())
{
  .
  .
  Other Coding Lines
  .
  isParamNotEmpty = true;
}

if(param2.isNotEmpty())
{
  .
  isParamNotEmpty = true;
}

if(param3.isNotEmpty())
{
  .
  . 
  isParamNotEmpty = true;
}

if(isParamNotEmpty)
{ 
  doSearch(); 
}

Simple Oracle Function which Returns Yes or No

CREATE OR REPLACE FUNCTION isStudentInArmy(p_location  IN VARCHAR(255),
                                           p_age       IN LONG)
RETURN CHAR
IS
   isArmyMen CHAR(1);
BEGIN
  SELECT CASE 
          WHEN  BodyType == 'Well Built and Strong' THEN  'Y'
          ELSE 'N'
       END INTO isArmyMen
  FROM tblMens 
 WHERE Location = p_location AND
       Age      = p_age;

  RETURN isArmyMen;
END isStudentInArmy;

How to set a Specific option as selected

<html>
<head>
	<script src="jquery-2.1.0.min.js" type="text/javascript"></script>
	<script>
	 $('document').ready(function(){
	   $('#btnSubmit').click(function(){
            alert($('#cboLocation').val());
            alert($('#cboLocation').find(":selected").text());
			});
		});
	</script>
</head>
<body>
<select name="cboLocation"  id="cboLocation">
  <option value="">Select Zone</option>
  <option value="South">South Chennai</option>
  <option value="North">North Chennai</option>
  <option value="East">East Chennai</option>
  <option value="West">West Chennai</option>
</select>
<input type="button" name="btnSubmit" id="btnSubmit" value="Click Me"/>
</body>
</html>

How to get Selected Item Value

 alert($('#cboLocation').val());

How to get Selected Item Text

 alert($('#cboLocation').find(":selected").text());

1.Utility Classes should have constants for variable

public class PolicyUtils 
{
 public static final String TOTAL_POLICY_LIMIT = "totalpolicylimit";
 requestHelper.setRequestAttribute(TOTAL_POLICY_LIMIT, policyLimit);
}

Since multiple Users can access the JSP page at same time assigning variable name to constant and changing it later makes it easy to change the actual variable name in case needed in future.

Posted in JSP.

Earnings per Share (EPS)

EPS = Profit/Total no of Shares

More the EPS tells the company is running in Profit

Book Value of Share
Book Value

Book Value = Assets – Liabilities

(or)

Book Value = Total amount after selling Company Asset/Total no of Shares

Amount of money that a holder of a common share would get if a company were to liquidate

P/E Ratio

The following should be considered while doing P/E Ratio Analysis

For Value Investment

  1. P/E ratio should be low for Value share and should have been consistent in the past
  2. The Dividend Yield would be More
  3. The Cash Flow Statement would be consistent

Outstanding – Outstanding shares are shown on a company balance sheet as Capital Stock.A companys stock currently held by all its shareholders, share blocks by institutional investors and restricted shares owned by the company

Market capitalization is calculated by multiplying a company’s shares outstanding by the current market price of one share

outstanding shares is not static, may fluctuate. Outstanding shares will decrease if the company buys back its shares under a share repurchase program.outstanding shares will increase if it issues additional shares.

The number of shares outstanding will double if a company undertakes a 2-for-1 stock split, or will be halved if it undertakes a 1-for-2 share consolidation.

Institutional Investor
A organization that trades securities in large quantities that they are given preferential treatment and lower commissions. Institutional investors has fewer protective regulations because it is assumed that they are more knowledgeable and better able to protect themselves.

Asset Management Companies like Relianace Asset Management, HDFC Asset Management are some of Institutional Investor.

 =CONCATENATE(B2,".",C2,".",D2)

--Update Script
  =CONCATENATE("UPDATE Location SET Location_Description = '", D2, "'  WHERE  LOCATION_CODE ='", B2,"' AND LOCATION_NAME ='", C2, "'")
 UPDATE Location 
   SET Location_Description = 'Thats where I Live'
 WHERE LOCATION_CODE = '600018'
   AND LOCATION_NAME = 'Teynampet'

DBUtilsTest.java

public class DBUtilsTest
{	
	public void getDBRecordsSQLTest()
	{	
		DBUtils objDBUtils 	 = new DBUtils();
		ResultSet resultSet  = objDBUtils.getDBRecordsSQL("SELECT 78985450.1245487986418648 decimal_val FROM dual");
		
		double expectedValue   = 1245.654618764;
		double dbValue 	 	   = 0; 
		double toleranceLimit  = 0.000000001;
		
		try
		{
			 while(resultSet.next())
			 {
				dbValue =  resultSet.getDouble("decimal_val");
				assertEquals(expectedValue, dbValue, toleranceLimit);
			 }
		} catch (SQLException e)
		{
			e.printStackTrace();
		}
		
		objDBUtils.closeConnection();
	}
	
	@Test
	public void getDBRecordsProcTest()
	{	
		DBUtils objDBUtils 	 = new DBUtils();
		ResultSet resultSet  = objDBUtils.getDBRecordsProc("{call TESTJUNIT.junitproc(?)}");
		
		double expectedValue   = 7.89854501245488E7;
		double dbValue 	 	   = 0; 
		double toleranceLimit  = 0.000000001;
		
		try
		{
			 while(resultSet.next())
			 {
				dbValue =  (double) resultSet.getDouble(1);				
				assertEquals(expectedValue, dbValue, toleranceLimit);
			 }
		} catch (SQLException e)
		{
			e.printStackTrace();
		}
		
		objDBUtils.closeConnection();
	}
}

DBUtils.java

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import oracle.jdbc.OracleTypes;

public class DBUtils
{
	Connection  conn  = null;
    Statement 	stmt  = null;
    ResultSet   rs    = null;
	
	public ResultSet getDBRecordsSQL(String pQuery)
	{    
	    try
	    {
	    	conn = DriverManager.getConnection("hostname", "admin", "admin123");
	        stmt = (Statement)conn.createStatement();
	        rs 	 = stmt.executeQuery(pQuery);
	     	
	    } catch (SQLException e)
		{
			e.printStackTrace();
		}
	    
		return rs;
	}
	
	public ResultSet getDBRecordsProc(String pQuery)
	{	
		CallableStatement stmt  = null; 
		
		try
	    {
	    	conn = DriverManager.getConnection("hostname", "admin", "admin123");	        
	        stmt = conn.prepareCall(pQuery);	        
	        stmt.registerOutParameter(1, OracleTypes.CURSOR);
	        stmt.execute();
	        rs = (ResultSet) stmt.getObject(1);
	    } catch (SQLException e)
		{
			e.printStackTrace();
		}
		
		return rs;
	}
	
	public void closeConnection()
	{
		if (rs  != null) try { rs.close();  } catch (SQLException ignore) {}
        if (stmt  != null) try { stmt.close();  } catch (SQLException ignore) {}
        if (conn != null) try { conn.close(); } catch (SQLException ignore) {}
	}
}

Package creation in Oracle is a TWO step Process.
1.Declaration of Package
2.Definition of Package

Declaration of Package

  CREATE OR REPLACE PACKAGE TEST IS
    PROCEDURE JUNITPROC(C OUT SYS_REFCURSOR);
  END TEST;

Definition of Package

  CREATE OR REPLACE PACKAGE BODY TEST IS
  PROCEDURE JUNITPROC(C OUT SYS_REFCURSOR) IS
  BEGIN  
    OPEN C FOR
      SELECT 78985450.1245487986418648 DECIMAL_VAL FROM DUAL;
  END JUNITPROC;
END TEST;