Sunday, February 25, 2018

String of Java

  • String  is immutable in Java. An immutable class is simply a class whose instances cannot be modified. All information in an instance is initialized when the instance is created and the information can not be modified. In  fact none  of methods defined in the String class modify  the object's own value . They all create new String objects.
                            ex :-    String   newString  =  "Game" ;
                                       newString.replace('a', 'A');
                                       System.out.println(newString) ; // Will print Game  
 
                 Due to strings  are immutable  we  can achieve
    • Security             - String is widely used as a parameter for many java classes, e.g. network connection, opening files, etc. Were String not immutable, a connection or file would be changed and this can lead to a serious security threat. The method thought it was connecting to one machine, but was not. Mutable strings could cause a security problem in Reflection too, as the parameters are strings.
    • Safe in threads   - immutable objects can not be changed, they can be shared among multiple threads freely.
           
  •  String Pool  -  When  string  is  created  and  if  the  string already existing in the  pool  without  using  key  word  new  ,then reference of  existing  string will  be  return , instead of  creating  new object.  
    ex :-   String  newStingOne =  "ABAC" ;
              String  newStingTwo =  "ABAC" ;  
    Above code will create only one string object in the heap.

  • If a string is going to remain constant throughout the program, then use String class object because a String object is immutable.                                                                                                                                                                     You should use StringBuilder class when we  have larger strings or modifying the  contents of a string  often .Doing that will  increase   performance.If a string can change (example: lots of logic and operations in the construction of the string) and will only be accessed from a single thread, using a StringBuilder is good enough.                                 If a string can change, and will be accessed from multiple threads, use a StringBuffer because StringBuffer is synchronous so you have thread-safety.
  • Class StringBuffer  provides  same functionality  StringBuilder  provides  minus the additional feature of synchronized methods





    References Used  :-  why-string-is-immutable-in-java
                                 :-   OCA Java SE 8  Programer  1 Guide  by   Mala Gupta

Monday, February 12, 2018

Why Your Attitude Is More Important Than Your IQ Extracted from Linkdin


Why Your Attitude Is More Important Than Your IQ


When it comes to success, it’s easy to think that people blessed with brains are inevitably going to leave the rest of us in the dust. But new research from Stanford University will change your mind (and your attitude).
Psychologist Carol Dweck has spent her entire career studying attitude and performance, and her latest study shows that your attitude is a better predictor of your success than your IQ.
Dweck found that people’s core attitudes fall into one of two categories: a fixed mindset or a growth mindset.
With a fixed mindset, you believe you are who you are and you cannot change. This creates problems when you’re challenged because anything that appears to be more than you can handle is bound to make you feel hopeless and overwhelmed.
People with a growth mindset believe that they can improve with effort. They outperform those with a fixed mindset, even when they have a lower IQ, because they embrace challenges, treating them as opportunities to learn something new.

Common sense would suggest that having ability, like being smart, inspires confidence. It does, but only while the going is easy. The deciding factor in life is how you handle setbacks and challenges. People with a growth mindset welcome setbacks with open arms.
According to Dweck, success in life is all about how you deal with failure. She describes the approach to failure of people with the growth mindset this way,
“Failure is information—we label it failure, but it’s more like, ‘This didn’t work, and I’m a problem solver, so I’ll try something else.’”
Regardless of which side of the chart you fall on, you can make changes and develop a growth mindset. What follows are some strategies that will fine-tune your mindset and help you make certain it’s as growth oriented as possible.
Don’t stay helpless. We all hit moments when we feel helpless. The test is how we react to that feeling. We can either learn from it and move forward or let it drag us down. There are countless successful people who would have never made it if they had succumbed to feelings of helplessness: Walt Disney was fired from the Kansas City Star because he “lacked imagination and had no good ideas,” Oprah Winfrey was fired from her job as a TV anchor in Baltimore for being “too emotionally invested in her stories,” Henry Ford had two failed car companies prior to succeeding with Ford, and Steven Spielberg was rejected by USC’s Cinematic Arts School multiple times. Imagine what would have happened if any of these people had a fixed mindset. They would have succumbed to the rejection and given up hope. People with a growth mindset don’t feel helpless because they know that in order to be successful, you need to be willing to fail hard and then bounce right back.
Be passionate. Empowered people pursue their passions relentlessly. There’s always going to be someone who’s more naturally talented than you are, but what you lack in talent, you can make up for in passion. Empowered people’s passion is what drives their unrelenting pursuit of excellence. Warren Buffet recommends finding your truest passions using, what he calls, the 5/25 technique: Write down the 25 things that you care about the most. Then, cross out the bottom 20. The remaining 5 are your true passions. Everything else is merely a distraction.
Take action. It’s not that people with a growth mindset are able to overcome their fears because they are braver than the rest of us; it’s just that they know fear and anxiety are paralyzing emotions and that the best way to overcome this paralysis is to take action. People with a growth mindset are empowered, and empowered people know that there’s no such thing as a truly perfect moment to move forward. So why wait for one? Taking action turns all your worry and concern about failure into positive, focused energy.
Then go the extra mile (or two). Empowered people give it their all, even on their worst days. They’re always pushing themselves to go the extra mile. One of Bruce Lee’s pupils ran three miles every day with him. One day, they were about to hit the three-mile mark when Bruce said, “Let’s do two more.” His pupil was tired and said, “I’ll die if I run two more.” Bruce’s response? “Then do it.” His pupil became so angry that he finished the full five miles. Exhausted and furious, he confronted Bruce about his comment, and Bruce explained it this way: “Quit and you might as well be dead. If you always put limits on what you can do, physical or anything else, it’ll spread over into the rest of your life. It’ll spread into your work, into your morality, into your entire being. There are no limits. There are plateaus, but you must not stay there; you must go beyond them. If it kills you, it kills you. A man must constantly exceed his level.”
If you aren’t getting a little bit better each day, then you’re most likely getting a little worse—and what kind of life is that?
Expect results. People with a growth mindset know that they’re going to fail from time to time, but they never let that keep them from expecting results. Expecting results keeps you motivated and feeds the cycle of empowerment. After all, if you don’t think you’re going to succeed, then why bother?
Be flexible. Everyone encounters unanticipated adversity. People with an empowered, growth-oriented mindset embrace adversity as a means for improvement, as opposed to something that holds them back. When an unexpected situation challenges an empowered person, they flex until they get results.
Don't complain when things don't go your way. Complaining is an obvious sign of a fixed mindset. A growth mindset looks for opportunity in everything, so there’s no room for complaints.

Bringing It All Together

By keeping track of how you respond to the little things, you can work every day to keep yourself on the right side of the chart above.
Do you have a growth mindset? Please share your thoughts in the comments section below as I learn just as much from you as you do from me.

ABOUT THE AUTHOR:

Dr. Travis Bradberry is the award-winning co-author of the #1 bestselling book, Emotional Intelligence 2.0, and the cofounder of TalentSmart, the world's leading provider of emotional intelligence tests and training, serving more than 75% of Fortune 500 companies. His bestselling books have been translated into 25 languages and are available in more than 150 countries. Dr. Bradberry has written for, or been covered by, Newsweek, TIME, BusinessWeek, Fortune, Forbes, Fast Company, Inc., USA Today, The Wall Street Journal, The Washington Post, and The Harvard Business Review.

If you'd like to learn how to increase your emotional intelligence (EQ), consider taking the online Emotional Intelligence Appraisal® test that's included with the Emotional Intelligence 2.0 book. Your test results will pinpoint which of the book's 66 emotional intelligence strategies will increase your EQ the most.

Saturday, January 27, 2018

Spring MVC Framework and REST

Understanding REST

Since Spring Framework is the most popular and the standard framework for developing Java web application and RESTful Web Services.

While the traditional MVC controller relies on the View technology, the RESTful web service controller simply returns the object and the object data is written directly to the HTTP response as JSON/XML.
REST (Representational State Transfer) was introduced and defined in 2000 by Roy . REST is an architectural style for designing distributed systems. It is not a standard but a set of constraints, such as being stateless, having a client/server relationship, and a uniform interface. REST is not strictly related to HTTP, but it is most commonly associated with it

Principles of REST

  • Resources expose easily understood directory structure URIs.
  • Representations transfer JSON or XML to represent data objects and attributes.
  • Messages use HTTP methods explicitly (for example, GET, POST, PUT, and DELETE).
  • Stateless interactions store no client context on the server between requests. State dependencies limit and restrict scalability. The client holds session state.

HTTP methods

Use HTTP methods to map CRUD (create, retrieve, update, delete) operations to HTTP requests.

  • GET     -    @RequestingMapping (method =  RequestMethod.GET)         or     @RequestingMapping ("/topics")
  • POST   -    @RequestingMapping (method =  RequestMethod.POST   ,  value = "/topics")
  • PUT     -    @RequestingMapping (method =  RequestMethod.PUT)
  • DELETE  -    @RequestingMapping (method =  RequestMethod.DELETE)
HTTP Verb CRUD Entire Collection (e.g. /customers) Specific Item (e.g. /customers/{id})
POST Create 201 (Created), 'Location' header with link to /customers/{id} containing new ID. 404 (Not Found), 409 (Conflict) if resource already exists..
GET Read 200 (OK), list of customers. Use pagination, sorting and filtering to navigate big lists. 200 (OK), single customer. 404 (Not Found), if ID not found or invalid.
PUT Update/Replace 405 (Method Not Allowed), unless you want to update/replace every resource in the entire collection. 200 (OK) or 204 (No Content). 404 (Not Found), if ID not found or invalid.
PATCH Update/Modify 405 (Method Not Allowed), unless you want to modify the collection itself. 200 (OK) or 204 (No Content). 404 (Not Found), if ID not found or invalid.
DELETE Delete 405 (Method Not Allowed), unless you want to delete the whole collection—not often desirable. 200 (OK). 404 (Not Found), if ID not found or invalid.

HTTP status codes

Status codes indicate the result of the HTTP request.
  • 1XX - informational
  • 2XX - success
  • 3XX - redirection
  • 4XX - client error
  • 5XX - server error

Using the @ResponseBody Annotation

When you use the @ResponseBody annotation on a method, Spring converts the return value and writes it to the http response automatically. Each method in the Controller class must be annotated with @ResponseBody.

Behind the Scenes

Spring has a list of HttpMessageConverters registered in the background. The responsibility of the HTTPMessageConverter is to convert the request body to a specific class and back to the response body again, depending on a predefined mime type. Every time an issued request hits @ResponseBody, Spring loops through all registered HTTPMessageConverters seeking the first that fits the given mime type and class, and then uses it for the actual conversion.

Using the @RestController Annotation

Spring 4.0 introduced @RestController, a specialized version of the controller which is a convenience annotation that does nothing more than add the @Controller and @ResponseBody annotations. By annotating the controller class with @RestController annotation, you no longer need to add @ResponseBody to all the request mapping methods. The @ResponseBody annotation is active by default.


References : –

Wednesday, January 24, 2018

Lessons learnt

# Find strong reason why are we doing something , develop discipline through singular activities. Pre planning for temptation . Use discipline got through doing single tasks well to do other tasks
#  Break down solutions that you goning to give ,check whether are they compatible each other.
#learn how to work fast .Try to understand things that wasted more time.Note down process that taken to early process, and revice why that actions taken.
#Ask yourself before doing anything , what should do to achieve task .break that into small task
#Develop your concentration , meditate.
#Before you talk with your boss , prepare well about what   are you talking about .
#You sholud learn new technologies and sholud apply them ,Best way is starting side project so you can apply what you have learnt.
#Most time answer for your problem is in internet , but you have to dive and find best answer.
#Challenge yourself , do what you are afraid to do.
#Don't depend on single income
#prove them they are wrong to people who said you are good enough.
#It is your duty to add worth to your life.
#We hope for brand new beginning always  ,without trying to make present situation  better. (One day arrived new beginning allso,will be bacome old)
#Learn the rules well.
#Some times there will be no time to do what you want ,after continuing procrastination.
#Its all about keep moving forward and fight back for your goals
#Don't lost your humanity .
#Before looking at chances that not yet came , try to get maximum of current opportunities you got.
#Focus on the process you need to take to achieve goal instead of focusing on goal.
#You should finish ,what you have started.
#Don't wait till motivation comes.It's not going to come ,you have to push hard yourself and be discipline  to your work.
#
This is easy work:
 complaining  pretending   blaming   judging  resenting   
 taking     shouting   expecting      waiting   doubting
This is hard work:
 inspiring  learning   teaching   trusting   empowering
 building   committing   giving   loving   leading"

Monday, January 1, 2018

MySql - Commands


  • create database employee;    
  • show databases;
  • use employee;
  • select database();
  • create table employeeDetailExample
  ( fName varchar(25) NOT NULL,
   lName varchar(25) NOT NULL,
                     state CHAR(2)  NOT NULL  DEFAULT "PA",
                     birth_date DATE NOT NULL ,
                     sex ENUM ('M','F') NOT NULL ,
                     empID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
                     lastWorkedDate TIMESTAMP,
                     money_owed FLOAT NULL
                   );

  •   show tables;
  •   create table employeeDetail
                     (
                   fName varchar(25) NOT NULL,
                   state CHAR(2)  NOT NULL  DEFAULT "PA",
                   sex ENUM ('M','F') NOT NULL ,
                   empID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
                   lastWorkedDate TIMESTAMP
                   );
  •    drop table employeeDetail ;
  •    quit
  •    desc employeeDetail;
  •    INSERT INTO employeeDetail VALUES('ROSHAN','AC','M',NULL,2222333444);
  •    INSERT INTO employeeDetail  VALUES(fName,lName ) values('roshan','sanjeewa');

  Resource Url :- https://www.youtube.com/watch?annotation_id=annotation_103363&feature=iv&src_vid=Em-AhbqVe48&v=9ywkQ9aGhVo

Problems Occured - With Solutions Used

  •  When :- Creating db connection 
    • Error got :- Mon Jan 01 16:39:51 IST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended.According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set.
      For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'.
      You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.    
    • Solution used :-    Connection myConnection  = DriverManager.getConnection(dbUrl+ "?useSSL=false", userName, password);    used instead  of    Connection myConnection  = DriverManager.getConnection(dbUrl, userName, password);
    • Help got from :- https://stackoverflow.com/questions/34189756/warning-about-ssl-connection-when-connecting-to-mysql-database
  • When :- Error while loading class org.springframework.http.server.reactive.ServletServerHttpRequest$RequestAsyncListener   Caused by: java.lang.NoClassDefFoundError:org/springframework/http/server/reactive/ServletServerHttpRequest$RequestBodyPublisher\
    • Solution used :-  Added following dependency 
    • <dependency>
    •    <groupId>org.reactivestreams</groupId>
         <artifactId>reactive-streams</artifactId>
         <version>1.0.1</version>
      </dependency>
  •   When :- Trying to run a .jar file 
  • Problem : - Unable  to  run  jar file 

Sunday, December 31, 2017

Reporting Tool for Spring Projects (Getting data from different databases in one report)

In spring projects , we use different databases for  different services .
There will be requirement to get  data from different databases in  to one report . It is practically not an easy task .

But  in  BIRT (an open source technology platform used to create data visualizations and reports that can be embedded into rich client and web applications) reporting tool can address this  issue easily .

First you have to create new separate Data Source connections for all  databases that you want to use .
Second step is  create separate Data Sets (Query to get data from particular database)  for  each  database that you want to use .

Third step is  create new  Join Data Set  using already created data sets in second step . Through this join data sets , you  can easily get data  from different databases to your report without much effort(you can create many Join Data Sets  as you wish) .

Some interesting things to explore more

 Here  some  some  things  to  study  more ,     How Google Search works               https://developers.google.com/search/docs/fundamental...