Pageviews

Friday, December 12, 2014

Lessons learnt from Stock Market

Everyone at some point thought about it, but it is hard to generate the second income when your first income takes most of your time and energy.  I always thought of increasing my first income as much as possible, so that I do not need to look for the second source of income. This strategy worked out pretty well for sometime. But then something changed, it is either because I felt that I have hit a saturation level in my first income (at least in the current job), or I just need to look out for something that closely aligns with my passion and goals. For a minute, I thought I wanted to be a writer and be an author of a book. Sounds crazy to you?, it should because it is a crazy idea. It took me two months to write one page of text. So I decided, I am not going to be financially independent by writing books. I did not quit writing, but moved on to something else. Mainly because I realized this cannot be my medium to attain financial independence.

The thought of having a second income became stronger as year passed. I am not worried about failure, I just need a good investment idea as a second option. When the second option start to generate money, then it is a bliss. It does not mean it has to be a huge amount. Even few dollars a month will do. That will keep my hope and dreams alive and going.


I really did not had any hobby or a side project. At Least that’s what I thought about myself. But on close evaluation of my activity, I realized that I have been in the stock market on and off for a long time. It is more off than on, but still I was in the stock market from year 2002. I have traded handful of stocks for few years, hoping and praying that it will go up. After ten years, I realized that the strategy of hoping and praying does not work.  I have to admit that during the first ten years, I lost couple of thousand dollars to the market. There is a reason why some stocks are cheap and will remain cheap for ever. This lead to my first golden rule , Rule 1 - Do not buy cheap stocks.


Starting year 2012, my strategy is to buy undervalued stocks.  The timing worked out well, I had few  good stocks in mind, but unfortunately I did not had enough money to invest in all the stocks. I do not want to diversify my stock portfolio. Diversification guarantees a good average result, but not great result. I did not diversify my portfolio because it gives average result, but because i do not want to be average. I did my research and invested in couple of most undervalued stocks.I doubled in my major investment, and made decent return on other stocks.. Part of me was happy, but somewhere I am not satisfied. Mainly because it was not my intelligence that made money this time. It is more of my timing to enter the stock market than anything else. Nevertheless I need to add this lesson to my golden rule, Rule 2 - Look for undervalued(not cheap) stocks.

In the start of 2014, I reevaluated my stocks and my performance, and I reevaluated my dissatisfaction over the wait period for the market to realize the full potential/value  of the undervalued stocks. Then I realized my frustration was due to the wait period.  That is, when i am invested on a stock, the wait period locked the money for an indefinite period of time. It feels like you are taking a huge risk with the hope that it will go up someday without getting back any returns during that time. It really felt miserable at times.  Moreover, most company strategy is futuristic on paper, but without any will power to back that up. Their planning strategy reflect pretty much the same with their future financial guidance as well. It is very difficult to evaluate the worthiness of a company that does not share their profit to the investor. You can fake an idea, but not profit that they have to pay off to investors as dividend. Most companies are only interested in throwing ideas to get public attention and their corporate bonus, but little focus on implementing those ideas and see it come to life. Most MNC companies are focused on acquiring other companies instead of organically growing up their market share. This gave way to the third golden rule, Rule 3 - Invest only in undervalued stocks that pays dividends regularly. 

Due to the third rule, I rearranged my stock investment in such a way that I invested in undervalued stocks which will pay me quarterly or monthly dividends on a regular basis. This made my portfolio look even attractive. Suddenly I started to have a real second income. What started as few dollars every month, changed to few hundred dollars every month, and it feels great. The dividend money is used to repurchase other undervalued stocks. It was my decision not to reinvest the dividend on the same company. The reason is , stock investment should be a calculated and educated pick, and not an automated process.  This makes up the fourth golden rule - Rule 4 - Reinvest your dividend money.



Buying and selling stocks could be fun, but do not forget that you are playing with your life’s savings. Be responsible when doing so. Lets not forget that you are paying a commission fees to the agent through which you are running all these transactions. It adds up to a lot of money when you add them up over a period of time, but that’s not the main problem. What you need is more focus, and not distractions.  Few focused and targeted trades can get you the desired result. You don't need hundreds of trades to get your focus. An investor focus on stable and long term growth potential, and a trader focus on short term growth potential of his investment. This gives away the fifth golden rule. Rule  5 - Be an investor, and not a trader.


After becoming an investor or a trader, it is important to understand how to allocate the excess cash, or when to get out of a stock when the underlying situation changes. It can either be because the stock you owned become overvalued at this time, or the company is going through a management crisis. When the time comes to sell and reallocate the money, you need to know how effectively and efficiently you can put your money to work. A good amount of research about the company, management and finance, plus your gut instinct driven by your logical mind should be trained to allocate the excess capital in reinvesting the money for the long term. This gives way to the final rule. Rule 6 - Learn & master the skill to allocate capital. 

Last, but not the least rule - Have fun, and enjoy the game of investing.


Rule 1: Do not look for cheap stocks.
Rule 2: Look for undervalued stocks.
Rule 3: Invest in undervalued stocks that pays dividend regularly.
Rule 4: Reinvest your dividend money.
Rule 5: Be an investor, and not a trader.
Rule 6: Learn and master the skill to allocate capital.
Rule 7: Have fun, and enjoy investing !






Monday, November 24, 2014

Tips on ADF page refresh, UI Component refresh and file download



Tip 1: Method to programmatically refresh ADF page      

This is not always recommended, but in case you need to refresh the entire view then use the below managed bean method to refresh the page programmatically.
 


Managed bean layer:

    public void refresh() {
           FacesContext facesContext = FacesContext.getCurrentInstance();
           String refreshpage = facesContext.getViewRoot().getViewId();
           ViewHandler  viewHandler =facesContext.getApplication().getViewHandler();
           UIViewRoot viewroot =  viewHandler.createView( facesContext, refreshpage);
           viewroot.setViewId(refreshpage);
           facesContext.setViewRoot(viewroot);
     }





Tip 2: Force a refresh on a UI component.

Example 1:
This examples dynamically sets the disable flag property to true/false during run time.

View layer:

                <af:button text="Download" partialSubmit="true" id="b2"
                           disabled="true" binding="#{viewScope.datasource.downloadButton}">

Managed Bean layer:


    private RichButton downloadButton;

 AdfFacesContext.getCurrentInstance().addPartialTarget(downloadButton);




Example 2:

This example refresh the table component when ever the data is refreshed with new set of values.

Managed Bean Layer:

 private RichTable issueTable;

AdfFacesContext.getCurrentInstance().addPartialTarget(issueTable);


Tip 3:  ADF file download

View Layer:

              <af:fileDownloadActionListener 
                                        contentType="text/csv; charset=utf-8"
                                             filename="#{viewScope.datasource.fileName}"
                                             method="#{viewScope.datasource.downloadAction}"/>


Managed bean Layer:
    private String fileName;

    public void downloadAction(FacesContext facesContext, OutputStream outputStream) throws IOException, Exception {
//  Write java code to read and download the file.

}



Monday, January 13, 2014

ADF Security Framework - Create Login/Logout using ADF security framework

ADF Security Framework - Create Login/Logout using ADF security framework



Step 1: Right click on ADF application, select Secure -> Configure ADF Security





Step 2: Select the ADF security model based on your application need. For this example, I have selected ADF Authentication and Authorization option.




Step 3: Next step is to choose the authentication type. I have selected the Form-Based Authentication for this example. Please make sure to select the checkbox to enable the ADF framework to generate default pages for login and error page.




Step 4:  Select No Automatic Grants option in order to secure the application. By doing so, all the pages within our application will be inaccessible until we explicitly grant access to them.




Step 5: Enable redirect checkbox option, and select the page that you want the login page to redirect  after a successful authentication.




Step 6: The summary section lists all the files that will be created/modified when you click the finish button. The details are as follows..

adf-config.xml - This file defines the JAAS(Java Authentication and Authorization Service) security context. This enables the use of ADF authentication servlet and Authorization checking.

web.xml - Sets the authentication type for your web project.

weblogic.xml - Maps security role to the OPSS principal users.

jazn-data.xml - Sets user and role credentials

jps-config.xml - Defines OPSS context and references jazn-data.xml as service provider.




Step 7: Add application roles. This updates jazn-data.xml file. Check out the below screenshot for details.




Step 8:  Add application users. This updates jazn-data.xml file. Check out the below screenshot for details.



Step 9: In resource grants, select Web Page resource type, then select the resource, and grant access to the newly created role. By giving access to the role, the users associated to the role gets the access to view the selected resource.



Step 10: Run the application, and check out the secure authentication and authorization functionality provided by ADF security framework.

ADF security framework Logout:




Check out the video below for the demo.






Click download to get the source code.

Saturday, December 28, 2013

Build ADF Hierarchy Viewer Component using custom built java data control.


Step 1:  Create a custom java object to hold the tree node object. I called it as TreeItem in my example.





Step 2: Create a custom java control to load the dummy data. Check out the HRTreeData java class for details.




Step 3:  Open adfc-config.xml, then add a view to the unbounded task flow. Create the view by double clicking the view control. Lets call the view as HViewer.jsf for now.




Step 4: Add HRTreeData as a managed bean resource to adfc-config, so that the custom java class is accessible from the view.



Step 5: Open the view in design mode, drag and drop Hierarchy Viewer component by selecting  ADF Data Visualization option in Component palette window.



Step 6: Add the images required to populate the Hierarchy Viewer component, and then right click on the view and run the application.







Enjoy and have fun!.



Check out the below video for demo.







Click download to get the source code.








Saturday, August 10, 2013

ADF - MYSQL JDBC connection issue.

ADF JDBC Error:

java.lang.ClassCastException: com.mysql.jdbc.JDBC4Connection cannot be cast to oracle.jdbc.OracleConnection
    at oracle.jbo.server.OracleSQLBuilderImpl.setSessionTimeZone(OracleSQLBuilderImpl.java:5534)
    at oracle.jbo.server.DBTransactionImpl.refreshConnectionMetadata(DBTransactionImpl.java:5329)
    at oracle.jbo.server.DBTransactionImpl.initTransaction(DBTransactionImpl.java:1167)
    at oracle.jbo.server.DBTransactionImpl.initTxn(DBTransactionImpl.java:6838)
    at oracle.jbo.server.DBTransactionImpl2.connectToDataSource(DBTransactionImpl2.java:298)
    at oracle.jbo.server.DBTransactionImpl2.connectToDataSource(DBTransactionImpl2.java:329)
    at oracle.jbo.common.ampool.DefaultConnectionStrategy.connect(DefaultConnectionStrategy.java:203)
    at oracle.jbo.server.ApplicationPoolMessageHandler.doPoolConnect(ApplicationPoolMessageHandler.java:600)
    at oracle.jbo.server.ApplicationPoolMessageHandler.doPoolMessage(ApplicationPoolMessageHandler.java:417)
    at oracle.jbo.server.ApplicationModuleImpl.doPoolMessage(ApplicationModuleImpl.java:9053)
    at oracle.jbo.common.ampool.ApplicationPoolImpl.sendPoolMessage(ApplicationPoolImpl.java:4606)
    at oracle.jbo.common.ampool.ApplicationPoolImpl.prepareApplicationModule(ApplicationPoolImpl.java:2536)
    at oracle.jbo.common.ampool.ApplicationPoolImpl.doCheckout(ApplicationPoolImpl.java:2346)
    at oracle.jbo.common.ampool.ApplicationPoolImpl.useApplicationModule(ApplicationPoolImpl.java:3245)
    at oracle.jbo.common.ampool.SessionCookieImpl.useApplicationModule(SessionCookieImpl.java:571)
    at oracle.jbo.common.ampool.SessionCookieImpl.useApplicationModule(SessionCookieImpl.java:504)
    at oracle.jbo.common.ampool.SessionCookieImpl.useApplicationModule(SessionCookieImpl.java:499)
    at oracle.adf.model.bc4j.DCJboDataControl.initializeApplicationModule(DCJboDataControl.java:517)
    at oracle.adf.model.bc4j.DCJboDataControl.getApplicationModule(DCJboDataControl.java:867)
    at oracle.jbo.jbotester.binding.TesterBinding.getConnectionInfo(TesterBinding.java:222)
    at oracle.jbo.jbotester.MainFrame.initializeDataControl(MainFrame.java:945)
    at oracle.jbo.jbotester.MainFrame.loadConfiguration(MainFrame.java:646)
    at oracle.jbo.jbotester.MainFrame.processArgs(MainFrame.java:612)
    at oracle.jbo.jbotester.MainFrame.main(MainFrame.java:446)

Solution:


To resolve this issue, select the SQL Platform to SQL92 when creating the entity objects and associations. SQL92 is the SQL standard platform to connect to MySQL database.  The default selection of Oracle should be used when connecting to Oracle Database.

Please note:  This is a one time setup. This option will not be available to view or modify after the selection is made. Check out the below screenshot for details.





Enjoy and have fun !

Sunday, July 28, 2013

ADF Train Component


ADF Train Component


The train component represents a series of train stops, each stop representing a step in a multi-step process. Each stop is tied to a view (.jsf page). Each page can either interact or display information that will help the user to complete the multi-step process. The train component helps the user to walk through these steps one stop at a time. User will be able to navigate to next stop or the previous stop in order to take corrective action to complete the multi-step process.  The train component can be rendered in a vertical layout as well as in horizontal layout, default being a horizontal layout.  The train component walks through the user in a predefined order as defined in the train model. Each train step is rendered with an image and a textual link indicating if they are in visited, current stop, unvisited stop and disabled state. 

Check out the below demo video explaining , bounded task flow, unbounded task flow, train model, train button bar, task flow control, method call activity etc.,  Persisting the user information collected in each train stop to a database table is not intended to be covered in this demo.  This is a basic demo to explain the above mentioned concepts. Hope it is helpful.


 



Saturday, July 27, 2013

JDeveloper - MySQL DB connection setup


JDeveloper - MySQL DB connection setup


JDeveloper connection to MySQL database is not straight forward, and certainly does not work with out of the box drivers. Check out the below screen shot for details. You need to download and add, Connector/J driver to establish the connection. MySQL Connector/J is the official JDBC driver for MySQL.

Follow the below instructions to download and configure, Connector/J driver.

Here is my connection details,

Connection In: Application Resources (selected by default)
Connection Name: dbConn
Connection Type: MySQL
Username : root

Under MySQL Settings:

Host Name: <Enter your hostname, in my case it is, localhost>
Port: Enter the default MySQL DB port number, 3306
Driver Class: com.mysql.jdbc.Driver (Default)
Library: <Press Browse to select a library>




The problem here is, MySQL connection library is not available by default to establish the MySQL DB connection. 
To resolve this issue, follow the below steps..

Step 1: 

To get the driver, navigate to the following link and download the jar file.


The above link takes you to the main download Connector/J driver location. From here, you have a choice to download as a compressed tar archive file or a zip archive format.

The above link2 takes you directly to download the Connector/J driver directly in zip archive format.

Step 2: 


Place the downloaded jar file under  a domain lib folder location. In my case, I placed the jar file in

Macintosh HD/Users/RajVenugopal/Oracle/Middleware/user_projects/applications/DefaultDomain/lib/mysql-jdbc-5.1.25

Quick Note: I renamed mysql-connector-java-5.1.25,zip to mysql-jdbc-5.1.25.zip. Unzipping the folder gets you the needed driver jar file.



Step 3:


In 'Create Database Connection' wizard, click the library browse button to open up "Select Library" window. Select User selection under Libraries. Click the "New" button to open the 'Create Library' window. Then click 'Add Entry' button to add the downloaded jar file to the library. Check out the below screenshot for details.








Step 4: 

Add the download jar file to the user libraries, and then select 'Test Connection' to test the DB connection. You should get a successful db connection at this point.



Enjoy and have fun.