Search This Blog

Tuesday, March 4, 2014

Java Strings

The Java String data type can contain a sequence (string) of characters. Strings are how you work with text in Java.
Strings in Java are represented internally using bytes, encoded as UTF-16. UTF-16 uses 2 bytes to represent a single character. UTF is a character encoding that can represent characters in a lot of different languages.
Table of contents:

Creating a String

Strings in Java are objects. Therefore you need to use the new operator to create a new String object. Here is an example:
String myString = new String("Hello World");
The text inside the quotes is the text the String object will contain.
Java has a shorter way of creating a new String:
String myString = "Hello World";
This notation is shorter since it doesn't declare a new String. A new String is created behind the scenes by the Java compiler though.
If you use the same string (e.g. "Hello World") in other String variable declarations, the Java compiler may only create a single String instance a make the various different variables initialized to that constant string point to the same String instance. Here is an example:
String myString1 = "Hello World";
String myString2 = "Hello World";
In this case the Java compiler will make both myString1 and myString2 point to the same String object. If you do not want that, use the new operator, like this:
String myString1 = new String("Hello World");
String myString2 = new String("Hello World");

Concatenating Strings

Concatenating Strings means appending one string to another. Strings in Java are immutable meaning they cannot be changed once created. Therefore, when concatenating two String objects to each other, the result is actually put into a third String object.
Here is a Java String concatenation example:
String one = "Hello";
String two = " World";

String three = one + two;
The content of the String referenced by the variable three will be Hello World; The two other Strings objects are untouched.

String Concatenation Performance

When concatenating Strings you have to watch out for possible performance problems. Concatenating two Strings in Java will be translated by the Java compiler to something like this:
String one = "Hello";
String two = " World";

String three = new StringBuilder(one).append(two).toString();
As you can see, a new StringBuilder is created, passing along the first String to its contructor, and the second String to its append() method, before finally calling the toString() method. This code actually creates two objects: A StringBuilder instance and a new String instance returned from the toString() method.
When executed by itself as a single statement, this extra object creation overhead is insignificant. When executed inside a loop, however, it is a different story.
Here is a loop containing the above type of String concatenation:
String[] strings = new String[]{"one", "two", "three", "four", "five" };

String result = null;
for(String string : strings) {
    result = result + string;
}
This code will be compiled into something similar to this:
String[] strings = new String[]{"one", "two", "three", "four", "five" };

String result = null;
for(String string : strings) {
    result = new StringBuilder(result).append(string).toString();
}
Now, for every iteration in this loop a new StringBuilder is created. Additionally, a temporary String object is created by the toString() method. This results in a small object instantiation overhead per iteration. This is not the real performance killer though.
When the new StringBuilder(result) code is executed, the StringBuilder constructor copies all characters from the result String into the StringBuilder. The more iterations the loop has, the bigger the result String grows. The bigger the result String grows, the longer it takes to copy the characters from it into a new StringBuilder, and again copy the characters from the StringBuilder into the temporary String created by the toString() method. In other words, the more iterations the slower each iteration becomes.
The fastest way of concatenating Strings is to create a StringBuilder once, and reuse the same instance inside the loop. Here is how that looks:
String[] strings = new String[]{"one", "two", "three", "four", "five" };

StringBuilder temp  = new StringBuilder();
for(String string : strings) {
    temp.append(string);
}
String result = temp.toString();
This code avoids both the StringBuilder and String object instantiations inside the loop, and therefore also avoids the two times copying of the characters, first into the StringBuilder and then into a String again.

String Length

You can obtain the length of a String using the length() method. The length of a String is the number of characters the String contains - not the number of bytes used to represent the String. Here is an example:
String string = "Hello World";
int length = string.length();

Substrings

You can extract a part of a String. This is called a substring. You do so using the substring() method of the String class. Here is an example:
String string1 = "Hello World";

String substring = string1.substring(0,5);
After this code is executed the substring variable will contain the string Hello.
The substring() method takes two parameters. The first is the character index of the first character to be included in the substring. The second is the index of the character after the last character to be included in the substring. Remember that. The parameters mean "from - including, to excluding". This can be a little confusing until you memorize it.
The first character in a String has index 0, the second character has index 1 etc. The last character in the string has has the index String.length() - 1.

Searching in Strings

You can search for substrings in Strings using the indexOf() method. Here is an example:
String string1 = "Hello World";

int index = string1.indexOf("World");
The index variable will contain the value 6 after this code is executed. The indexOf() method returns the index of where the first character in the first matching substring is found. In this case the W of the matched substring World was found at index 6.
If the substring is not found within the string, the indexOf() method returns -1;
There is a version of the indexOf() method that takes an index from which the search is to start. That way you can search through a string to find more than one occurrence of a substring. Here is an example:
String theString = "is this good or is this bad?";
String substring = "is";

int index = theString.indexOf(substring);
while(index != -1) {
    System.out.println(index);
    index = theString.indexOf(substring, index + 1);
}
This code searches through the string "is this good or is this bad?" for occurrences of the substring "is". It does so using the indexOf(substring, index) method. The index parameter tells what character index in the String to start the search from. In this example the search is to start 1 character after the index where the previous occurence was found. This makes sure that you do not just keep finding the same occurrence.
The output printed from this code would be:
0
5
16
21
The substring "is" is found in four places. Two times by itself, and two times inside the word "this".
The String class also has a lastIndexOf() method which finds the last occurrence of a substring. Here is an example:
String theString = "is this good or is this bad?";
String substring = "is";

int index = theString.lastIndexOf(substring);
System.out.println(index);
The output printed from this code would be 21 which is the index of the last occurrence of the substring "is".

Comparing Strings

Java Strings also have a set of methods used to compare Strings. These methods are:
  • equals()
  • equalsIgnoreCase()
  • startsWith()
  • endsWith()
  • compareTo()

equals()

The equals() method tests if two Strings are exactly equal to each other. If they are, the equals() method returns true. If not, it returns false. Here is an example:
String one   = "abc";
String two   = "def";
String three = "abc";
String four  = "ABC";

System.out.println( one.equals(two) );
System.out.println( one.equals(three) );
System.out.println( one.equals(four) );
The two strings one and three are equal, but one is not equal to two or to four. The case of the characters must match exactly too, so lowercase characters are not equal to uppercase characters.
The output printed from the code above would be:
false
true
false

equalsIgnoreCase()

The String class also has a method called equalsIgnoreCase() which compares two strings but ignores the case of the characters. Thus, uppercase characters are considered to be equal to their lowercase equivalents.

startsWith() and endsWith()

The startsWith() and endsWith() methods check if the String starts with a certain substring. Here are a few examples:
String one = "This is a good day to code";

System.out.println( one.startsWith("This")    );
System.out.println( one.startsWith("This", 5) );

System.out.println( one.endsWith  ("code")    );
System.out.println( one.endsWith  ("shower")  );
This example creates a String and checks if it starts and ends with various substrings.
The first line (after the String declaration) checks if the String starts with the substring "This". Since it does, the startsWith() method returns true.
The second line checks if the String starts with the substring "This" when starting the comparison from the character with index 5. The result is false, since the character at index 5 is "i".
The third line checks if the String ends with the substring "code". Since it does, the endsWith() method returns true.
The fourth line checks if the String ends with the substring "shower". Since it does not, the endsWith() method returns false.

compareTo()

The compareTo() method compares the String to another String and returns an int telling whether this String is smaller, equal to or larger than the other String. If the String is earlier in sorting order than the other String, compareTo() returns a negative number. If the String is equal in sorting order to the other String, compareTo() returns 0. If the String is after the other String in sorting order, the compareTo() metod returns a positive number.
Here is an example:
String one   = "abc";
String two   = "def";
String three = "abd";

System.out.println( one.compareTo(two)   );
System.out.println( one.compareTo(three) );
This example compares the one String to two other Strings. The output printed from this code would be:
-3
-1
The numbers are negative because the one String is earlier in sorting order than the two other Strings.
The compareTo() method actually belongs to the Comparable interface. This interface is described in more detail in my tutorial about Sorting.
You should be aware that the compareTo() method may not work correctly for Strings in different languages than English. To sort Strings correctly in a specific language, use a Collator.

Getting Characters and Bytes

It is possible to get a character at a certain index in a String using the charAt() method. Here is an example:
String theString = "This is a good day to code";

System.out.println( theString.charAt(0) );
System.out.println( theString.charAt(3) );
This code will print out:
T
s
since these are the characters located at index 0 and 3 in the String.
You can also get the byte representation of the String method using the getBytes() method. Here are two examples:
String theString = "This is a good day to code";

byte[] bytes1 = theString.getBytes();
byte[] bytes2 = theString.getBytes(Charset.forName("UTF-8");
The first getBytes() call return a byte representation of the String using the default character set encoding on the machine. What the default character set is depends on the machine on which the code is executed. Therefore it is generally better to explicitly specify a character set to use to create the byte representation (as in the next line).
The second getBytes() call return a UTF-8 byte representation of the String.

Converting to Uppercase and Lowercase

You can convert Strings to uppercase and lowercase using the methods toUpperCase() and toLowerCase(). Here are two examples:
String theString = "This IS a mix of UPPERcase and lowerCASE";

String uppercase = theString.toUpperCase();
String lowercase = theString.toLowerCase();
Read More

News IN TECH CHANGES

Handing Touch Events in JavaScript
I have extended my "Responsive, Mobile Friendly Web Design" tutorial with a text on how to handle touch events in JavaScript. Touch events are fired by tablets and smart phones, and can be more advanced than mouse events.

AngularJS Custom Directives - Updated
I have extended my AngularJS custom directives tutorial with a section explaining how to use the "transclusion" feature of AngularJS. Transclusion makes it possible to have AngularJS process the HTML nested inside a directive element, instead of having to provide a full HTML template for the directive. Thus, the user of your directive can nest his / her own HTML inside your directive.

HTML5 - Dragging Files Into The Browser
I have just updated my HTML5 drag and drop tutorial with a section explaining how to access files that are dragged into the browser from the file system.

HTML5 Drag and Drop
HTML5 enables drag and drop directly in the browser. While this has been possible for some time now with proprietary APIs, HTML5 is now standardizing the API for drag and drop. This tutorial explains how to use the new HTML5 drag and drop features.

AngularJS Custom Directives
This text explains how to create your own AngularJS directives for use inside AngularJS HTML templates. Creating your own directives can be useful sometimes to clean up your HTML templates.

AngularJS Custom Directives Tutorial
I have extended my AngularJS tutorial with a text explaining how to implement your own AngularJS directives for use in your HTML templates.

HTML5 Messaging - Bug fixes
I have fixed a few minor errors in the code examples in my HTML5 messaging tutorial. Now the examples should be able to actually run!

AngularJS Critique
In extension of my AngularJS tutorial I have added a critique of the AngularJS framework. I don't often criticise what I write about, but in this case with AngularJS getting so popular, and almost no critique available about it, I felt the need to put down what I feel about it.

AngularJS Forms - Updated
The AngularJS Forms tutorial has been updated with information about how to create data bound Select boxes, and about form validation.

AngularJS Forms - Tutorial
My AngularJS tutorial now has a text explaining the basics of form handling in AngularJS. It has enough detail to get you started. I will add more details in a near future.

Angular JS AJAX - JSONP
I have just updated the AngularJS AJAX tutorial with a section explaining how to make JSONP calls. JSONP calls are a way to make cross domain remote service calls - something which is not normally possible with AJAX.

AngularJS AJAX
The 4th text in my AngularJS tutorial explains how to make AJAX calls with AngularJS. So far the basic $http service is covered. The rest of AngularJS's more advanced AJAX options will be covered soon.

HTML5 Canvas - Transformations - Updated
I have updated my transformations text in my HTML5 canvas tutorial. It is the part about rotating a shape around its own center (or around any other point) that is updated. A reader notified me that this section could be made better (including how), and now I have updated it (thanks!).

AngularJS Events
This text explains how to wire up your AngularJS application to listen for mouse, keyboard and other events from the browser.

AngularJS Views and Directives
The AngularJS tutorial has been extended with a text explaining how to create AngularJS views. The text covers the core principles, and the core AngularJS directives used to generate views.
Read More

Tuesday, February 18, 2014

9 Warning Signs You’re On the Wrong Track



9 Warning Signs You’re On the Wrong Track 

“May you live every day of your life.”
―Jonathan Swift


A few years ago one of our close friends unexpectedly passed away at age 27.  Angel and I spent several weeks mourning, reflecting, and re-evaluating our purpose and path forward.  The aftermath of this tragedy reframed our thinking on many levels, and completely overhauled how we approach our lives, our dreams, and our relationships.
We suddenly realized how the fragility of life makes every moment so meaningful, and that most of us waste far too many moments immersing ourselves in needless distractions that steal our attention away from the things that actually matter.
If you feel like you’re on the wrong track with what matters most to you, here are nine warning signs to look for, and tips to get you back on track:

1.  All the decisions you’ve made someone else made for you.

There are people who live their entire lives on the default settings, never realizing they can customize everything.  Don’t be one of them.
You have to live your own life your own way.  That’s all there is to it.  Each of us has a unique fire in our heart for something that makes us feel alive.  It’s your duty to find it and keep it lit.  You’ve got to stop caring so much about what everyone else wants for you, and start actually living for yourself.
Find your love, your talents, your passions and embrace them.  Don’t hide behind other people’s decisions.  Don’t let others tell you what you want.  Design and experience YOUR life!  The life you create from doing something that moves you is far better than the life you get from sitting around wishing you were doing it.  (Angel and I discuss this in more detail in the “Passion and Growth” chapter of 1,000 Little Things Happy, Successful People Do Differently.)

2.  You’re only doing what you’re doing because it’s safe.

Never let your fear decide your future.  To play it too safe is one of the riskiest choices you can make.  You cannot grow unless you are willing to change and adapt.  You will never improve yourself if you cling to what used to be simply because it’s familiar and comfortable.
Accept what is, let go of what was and have faith in what could be.  The bold steps you take into the unknown won’t be easy, but every step is worth it.  There’s no telling how many miles you will have to run while chasing a dream, but this chase is what gives meaning to life.  And even if you have to fail several times before you succeed, your worst attempt will always be 100% better than the person who settles and never tries at all.

3.  You have chosen the easiest possible path.

Nothing in life is easy. Don’t expect things to be given to you.  Go out and achieve them.  Good things come to those who work for them.  Some have natural talent, while others make up for it with tremendous heart and determination, and it’s almost always the latter group that succeeds in the long run.
There is too much emphasis on finding a ‘quick fix’ in today’s society.  For example taking diet pills to lose weight instead of exercising and eating well.  No amount of magic fairy dust replaces diligent, focused, hard work.
Working and training for something is the opposite of hoping for it.  If you believe in it with all your heart, then work for it with all your might.  Great achievements must be earned.  There is no elevator to success; you must take the stairs.  So forget how you feel and remember what you deserve.  NOW is always the best time to break out of your shell and show the world who you really are and what you’re really made of.  Start right where you are, use what you have, do what you can, and give it your best shot.

4.  Obstacles are all you see.

The big difference between an obstacle and an opportunity is how you look at it.  Look at the positives and don’t dwell on the negatives.  If you keep your head down, you’ll miss life’s goodness.
There’s no shortage of problems waiting to be addressed.  When you see problems piled on top of problems, and when there seems to be no end to the work that must be done in order to resolve them, what are you really seeing?  You’re looking at a mountain of opportunity.  You’re looking at a situation in which you can truly make a difference.  You’re looking at an environment where you can reach great heights by raising the stakes and pulling the reality of what’s possible along with you.
When you look at an obstacle, but see opportunity instead, you become a powerful source that transforms grief into greatness.  (Read Flourish.)

5.  You are working hard, but making zero progress.

To achieve success and sustain happiness in life, you must focus your attention on the right things, in the right ways.  Every growing human being (that means all of us) has resource constraints: limited time and energy.  It is critical that you spend your resources effectively.  You have to stay laser-focused on doing the RIGHT work, instead of doing a bunch of inconsequential work, right.
Not all work is created equal.  Don’t get caught up in odd jobs, even those that seem urgent, unless they are also important.  Don’t confuse being busy with being productive.

6.  You have a started a dozen projects and completed none of them.

We are judged by what we finish, not what we start.  Period.
Think about it, you rarely fail for the things you do.  You fail for the things you don’t do, the business you leave unfinished, and the things you make excuses about for the rest of your life.
In all walks of life, passion is what starts it and dedication is what finishes it.

7.  You are too busy to connect with others in a meaningful way.

Never get so busy making a living that you forget to make a life for yourself.  Never get so busy that you don’t have time to be kind and connect with others.  The happiest lives are connected to quality relationships.  If you are too busy to share an occasional laugh with someone, you a://ir-na.amazon-adsystem.com/e/ir?t=marandang-20&l=as2&o=1&a=0060928972" style="border: medium none ! important; margin: 0px ! important" border="0" height="1" width="1" />.)

9.  You are playing a role in life’s drama circle.

Needless drama doesn’t just walk into your life out of nowhere; you either create it, invite it or associate with those who bring it.  Do not let anyone’s ignorance, hate, drama or negativity stop you from being the best person you can be.
Be an example of a pure existence.  Don’t spew hostile words at someone who spews them at you.  Ignore their foolish antics and focus on kindness.  Communicate and express yourself from a place of peace, from a place of love, with the best intentions.  Use your voice for good – to inspire, to encourage, to educate, and to spread the notions of compassion and understanding.
If someone insists on foisting their hostility and drama on you, simply ignore them and walk away.  Sometimes people will talk about you when they envy the life you lead.  Let them be.  You affected their life; don’t let them affect yours.  Those who create their own drama deserve their own karma.  Don’t get sidetracked by people who are not on track.
Read More

Monday, February 17, 2014

10 Simple Things You Can Do Today That Will Make You Happier, Backed By Science

Happiness is so interesting, because we all have different ideas about what it is and how to get it. It’s also no surprise that it’s the Nr.1 value for Buffer’s culture, if you see our slidedeck about it. So naturally we are obsessed with it.
I would love to be happier, as I’m sure most people would, so I thought it would be interesting to find some ways to become a happier person that are actually backed up by science. Here are ten of the best ones I found.

1. Exercise more – 7 minutes might be enough

You might have seen some talk recently about the scientific 7 minute workout mentioned in The New York Times. So if you thought exercise was something you didn’t have time for, maybe you can fit it in after all.
Exercise has such a profound effect on our happiness and well-being that it’s actually been proven to be an effective strategy for overcoming depression. In a study cited in Shawn Achor’s book, The Happiness Advantage, three groups of patients treated their depression with either medication, exercise, or a combination of the two. The results of this study really surprised me. Although all three groups experienced similar improvements in their happiness levels to begin with, the follow up assessments proved to be radically different:
The groups were then tested six months later to assess their relapse rate. Of those who had taken the medication alone, 38 percent had slipped back into depression. Those in the combination group were doing only slightly better, with a 31 percent relapse rate. The biggest shock, though, came from the exercise group: Their relapse rate was only 9 percent!

You don’t have to be depressed to gain benefit from exercise, though. It can help you to relax, increase your brain power and even improve your body image, even if you don’t lose any weight.
A study in the Journal of Health Psychology found that people who exercised felt better about their bodies, even when they saw no physical changes:
Body weight, shape and body image were assessed in 16 males and 18 females before and after both 6 × 40 mins exercise and 6 × 40 mins reading. Over both conditions, body weight and shape did not change. Various aspects of body image, however, improved after exercise compared to before.
We’ve explored exercise in depth before, and looked at what it does to our brains, such as releasing proteins and endorphins that make us feel happier, as you can see in the image below.
make yourself happier - exercise

2. Sleep more – you’ll be less sensitive to negative emotions

We know that sleep helps our bodies to recover from the day and repair themselves, and that it helps us focus and be more productive. It turns out, it’s also important for our happiness.
In NutureShock, Po Bronson and Ashley Merryman explain how sleep affects our positivity:
Negative stimuli get processed by the amygdala; positive or neutral memories gets processed by the hippocampus. Sleep deprivation hits the hippocampus harder than the amygdala. The result is that sleep-deprived people fail to recall pleasant memories, yet recall gloomy memories just fine.
In one experiment by Walker, sleep-deprived college students tried to memorize a list of words. They could remember 81% of the words with a negative connotation, like “cancer.” But they could remember only 31% of the words with a positive or neutral connotation, like “sunshine” or “basket.”
The BPS Research Digest explores another study that proves sleep affects our sensitivity to negative emotions. Using a facial recognition task over the course of a day, the researchers studied how sensitive participants were to positive and negative emotions. Those who worked through the afternoon without taking a nap became more sensitive late in the day to negative emotions like fear and anger.
Using a face recognition task, here we demonstrate an amplified reactivity to anger and fear emotions across the day, without sleep. However, an intervening nap blocked and even reversed this negative emotional reactivity to anger and fear while conversely enhancing ratings of positive (happy) expressions.
Of course, how well (and how long) you sleep will probably affect how you feel when you wake up, which can make a difference to your whole day. Especially this graph showing how your brain activity decreases is a great insight about how important enough sleep is for productivity and happiness:
make yourself happier
Another study tested how employees’ moods when they started work in the morning affected their work day.
Researchers found that employees’ moods when they clocked in tended to affect how they felt the rest of the day. Early mood was linked to their perceptions of customers and to how they reacted to customers’ moods.
And most importantly to managers, employee mood had a clear impact on performance, including both how much work employees did and how well they did it.
Sleep is another topic we’ve looked into before, exploring how much sleep we really need to be productive.

3. Move closer to work – a short commute is worth more than a big house

Our commute to the office can have a surprisingly powerful impact on our happiness. The fact that we tend to do this twice a day, five days a week, makes it unsurprising that its effect would build up over time and make us less and less happy.
According to The Art of Manliness, having a long commute is something we often fail to realize will affect us so dramatically:
… while many voluntary conditions don’t affect our happiness in the long term because we acclimate to them, people never get accustomed to their daily slog to work because sometimes the traffic is awful and sometimes it’s not. Or as Harvard psychologist Daniel Gilbert put it, “Driving in traffic is a different kind of hell every day.”
We tend to try to compensate for this by having a bigger house or a better job, but these compensations just don’t work:
Two Swiss economists who studied the effect of commuting on happiness found that such factors could not make up for the misery created by a long commute.

4. Spend time with friends and family – don’t regret it on your deathbed

Staying in touch with friends and family is one of the top five regrets of the dying. If you want more evidence that it’s beneficial for you, I’ve found some research that proves it can make you happier right now.
Social time is highly valuable when it comes to improving our happiness, even for introverts. Several studies have found that time spent with friends and family makes a big difference to how happy we feel, generally.
I love the way Harvard happiness expert Daniel Gilbert explains it:
We are happy when we have family, we are happy when we have friends and almost all the other things we think make us happy are actually just ways of getting more family and friends.
George Vaillant is the director of a 72-year study of the lives of 268 men.
In an interview in the March 2008 newsletter to the Grant Study subjects, Vaillant was asked, “What have you learned from the Grant Study men?” Vaillant’s response: “That the only thing that really matters in life are your relationships to other people.”
He shared insights of the study with Joshua Wolf Shenk at The Atlantic on how the men’s social connections made a difference to their overall happiness:
The men’s relationships at age 47, he found, predicted late-life adjustment better than any other variable, except defenses. Good sibling relationships seem especially powerful: 93 percent of the men who were thriving at age 65 had been close to a brother or sister when younger.
In fact, a study published in the Journal of Socio-Economics states than your relationships are worth more than $100,000:
Using the British Household Panel Survey, I find that an increase in the level of social involvements is worth up to an extra £85,000 a year in terms of life satisfaction. Actual changes in income, on the other hand, buy very little happiness.
I think that last line is especially fascinating: Actual changes in income, on the other hand, buy very little happiness. So we could increase our annual income by hundreds of thousands of dollars and still not be as happy as if we increased the strength of our social relationships.
The Terman study, which is covered in The Longevity Project, found that relationships and how we help others were important factors in living long, happy lives:
We figured that if a Terman participant sincerely felt that he or she had friends and relatives to count on when having a hard time then that person would be healthier. Those who felt very loved and cared for, we predicted, would live the longest.
Surprise: our prediction was wrong… Beyond social network size, the clearest benefit of social relationships came from helping others. Those who helped their friends and neighbors, advising and caring for others, tended to live to old age.

5. Go outside – happiness is maximized at 13.9°C

In The Happiness Advantage, Shawn Achor recommends spending time in the fresh air to improve your happiness:
Making time to go outside on a nice day also delivers a huge advantage; one study found that spending 20 minutes outside in good weather not only boosted positive mood, but broadened thinking and improved working memory…
This is pretty good news for those of us who are worried about fitting new habits into our already-busy schedules. Twenty minutes is a short enough time to spend outside that you could fit it into your commute or even your lunch break.
A UK study from the University of Sussex also found that being outdoors made people happier:
Being outdoors, near the sea, on a warm, sunny weekend afternoon is the perfect spot for most. In fact, participants were found to be substantially happier outdoors in all natural environments than they were in urban environments.
The American Meteorological Society published research in 2011 that found current temperature has a bigger effect on our happiness than variables like wind speed and humidity, or even the average temperature over the course of a day. It also found that happiness is maximized at 13.9°C, so keep an eye on the weather forecast before heading outside for your 20 minutes of fresh air.
The connection between productivity and temperature is another topic we’ve talked about more here. It’s fascinating what a small change in temperature can do.

6. Help others – 100 hours a year is the magical number

One of the most counterintuitive pieces of advice I found is that to make yourself feel happier, you should help others. In fact, 100 hours per year (or two hours per week) is the optimal time we should dedicate to helping others in order to enrich our lives.
If we go back to Shawn Achor’s book again, he says this about helping others:
…when researchers interviewed more than 150 people about their recent purchases, they found that money spent on activities—such as concerts and group dinners out—brought far more pleasure than material purchases like shoes, televisions, or expensive watches. Spending money on other people, called “prosocial spending,” also boosts happiness.
The Journal of Happiness Studies published a study that explored this very topic:
Participants recalled a previous purchase made for either themselves or someone else and then reported their happiness. Afterward, participants chose whether to spend a monetary windfall on themselves or someone else. Participants assigned to recall a purchase made for someone else reported feeling significantly happier immediately after this recollection; most importantly, the happier participants felt, the more likely they were to choose to spend a windfall on someone else in the near future.
So spending money on other people makes us happier than buying stuff for ourselves. What about spending our time on other people? A study of volunteering in Germany explored how volunteers were affected when their opportunities to help others were taken away:
 Shortly after the fall of the Berlin Wall but before the German reunion, the first wave of data of the GSOEP was collected in East Germany. Volunteering was still widespread. Due to the shock of the reunion, a large portion of the infrastructure of volunteering (e.g. sports clubs associated with firms) collapsed and people randomly lost their opportunities for volunteering. Based on a comparison of the change in subjective well-being of these people and of people from the control group who had no change in their volunteer status, the hypothesis is supported that volunteering is rewarding in terms of higher life satisfaction.
In his book Flourish: A Visionary New Understanding of Happiness and Well-being, University of Pennsylvania professor Martin Seligman explains that helping others can improve our own lives:
…we scientists have found that doing a kindness produces the single most reliable momentary increase in well-being of any exercise we have tested.

7. Practice smiling – it can alleviate pain

Smiling itself can make us feel better, but it’s more effective when we back it up with positive thoughts, according to this study:
A new study led by a Michigan State University business scholar suggests customer-service workers who fake smile throughout the day worsen their mood and withdraw from work, affecting productivity. But workers who smile as a result of cultivating positive thoughts – such as a tropical vacation or a child’s recital – improve their mood and withdraw less.
Of course it’s important to practice “real smiles” where you use your eye sockets. It’s very easy to spot the difference:
make yourself happier smiling
According to PsyBlog, smiling can improve our attention and help us perform better on cognitive tasks:
Smiling makes us feel good which also increases our attentional flexibility and our ability to think holistically. When this idea was tested by Johnson et al. (2010), the results showed that participants who smiled performed better on attentional tasks which required seeing the whole forest rather than just the trees.
A smile is also a good way to alleviate some of the pain we feel in troubling circumstances:
Smiling is one way to reduce the distress caused by an upsetting situation. Psychologists call this the facial feedback hypothesis. Even forcing a smile when we don’t feel like it is enough to lift our mood slightly (this is one example of embodied cognition).
One of our previous posts goes into even more detail about the science of smiling.

8. Plan a trip – but don’t take one

As opposed to actually taking a holiday, it seems that planning a vacation or just a break from work can improve our happiness. A study published in the journal, Applied Research in Quality of Life showed that the highest spike in happiness came during the planning stage of a vacation as employees enjoyed the sense of anticipation:
In the study, the effect of vacation anticipation boosted happiness for eight weeks.
After the vacation, happiness quickly dropped back to baseline levels for most people.
Shawn Achor has some info for us on this point, as well:
One study found that people who just thought about watching their favorite movie actually raised their endorphin levels by 27 percent.
If you can’t take the time for a vacation right now, or even a night out with friends, put something on the calendar—even if it’s a month or a year down the road. Then whenever you need a boost of happiness, remind yourself about it.

9. Meditate – rewire your brain for happiness

Meditation is often touted as an important habit for improving focus, clarity and attention span, as well as helping to keep you calm. It turns out it’s also useful for improving your happiness:
In one study, a research team from Massachusetts General Hospital looked at the brain scans of 16 people before and after they participated in an eight-week course in mindfulness meditation. The study, published in the January issue of Psychiatry Research: Neuroimaging, concluded that after completing the course, parts of the participants’ brains associated with compassion and self-awareness grew, and parts associated with stress shrank.
Meditation literally clears your mind and calms you down, it’s been often proven to be the single most effective way to live a happier life. I believe that this graphic explains it the best:
calming-mind-brain-waves make yourself happier
According to Shawn Achor, meditation can actually make you happier long-term:
Studies show that in the minutes right after meditating, we experience feelings of calm and contentment, as well as heightened awareness and empathy. And, research even shows that regular meditation can permanently rewire the brain to raise levels of happiness.
The fact that we can actually alter our brain structure through mediation is most surprising to me and somewhat reassuring that however we feel and think today isn’t permanent.
We’ve explored the topic of meditation and it’s effects on the brain in-depth before. It’s definitely mind-blowing what this can do to us.

10. Practice gratitude – increase both happiness and life satisfaction

This is a seemingly simple strategy, but I’ve personally found it to make a huge difference to my outlook. There are lots of ways to practice gratitude, from keeping a journal of things you’re grateful for, sharing three good things that happen each day with a friend or your partner, and going out of your way to show gratitude when others help you.
In an experiment where some participants took note of things they were grateful for each day, their moods were improved just from this simple practice:
The gratitude-outlook groups exhibited heightened well-being across several, though not all, of the outcome measures across the 3 studies, relative to the comparison groups. The effect on positive affect appeared to be the most robust finding. Results suggest that a conscious focus on blessings may have emotional and interpersonal benefits.
The Journal of Happiness studies published a study that used letters of gratitude to test how being grateful can affect our levels of happiness:
Participants included 219 men and women who wrote three letters of gratitude over a 3 week period.
Results indicated that writing letters of gratitude increased participants’ happiness and life satisfaction, while decreasing depressive symptoms.
For further reading, check out 7 Simple productivity tips you can apply today, backed by science, which goes even deeper into what we can do to be more grateful.

Quick last fact: Getting older will make yourself happier

As a final point, it’s interesting to note that as we get older, particularly past middle age, we tend to grow happier naturally. There’s still some debate over why this happens, but scientists have got a few ideas:
Researchers, including the authors, have found that older people shown pictures of faces or situations tend to focus on and remember the happier ones more and the negative ones less.
Other studies have discovered that as people age, they seek out situations that will lift their moods — for instance, pruning social circles of friends or acquaintances who might bring them down. Still other work finds that older adults learn to let go of loss and disappointment over unachieved goals, and hew their goals toward greater wellbeing.
So if you thought being old would make you miserable, rest assured that it’s likely you’ll develop a more positive outlook than you probably have now.
Want to chat about this article? Leave a comment below or send me an email with your thoughts.
Oh and before I forget, we’ve recently launched the new Buffer for Business. Take a look, it’s the most powerful Buffer yet to help you better manage your social media everywhere.
If you liked this post, you might also like “10 of the most controversial productivity tips that actually work” and “A scientific guide to saying “no”: How to avoid temptation and distraction
Read More

Saturday, February 15, 2014

The 10 Most Important Things to Simplify in Your Life

“Purity and simplicity are the two wings with which man soars above the earth and all temporary nature.” – Thomas Kempis
Simplicity brings balance, freedom, and joy. When we begin to live simply and experience these benefits, we begin to ask the next question, “Where else in my life can i remove distraction and simply focus on the essential?”
Based on our personal journey, our conversations, and our observations, here is a list of the 10 most important things to simplify in your life today to begin living a more balanced, joyful lifestyle:
  1. Your Possessions - Too many material possessions complicate our lives to a greater degree than we ever give them credit. They drain our bank account, our energy, and our attention. They keep us from the ones we love and from living a life based on our values. If you will invest the time to remove nonessential possessions from your life, you will never regret it. For further reading on this, 
  2. Your Time Commitments – Most of us have filled our days full from beginning to end with time commitments: work, home, kid’s activities, community events, religious endeavors, hobbies… the list goes on. When possible, release yourself from the time commitments that are not in line with your greatest values.
  3. Your Goals – Reduce the number of goals you are intentionally striving for in your life to one or two. By reducing the number of goals that you are striving to accomplish, you will improve your focus and your success rate. Make a list of the things that you want to accomplish in your life and choose the two most important. When you finish one, add another from your list.
  4. Your Negative Thoughts – Most negative emotions are completely useless. Resentment, bitterness, hate, and jealousy have never improved the quality of life for a single human being. Take responsibility for your mind. Forgive past hurts and replace negative thoughts with positive ones.
  5. Your Debt – If debt is holding you captive, reduce it. Start today. Do what you’ve got to do to get out from under its weight. Find the help that you need. Sacrifice luxury today to enjoy freedom tomorrow.
  6. Your Words – Use fewer words. Keep your speech plain and honest. Mean what you say. Avoid gossip.
  7. Your Artificial Ingredients – Avoid trans fats, refined grain (white bread), high-fructose corn syrup, and too much sodium. Minimizing these ingredients will improve your energy level in the short-term and your health in the long-term. Also, as much as possible, reduce your consumption of over-the-counter medicine – allow your body to heal itself naturally as opposed to building a dependency on substances.
  8. Your Screen Time – Focusing your attention on television, movies, video games, and technology affects your life more than you think. Media rearranges your values. It begins to dominate your life. And it has a profound impact on your attitude and outlook. Unfortunately, when you live in that world on a consistent basis, you don’t even notice how it is impacting you. The only way to fully appreciate its influence in your life is to turn them off.
  9. Your Connections to the World - Relationships with others are good, but constant streams of distraction are bad. Learn when to power off the blackberry, log off facebook, or not read a text. Focus on the important, not the urgent. A steady flow of distractions from other people may make us feel important, needed, or wanted, but feeling important and accomplishing importance are completely different things.
  10. Your Multi-Tasking - Research indicates that multi-tasking increases stress and lowers productivity. while single-tasking is becoming a lost art, learn it. Handle one task at a time. Do it well. And when it is complete, move to the next.
Read More

THE IMPORTANCE OF LIFE SKILLS

In our society, every employer sets out the prerequisites for potential employees as having a number of certificates: be they Diploma, Degree, Masters or Doctorate. There is no problem with these prerequisites; however, one may wonder why organizations, businesses or institutions are still crumbling and experiencing so many problems.
Employers may have all the ‘qualifications’ from the finest universities around the world and employ individuals who have graduated from the most recognized, accredited universities, but according to research and observation, workplace violence, lack of interpersonal communication skills, stress and anger issues are abundantly high. Mere academic qualifications will not make an organization more efficient.
With all the qualifications, can we say that we exercise emotional intelligence? Do we know how to control our anger? Are we aware of what we are doing to ourselves- the self-destruction we are causing? No one destroys us you know, we are doing a pretty, darn good job at destroying ourselves.
The reason businesses and organizations are experiencing many problems is that their employers and employees are ‘Lacking Life Skills’ – those basic things we need to take us through life every day. What purpose would it serve if a man has a Degree or Masters, but insults everyone when he’s angry or perhaps breaks things, or maybe utters a flood of epithets?
Why do we refuse to accept those who have no Certificates into our organizations even though these individuals have all the necessary experience and common sense? Have we ever thought of how the Egyptians built the pyramids? Did they have certificates?
These are pertinent questions. However the employer is one who always looks at the person most likely to advance his business. And for him advancing the business means pushing the worker, sometimes treating that worker little better than a slave. We have had reports of employers actually assaulting workers, physically.
There are people who would say that they are not children and therefore they would resent and attempt to assault them. But then again, the idea of job hunting is not something that some people relish. There are not too many jobs in the country and employers know this.
More recently, some people have been complaining that their recent employers merely kept hiring and firing. He would hire someone and fire that person before that person could qualify for benefits. This cycle is allowed to continue because the employer knows that there would always be a line leading to his door for the very reason that jobs are simply not there. People who were previously hired and fired return for more of the same treatment.
Such practices make people promote the application of life skills in the workplace. The most efficient businesses are those make each worker feel wanted.  Those in which anger seems to be the common factor are the places with production problems. The sugar estates are classic examples. The foremen are nothing but bullies and the workers would strike at the drop of a hat.
A number of articles have been written on Life Skills and their benefits, especially in the area of Anger Management.
The public needs to be aware of the importance of Life Skills – programmers which would actually benefit the individual in self-development.
Government departments are inefficient because of poor management skills.  We have seen things reach the stage where workers come and go pretty much as they please simply because the manager is insecure and often demonstrates attitudes that are little better than the errant staff member.
Just this past week an educationist noted that the difference between schools is the management. Those with strong managers, people who have interpersonal skills, do better than those where the manager is laidback. Those who insist on proper behavior from the staff would present the better results and this has been proven.
That is why the training institutions at one time focused on psychology. Every teacher had to understand human nature and apply the knowledge in any condition. Perhaps there is need to review the policy of management training.
Read More

Thursday, February 13, 2014

HISTORY OF VALENTINE’S DAY

Every year, the fourteenth day of the month of February has millions across the world presenting their loved ones with candy, flowers, chocolates and other lovely gifts. In many countries, restaurants and eateries are seen to be filled with couples who are eager to celebrate their relationship and the joy of their togetherness through delicious cuisines. There hardly seems to be a young man or woman who is not keen to make the most of the day.
The reason behind all of this is a kindly cleric named Valentine who died more than a thousand years ago.
“The story of Valentine’s Day begins in the third century with an oppressive Roman emperor and a humble Christian Martyr. The emperor was Claudius II. The Christian was Valentinus.
Claudius had ordered all Romans to worship twelve gods, and had made it a crime punishable by death to associate with Christians. But Valentinus was dedicated to the ideals of Christ; not even the threat of death could keep him from practicing his beliefs. He was arrested and imprisoned.
During the last weeks of Valentinus’s life a remarkable thing happened. Seeing that he was a man of learning, the jailer asked whether his daughter, Julia, might be brought to Valentinus for lessons. She had been blind since birth. Julia was a pretty young girl with a quick mind. Valentinus read stories of Rome’s history to her. He described the world of nature to her. He taught her arithmetic and told her about God. She saw the world through his eyes, trusted his wisdom, and found comfort in his quiet strength.
“Valentinus, does God really hear our prayers?” Julia asked one day.
“Yes, my child, He hears each one.”
“Do you know what I pray for every morning and every night? I pray that I might see. I want so much to see everything you’ve told me about!”
“God does what is best for us if we will only believe in Him,” Valentinus said.
“Oh, Valentinus, I do believe! I do!” She knelt and grasped his hand.
They sat quietly together, each praying. Suddenly there was a brilliant light in the prison cell. Radiant, Julia screamed, “Valentinus, I can see! I can see!”
“Praise be to God!” Valentinus exclaimed, and he knelt in prayer.
Meanwhile, a deep friendship had been formed between Valentine and Asterius’ daughter. It caused great grief to the young girl to hear of his friend’s imminent death.
On the eve of his death Valentinus wrote a last note to Julia, urging her to stay close to God. He signed it, “From your Valentine.” His sentence was carried out the next day, February 14, 270 A.D., near a gate that was later named Porta Valentini in his memory. He was buried at what is now the Church of Praxedes in Rome. It is said that Julia planted a pink-blossomed almond tree near his grave. Today, the almond tree remains a symbol of abiding love and friendship. On each February 14, Saint Valentine’s Day, messages of affection, love, and devotion are exchanged around the world.”
Valentine wanted to see happy in her face through his love. his pure love make her to forget her disability.
if your love makes People happy then it is said to be true love.
Love is not for fulfill the lustful desires.
Valentine’s day is not for Romantic Enjoyment with Valentines.
find true love, and spread that true love to all your Neighbors.
Read More

Popular Posts

Followers

About