life is too short for a diary




Dear Vishi, daily log on Aug 29, 2022

Tags: diary letters

Dear Vishi, this is my daily log on Aug 29, 2022.

Reading Origin of Species

Charles Darwin coined the term called Natural Selection. In his own words, "Owing to this struggle for life, any variation, however slight and from whatever cause proceeding, if it be in any degree profitable to an individual of any species, in its infinitely complex relations to other organic beings and to external nature, will tend to the preservation of that individual, and will generally be inherited by its offspring.The offspring, also, will thus have a better chance of surviving, for, of the many individuals of any species which are periodically born, but a small number can survive. I have called this principle, by which each slight variation, if useful, is preserved, by the term of Natural Selection, in order to mark its relation to man's power of selection."

So variations in the organisms that are suited for their environment are “naturally selected” to survive and become more common. It’s the foundation of the modern theory of evolution.

Words of the day

I want to introduce you to two new words in the English language-

  1. Sagacious: Somebody who has sound judgment. Like he was sagacious enough to pay his taxes on time.

  2. Concur: Agree. Like he concurred with my views.

Vitamins

I am taking Vitamin D3 (every alternative day) with a dose of 125 mcg. I think it's better to take Vitamin D from supplements than the sun. According to this study in Yale 1, consuming Vitamin D from either food, supplements, or Sun is the same. Another problem with taking vitamin D from the sun is that there are ultraviolet (UV) rays that can damage the skin, eyes, and immune system.

However, there's another study that says that Vitamin D supplements 2 are not adequately absorbed by the human body. In another research, Richard Weller of the University of Edinborough Medical School, found that exposing volunteers in 2010 to 30 minutes of sunlight, without sunscreen, raised their levels of nitric oxide, which in turn brought their blood pressure down.

So is sunlight good or bad for us? I guess like I always said moderation is the mantra. If you stay for an extended time in the sunlight, use a good sunscreen with SPF number of at least 30.

Java

Today I want to talk about sorting arrays in java. Lets say if you have an array of integer and we want to sort it, we can do this way

int[] testArray = {11, 234, 45, 1, -30};

Arrays.sort(testArray); 

for (int i : testArray) {
  System.out.println(i);
}

This will print the following output in ascending order

-30
1
11
45
234

Now what happens if you have an array of strings, like this


String[] testArray = {"hello", "bye", "si"};

//Sort an array
Arrays.sort(testArray); 

for (String i : testArray) {
  System.out.println(i);
}

This will print strings sorted in lexicographic order.

bye
hello
si

However if we want to change the order of sorting, we can use Comparator. Like we want to sort the array based on length of strings. Comparators in java are objects that can be used to compare two objects.

String[] testArray = {"hello", "bye", "si"};

Comparator<String> comparator = new Comparator<String>(){
  public int compare(String s1, String s2){
    return Integer.compare(s1.length(), s2.length());
  }
};

Arrays.sort(testArray, comparator); 

for (String i : testArray) {
  System.out.println(i);
}

This will print

si 
bye
hello

Songs

Lastly I leave you with some of the news songs that I listened today




References


comments powered by Disqus