Tuesday, October 6, 2015

The Bucket List and Stuff...

Take out your pen and paper or open up a text document. Start writing down what comes to mind as you read these questions:
  • What if you were to die tomorrow? What would you wish you could do before you die?
  • What would you do if you had unlimited time, money and resources?
  • What have you always wanted to do but have not done yet?
  • Any countries, places or locations you want to visit?
  • What are your biggest goals and dreams?
  • What do you want to see in person?
  • What achievements do you want to have?
  • What experiences do you want to have / feel?
  • Are there any special moments you want to witness?
  • What activities or skills do you want to learn or try out?
  • What are the most important things you can ever do?
  • What would you like to say/do together with other people? People you love? Family? Friends?
  • Are there any specific people you want to meet in person?
  • What do you want to achieve in the different areas: Social, Love, Family, Career, Finance, Health (Your weight, Fitness level), Spiritual?
  • What do you need to do to lead a life of the greatest meaning?

Come up with as many items as you can. The items should be things you have not done yet. If you find yourself stuck, chances are you are mentally limiting/constraining yourself. Release those shackles – Your bucket list is meant to be a list of everything you want to achieve, do, see, feel and experience in your life.

From: 101 Things To Do Before You Die



Everyone makes their own choices. But if I were at your position, after seeking my answers to above questions, I would definitely...

Travel the world with the person I love (or alone).


See: How does it feel to travel alone?

There's so much we don't know, can't know because we stay at one place all our lives. Not everyone gets such an opportunity to do something what others can't. And if you got one, you gotta do the things what gives you an edge. By travelling, you get the experience of the places, people, problems, cultures, new things, and all that at once! It can be rough in the beginning but it gets beautiful. You just have to understand why is that you are doing what you are doing.

Here are the problems people face in their late 20's.

- Time, but no money
- Money, but no time

Well, my friend, do you see the opportunity you have right here?

Wouldn't you like to gaze at the Northern Lights from a glass igloo in Finnish Lapland?

Wouldn't you like to go and have dinner at this restaurant near Sanyou Cave above the Chang Jiang river, Hubei , China?

Wouldn't you like to leave the world behind for all it's complexities and search for simplicity? Here are a few places that are in my travel bucket list.

Blue Caves – Zakynthos Island, Greece

Santorini, Greece

Blue Lagoon Galapagos Islands in Ecuador

Skaftafell Ice Cave in Iceland

Get Into Action!

After you finish your list, here’s what to do next:
  • Start acting on them! Plan out the successful path toward these goals
  • Be reminded of the list all the time. Use environmental reinforcement – put them up in a prominent spot where you will see them every day / very regularly. Put it in your life handbook, set it as your wallpaper, pin it on your noticeboard, print it out, stick it on your wardrobe/locker.
  • Share them with your family and
    personalexcellence.co
    friends
    . Inspire them to create their own bucket lists too! This way, you also create accountability for yourself as you complete the items on your list.
  • Don’t limit your list items to a certain definition. Sometimes opportunity present itself in a totally different manner. Keep your eyes peeled! The universe will start throwing things your way.
  • Review your list regularly. Cross out the things after you do them. See if some of the items become irrelevant and if there are new things you want to add. Just as you finish the items, you’ll add new ones as they come along. There is absolutely no reason why your list should ever be empty. There is such an incredible wealth of things, events, activities, experiences to witness/go through in life that it’s impossible that you will ever be done with living.

So, I guess you figure out what you want to achieve in this life and go get it.

Thursday, October 1, 2015

All you need to know about Fragments in Android

A Fragment is a piece of an application's user interface or behavior that can be placed in an Activity. Interaction with fragments is done through FragmentManager, which can be obtained via Activity.getFragmentManager() and Fragment.getFragmentManager().
The Fragment class can be used many ways to achieve a wide variety of results. In its core, it represents a particular operation or interface that is running within a larger Activity. A Fragment is closely tied to the Activity it is in, and can not be used apart from one. Though Fragment defines its own lifecycle, that lifecycle is dependent on its activity: if the activity is stopped, no fragments inside of it can be started; when the activity is destroyed, all fragments will be destroyed.
All subclasses of Fragment must include a public no-argument constructor. The framework will often re-instantiate a fragment class when needed, in particular during state restore, and needs to be able to find this constructor to instantiate it. If the no-argument constructor is not available, a runtime exception will occur in some cases during state restore.

So lets take an example of a Music Player. Now if you close the music player all the fragments ie. Album Art placeholder,Song name and Play Pause button all will close.

Basically there are elements that are on an Activity ie UI of the Application. If the activity is closed none of its fragments can be accessed.

  When you add a fragment as a part of your activity layout, it lives in a ViewGroup inside the activity's view hierarchy and the fragment defines its own view layout. You can insert a fragment into your activity layout by declaring the fragment in the activity's layout file, as a element, or from your application code by adding it to an existing ViewGroup. However, a fragment is not required to be a part of the activity layout; you may also use a fragment without its own UI as an invisible worker for the activity.



Wednesday, September 9, 2015

Pyramid Star Triangle with Astrik in Java

How to make a program in java to get a pyramid star?

    *
   * *
  * * *
 * * * *
* * * * *


The Program -

class PrintPyramidStar

    public static void main(String args[]) {

        int c = 1;
        for (int i = 1; i <= 5; i++) {
            for (int j = i; j < 5; j++) {
                System.out.print(" ");
            }
            for (int k = 1; k <= c; k++) {
                if (k % 2 == 0)
                    System.out.print(" ");
                else
                    System.out.print("*");
            }
            System.out.println();
            c += 2;
        }
    }
}


Now the best way to know how it works is by making some changes in the code. Lets do that.

 I will mark the changes I have made in the above program with red.

 CASE 1 -

class PrintPyramidStar

    public static void main(String args[]) {

        int c = 1;
        for (int i = 1; i <= 5; i++) {
            for (int j = i; j < 5; j++) {
                System.out.print(" ");
            }
            for (int k = 1; k <= c; k++) {
                if (k % 2 == 0)
                    System.out.print("1");
                else
                    System.out.print("*");
            }
            System.out.println();
            c += 2;
        }
    }
}


 That resulted in this 

    *
   *1*
  *1*1*
 *1*1*1*
*1*1*1*1*


Ah! So I guess it was for the free spacing between the stars/asterik marks.



Now What if we tweak the numbers.
  

Case 2


Assigning c =10; 

class PrintPyramidStar {

    public static void main(String args[]) {

        int c = 10;
        for (int i = 1; i <= 5; i++) {
            for (int j = i; j < 5; j++) {
                System.out.print(" ");
            }
            for (int k = 1; k <= c; k++) { 
                if (k % 2 == 0)
                    System.out.print(" ");
                else
                    System.out.print("*");
            }
            System.out.println();
            c += 2;
        }
    }
}
 


Output -
    * * * * *
   * * * * * *
  * * * * * * *
 * * * * * * * *
* * * * * * * * *



Got it?

Can you print this?

    *
   ***
  *****
 *******
*********
    *
 
 Leave it in the comments. 

Monday, August 17, 2015

Things that needs to be done. The Great Delusion.

I was just browsing through some videos on Vessel and then I came across Veritasium's new video Our Greatest Delusion. It is one of those videos that really make you reflect on your life...Why are we here? What are we upto?

When one day everything will just end. Why all our lives we run for something that won't be ours anyway? We are not eternal and certainly won't reap the fruits of our success totally? The nothingness will remain in the future...Great leaders who conquered great lands ruled over millions of people were born on the face of earth and now where are they?

We procrastinate things that needs to be done now thinking that we have forever to live..but our days are numbered. It's finite so you better get busy doing what really matters.

Saturday, August 8, 2015

Where am I going wrong? and how one should learn to code?

Enough is Enough now! Seriously who is as slow as me. Why cant I complete something I start? Why I keep on procrastinating? Its not that I don't want to learn JAVA or programming but I still can't keep my mind on it even when I want to and I don't know why? Maybe because right now there are no particular returns that I am expecting off it. Anyway there is a lot happening in my life too and I have to focus on so many things at the very same time. Its just sooooooooooooooo much.

At times I get into some real thinking and I find no reason in anything? What is point of anything? We are hardly doing anything?
We are just like Mayflies running after that source of light even when it lives for just couple of hours but in our case that source of light are these materialistic things that keeps us going.

Maybe I am thinking because I am so damn lazy and always want to find excuses.


You know what is the best way to learn programming or for that matter anything?


Just lock up yourself in your room and learn that goddamn thing and then only come out. Don't use facebook or whatsapp your gf every now and then for that period just ignore everything that distracts you. Infact when you really think about it... We only live for 36500 days at most (if we somehow life for 100 years) but that is rare. The global average is 71 and where I live it is just 66. HA! and I have already lived 1/3 rd of it almost. When you really think about it life is nothing but the minor blip.

The only way you can actually postpone your death is by moving to a distant planet like Earth but longer days. Like 7 hours on that planet equivalent to 700 years on Earth. Imagine? You will see the world changing so fast.

Let me tell you what I will see in those 7 years . Mughals coming to India..Taj Mahal will rise in just seconds... Then come Britishers and after that two World Wars that shook the world. It will be more or less like watching three movies back to back. Amazing it is how the world can change so fast.


Now coming back to Java. I did find some more tutorials on the internet and they are anyday better than reading a book.


Stanford has a course on Java.


You can check it out here

What I was thinking all this while was that I will blog daily now. Blog about what I learn daily. More like a teach and learn thingy.

Keep following to the blog or subscribe to the newsletter.

Sunday, July 19, 2015

Java Synatax and Stuff...

When we consider a Java program it can be defined as a collection of objects that communicate via invoking each other's methods. Let us now briefly look into what do class, object, methods and instance variables mean.
  • Object - Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behaviors -wagging, barking, eating. An object is an instance of a class.
  • Class - A class can be defined as a template/ blue print that describes the behaviors/states that object of its type support.
  • Methods - A method is basically a behavior. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed.
  • Instance Variables - Each object has its unique set of instance variables. An object's state is created by the values assigned to these instance variables.

First Java Program:

Let us look at a simple code that would print the words Hello World.
public class MyFirstJavaProgram {

   /* This is my first java program.  
    * This will print 'Hello World' as the output
    */

    public static void main(String []args) {
       System.out.println("Hello World"); // prints Hello World
    }
} 
Let's look at how to save the file, compile and run the program. Please follow the steps given below:
  • Open notepad and add the code as above.
  • Save the file as: MyFirstJavaProgram.java.
  • Open a command prompt window and go o the directory where you saved the class. Assume it's C:\.
  • Type ' javac MyFirstJavaProgram.java ' and press enter to compile your code. If there are no errors in your code, the command prompt will take you to the next line (Assumption : The path variable is set).
  • Now, type ' java MyFirstJavaProgram ' to run your program.
  • You will be able to see ' Hello World ' printed on the window.
C : > javac MyFirstJavaProgram.java
C : > java MyFirstJavaProgram 
Hello World

Basic Syntax:

About Java programs, it is very important to keep in mind the following points.
  • Case Sensitivity - Java is case sensitive, which means identifier Hello and hello would have different meaning in Java.
  • Class Names - For all class names the first letter should be in Upper Case.

    If several words are used to form a name of the class, each inner word's first letter should be in Upper Case.

    Example class MyFirstJavaClass
  • Method Names - All method names should start with a Lower Case letter.

    If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case.

    Example public void myMethodName()
  • Program File Name - Name of the program file should exactly match the class name.

    When saving the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to the end of the name (if the file name and the class name do not match your program will not compile).

    Example : Assume 'MyFirstJavaProgram' is the class name. Then the file should be saved as 'MyFirstJavaProgram.java'
  • public static void main(String args[]) - Java program processing starts from the main() method which is a mandatory part of every Java program..

Java Identifiers:

All Java components require names. Names used for classes, variables and methods are called identifiers.
In Java, there are several points to remember about identifiers. They are as follows:
  • All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an underscore (_).
  • After the first character identifiers can have any combination of characters.
  • A key word cannot be used as an identifier.
  • Most importantly identifiers are case sensitive.
  • Examples of legal identifiers: age, $salary, _value, __1_value
  • Examples of illegal identifiers: 123abc, -salary

Java Modifiers:

Like other languages, it is possible to modify classes, methods, etc., by using modifiers. There are two categories of modifiers:
  • Access Modifiers: default, public , protected, private
  • Non-access Modifiers: final, abstract, strictfp
We will be looking into more details about modifiers in the next section.

Java Variables:

We would see following type of variables in Java:
  • Local Variables
  • Class Variables (Static Variables)
  • Instance Variables (Non-static variables)

Java Arrays:

Arrays are objects that store multiple variables of the same type. However, an array itself is an object on the heap. We will look into how to declare, construct and initialize in the upcoming chapters.

Java Enums:

Enums were introduced in java 5.0. Enums restrict a variable to have one of only a few predefined values. The values in this enumerated list are called enums.
With the use of enums it is possible to reduce the number of bugs in your code.
For example, if we consider an application for a fresh juice shop, it would be possible to restrict the glass size to small, medium and large. This would make sure that it would not allow anyone to order any size other than the small, medium or large.

Example:

class FreshJuice {

   enum FreshJuiceSize{ SMALL, MEDIUM, LARGE }
   FreshJuiceSize size;
}

public class FreshJuiceTest {

   public static void main(String args[]){
      FreshJuice juice = new FreshJuice();
      juice.size = FreshJuice. FreshJuiceSize.MEDIUM ;
      System.out.println("Size: " + juice.size);
   }
}
Above example will produce the following result:
Size: MEDIUM
Note: enums can be declared as their own or inside a class. Methods, variables, constructors can be defined inside enums as well.

Java Keywords:

The following list shows the reserved words in Java. These reserved words may not be used as constant or variable or any other identifier names.
abstract assert boolean break
byte case catch char
class const continue default
do double else enum
extends final finally float
for goto if implements
import instanceof int interface
long native new package
private protected public return
short static strictfp super
switch synchronized this throw
throws transient try void
volatile while

Comments in Java

Java supports single-line and multi-line comments very similar to c and c++. All characters available inside any comment are ignored by Java compiler.
public class MyFirstJavaProgram{

   /* This is my first java program.
    * This will print 'Hello World' as the output
    * This is an example of multi-line comments.
    */

    public static void main(String []args){
       // This is an example of single line comment
       /* This is also an example of single line comment. */
       System.out.println("Hello World"); 
    }
} 

Using Blank Lines:

A line containing only whitespace, possibly with a comment, is known as a blank line, and Java totally ignores it.

Inheritance:

In Java, classes can be derived from classes. Basically if you need to create a new class and here is already a class that has some of the code you require, then it is possible to derive your new class from the already existing code.
This concept allows you to reuse the fields and methods of the existing class without having to rewrite the code in a new class. In this scenario the existing class is called the superclass and the derived class is called the subclass.

Interfaces:

In Java language, an interface can be defined as a contract between objects on how to communicate with each other. Interfaces play a vital role when it comes to the concept of inheritance.
An interface defines the methods, a deriving class(subclass) should use. But the implementation of the methods is totally up to the subclass.

First week of Learning Java ended with Null(void)

Okay So another week and still I am nowhere near to Android Development?
What exactly is the best way to learn Java? How to go about it? Infact What is the best way to learn any language for that matter?

I googled these questions and there were some good anwers and this one is what I really liked on Quora-

Read Faizan Ahemad's answer to How can I learn Java? on Quora

Now he did explain pretty much but still where am I lacking?

I did try Java in a Nutshell and Head First Java even Java for Dummies. But where should I stop? Anyway I will try yet again and let's see how it goes...