Wednesday, August 30, 2017

How do i become a good Java Programmer?

1. Have strong foundation and understanding on OOP Principles
 For a Java developer, having strong understanding on Object Oriented Programming is a must. Without having a strong foundation on OOPS, one can't realize the beauty of an Object Oriented Programming language like Java. If you don't have good idea on what OOPS is, even though you are using OOP language you may be still coding in procedural way. Just studying OO principle definitions won't help much. We should know how to apply those OO principles in designing a solution in OO way. So one should have a strong knowledge on Object modeling, Inheritance, Polymorphism, Design Patterns.
2. Master the core APIs
 It doesn't matter how strong you are in terms of theoretical knowledge if you don't know the language constructs and core APIs. In case of Java, one should have very strong hands-on experience with core APIs like java.lang.*, I/O, Exceptions, Collections, Generics, Threads, JDBC etc. When it comes to Web application development, no matter which framework you are using having strong knowledge on Servlets, JSPs is a must.
3. Keep coding
 Things look simpler when talking about them theoretically. We can give a solution to a problem very easily in theory. But we can realize the depth of the problem when we start implementing our approach. You will come to know the language limitations, or design best practices while coding. So keep coding.
4. Subscribe to forums 
 We are not alone. There are lots of people working on the same technologies that we are working on. While doing a simple proof of concept on a framework may not give you real challenges, when you start using it on real projects you will face weird issues and you won't find any solution in their official documentation. When starting to work on a new technology the best and first thing to do is subscribe to the relevant technology forums. Whatever the issue you are facing, someone else in the world might have already faced it earlier and might have found the solution. And it would be really really great if you can answer the questions asked by other forum users.
5. Follow blogs and respond
 As I already told you are not alone. There are thousands of enthusiastic technology freaks around the world blogging their insights on technology. You can see different perspectives of same technology on blogs. Someone can find great features in a technology and someone else feels its a stupid framework giving his own reasons of why he felt like that. So you can see both good and bad of a technology on blogs. Follow the good blogs and respond/comment on posts with your opinion on that.
6. Read open source frameworks source code
 A good developer will learn how to use a framework. But if you want to be an outstanding developer you should study the source code of various successful, popular frameworks where you can see the internal working mechanism of the framework and lot of best practices. It will help a lot in using the frameworks in very effective way.
7. Know the technology trends
 In the open source software development technology trends keep on changing. By the time you get good idea on a framework that might become obsolete and some brand new framework came into picture with super-set of features. The problem which you are trying to solve with your current framework may be already solved by the new framework with a single line of configuration. So keep an eye on whats coming in and whats going out.
8. Keep commonly used code snippets/utilities handy
 Overtime you may need to write/copy-paste same piece of code/configuration again and again. Keeping those kind of configuration snippets like log4.properties, jdbc configuration etc and utilities like StringUtils, ReflectionUtils, DBUtils will be more helpful. I know it itself won't make you outstanding developer. But just imagine some co-developer asks you to help in fetching the list of values of a property from a collection of objects and then you just used your ReflectionUtil and gave the solution in few minutes. That will make you outstanding.
9. Know different development methodologies
 Be familiar with various kinds of methodologies like Agile, SCRUM, XP, Waterfall etc. Nowadays choosing the development methodology depends on the client. Some clients prefer Agile and some clients are happy with waterfall model. So having an idea on various methodologies would be great.
10. Document/blog your thoughts on technology
 In day to day job you may learn new things, new and better way of doing things, best practices, architectural ideas. Keep documenting those thoughts or blog it and share across the community. Imagine you solved a weird problem occurred while doing a simple POC and you blogged about it. May be some developer elsewhere in the world is facing the same issue on a production deployed application. Think how important that solution for that developer. So blog your thoughts, they might be helpful for others or to yourself.


NOTE:- Don't focus on a particular language especially when you are yet to get a steady job or any core area of specialization.


Monday, August 21, 2017

Simple linear regression analysis "Java Code Snippet"

Simple linear regression analysis calculator : - the code below shows the modeling of the relationship between a response variable and an explanatory variable (dependent and independent variable respectively) in one of the most widely use of statistical techniques referred to as “Regression Analysis”. 
This regression model allows “you” to explore what happens to the response variable for specified changes in explanatory variable.
It aims at aims finding the line of best fit through a 2 - dimensional plane of paired x and y variables, finding the error of estimation, Pearsons’ coefficient of correlation and also, finding the (a) regression line using y = a + bx with it corresponding scatter plot.
 A regression (linear) has two parameters which are the slope and the intercept. Once the estimates of both parameters are known using the program, current application, the predicted value (y) will be generated.

----------------------------------------------------------------------

Copy, Save on your preferred storage device... Note, the class name is LRegression, so all you have to do is "change to your current directory" then Run...

If you saved on "c:\users\document"--- all you have to do is change ur current directory in your cmd prompt to "c:\users\document" then "java LRegression Values of x each separated by a space FOLLOWED by Vales of y.


Example---- if your x values are 12, 23, 45, 6 and your y values are 23, 32.41,12----- all you have to do after changing to your current directory is ~> java LRegression 12 23 45 6 23 32 41 12. 


In case of any error (Exception), fear not, its taken care of.... you would get an\ user friendly error message.

-------------------------------------------------------------------------------------------------
/*
Simple Linear Regression calculator
Program written by Doubra Clement Ebijuoworih
*/
     import java.util.Scanner;
     import static java.lang.System.out;
     import javax.swing.JOptionPane;

                  class LRegression

                  {
                        // n counts for entry values (x and y)
                        static int n = 0;

                         // initialization and declaration of the summatioon of x and y values..

                            static double sumOfx = 0.0;
                            static double sumOfy = 0.0;

                          ///000  UserInput.. i.e.trying to get the sum of x and sum of y...


                           public static void main(String [] args)

                           {            
                                        double[] x = new double[args.length];
   double[] y = new double[args.length];

  // checking for NaN

for (int i = 0; i <args.length; i++)
{
try
                                  {   
                                  double change = Double.parseDouble(args[i]);
               if (change == Double.NaN)
                   {}
  }
                catch (Exception e) 
                  {System.out.println("\n\nVALUES OTHER THAN INTEGER OR  DOUBLE HAVE BEEN ENTERED");
                                                           System.exit(1);
 }};
                                       // making sure more than 1 value is input into the system

                                           if (args.length < 3)

                                           {
                       System.out.println("\n\n        REQUIRED INPUT SHOULD BE MORE THAN 1 FOR BOTH X & Y");
                                                         System.exit(1);
                                  }

                                //  checking if x input == y input

                          if ((args.length % 2) != 0)
                          {
                               out.println("\n  **ERROR** Corresponding 'y' values not found  for every                          x' values or     vice versa.....");
                               out.println("\n  **Enter Your 'X' and 'Y' values again; Using the previous                                format.........");
                          }
                            else
                                 {
                                   n = args.length / 2 ;

                                         for (int count = 0; count <= args.length - 1; count++)

                                           {
                                if (count >= n)
                                                        {
                                    // y input and functions...
                                                  y[count] = Double.parseDouble(args[count]);
                                                   sumOfy += y[count];   // getting the summation of y

                                                                  continue;

                                                        } 
                                                       else {;}
                                          x[count] = Double.parseDouble(args[count]);
                                                   sumOfx += x[count];
                                              }
                                 //000
                                         // 111
                                          // Getting the summation of xy i.e. (Exy)

                                double [] x_ = new double[args.length];

                                double [] y_ = new double[args.length];
                                double SumOfXY = 0.0;
                                double SumOfxSquare = 0.0;
                                double SumOfySquare = 0.0;
                                double slope = 0.0;
                                double xMean = 0.0;
                                double yMean = 0.0;
                                double intercept = 0.0;
                                double leastSquare = 0.0 ;
                                double pearsonsCofC = 0.0;

                                for (int xycounter =0; xycounter <=args.length -1; xycounter++)

                                          {     //opening 44
                                                if (xycounter == n)
                                                   break;
                                    x_ [xycounter] = Double.parseDouble(args[xycounter]);
                                          SumOfxSquare += (x_[xycounter] * x_[xycounter]);
                                    y_ [xycounter] = Double.parseDouble(args[xycounter+n]);
                                          SumOfySquare += (y_[xycounter] * y_[xycounter]);
                                SumOfXY += (x_[xycounter] * y_[xycounter]);

                              }    // closing 44 

                                                 // 111
                                            /// 222  Calculating "b" = SLOPE of the line...

             slope =  ((n * SumOfXY)  - (sumOfx * sumOfy)) / ((n * SumOfxSquare) -(sumOfx *                  sumOfx));


                                                /// Calculating "a" = intercept...

                                           xMean = sumOfx / n ;
                                           yMean = sumOfy / n ;
                                           intercept = yMean - (slope * xMean);

                                            /////// Calculating the least Square...

       leastSquare = Math.sqrt(((intercept * SumOfySquare) - (slope * SumOfXY) - (n * (yMean * yMean))) / ( SumOfySquare - (n * (yMean * yMean))));

                                               // if (leastSquare == (double)NaN)

                                               // { leastSquare = 0.00; }
                                            /////// Calculating the pearsons CofC

       pearsonsCofC = (SumOfXY - (n * (xMean * yMean))) / Math.sqrt((SumOfySquare - (n * (yMean * yMean))) * (SumOfxSquare - (n * (xMean * xMean))));


                           ///// *****************working with JFrames & console***************


                          out.println("\n    For the given values of x and y,\n");


                                                   //** Drawing the table**//

                               out.println("       ---------------------------"); 
                    out.printf("       %s %15s", "Values of x" ," Values of y\n");
                               out.println("       ---------------------------");

                           for (int draw = 0; draw < n; draw++)

                               {
                                double xdouble = 0.0;
                                double ydouble = 0.0;

                                xdouble = Double.parseDouble(args[draw]);

                                ydouble = Double.parseDouble(args[draw+n]);

                              out.printf("      %9s %s %7s" , xdouble ,"    |" , ydouble);

                                                     out.println();

                                  }

                                  out.println("       ---------------------------");
                                  out.printf("      %9s%14s" , sumOfx, sumOfy);
                                  out.println();
                                  out.println("       ---------------------------");
            out.printf("\n  %s%.2f %10s%.2f" , "mean of x = " , xMean ,";  mean of y = ", yMean);
                                  out.println();

                                                  //** end of table...**//

                                     //  out.printf("\n  %s " , " ::

      out.printf("\n  %s%.2f%s%.2f%s\n" , "The regression line :: y = ", intercept, " + ",  slope, "(x)");

       out.printf("\n  %s %.2f\n" , "The LeastSquare :: r = ", leastSquare);
       out.printf("\n  %s %.2f \n" , "The Pearsons Coefficient of Correlation :: r = ", pearsonsCofC);

      // JOptionPane.showMessageDialog(null, "The regression line :-  Y = " + (int)intercept +" + "+ //(int)slope +"(x)"+ "\n\nThe LeastSquare :-  r = " +(int)leastSquare + "\n\nThe Pearsons //Coefficient of Correlation :-  r = " + (int)pearsonsCofC);

                                            ///222
                          }}}