Wednesday, July 21, 2021

How to create a icon to run for application in Ubuntu

 1.  Go   to   root  folder and  then open  a  terminal there .  If  not  use  Ctrl  +  L   and  search  "/usr/share/applications"

2. Then  go  to  path  "/usr/share/applications

     root@roshans-HP-PrBook-G4:/usr/share/applications#

3. Then  we have  to  give  a  name  for   icon  name as  we want ,

    Here  my  icon  name  is   "intelJIdea"

   sudo  touch intelJIdea.desktop 

4. After  that   sudo vi   intelJIdea.desktop .Then    we  have  to add following  code  to  that  file  

    [Desktop Entry]
    Name=IntelliJ IDEA
    Comment=IntelliJ IDEA IDE
    Exec=/home/roshans/Documents/Software/idea-IC-211.7628.21/bin/idea.sh
    Icon=/home/roshans/Documents/Software/idea-IC-211.7628.21/bin/idea.png
    Terminal=false
    StartupNotify=true
    Type=Application
    Categories=Development;IDE;

5. Then  save  that  file using :wq

6. Then  you  will  be  able  to  find   icon   for  any  application  you  wanted  to  run  using  icon  in the   your  application  list.  

 

 

 


 

Saturday, June 26, 2021

Arrays Utility Class in Java

The Arrays is a utility class which can be found in the  java.util  package. It is very  useful class  and  following  are some of useful methods it has:

  • asList(): returns a fixed-size list backed by an array.
  • binarySearch(): searches for a specific value in an array. Returns the index of the element if found, or -1 if not found. Note that the array must be sorted first.
               int  indexWhichFound  =  Arrays.binarySearch(arrayToSearch,  keyWhichWantToFind);
  • copyOf(): copies a portion of the specified array to a new one. 
               Interger[]   trimmedArray    =   Arrays.copyOf(originalArray, newLength);
  • copyOfRange(): copies a specified range of an array to a new one.
                Interger[]   croppedArray    =   Arrays.copyOfRange(originalArray, startLength,  endLength); 
  • equals(): compares two arrays to determine if they are equal or not.
  • fill(): fills same values to all or some elements in an array.
  • sort(): sorts an array into ascending order.
                 void sort(X[] a)
                 void sort(X[] a, int fromIndex, int toIndex)
                 void sort(T[] a, Comparator<? super T> c)
                 void sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c)

In addition, the System.arraycopy() is an efficient method for copying elements from one array to another. Remember using this method instead of writing your own procedure because this method is very efficient. Arrays.copyOf(originalArray, newLength)  method  internally  uses that  method .Refer  this  document  for more  about  creating  a  copy  of  array. 

System.arraycopy(Object  copyFromArray, int startingPositionOfArrayToCopy,
                             Object  copyToArray, int landingPositionOfArrayCopy, int totalNumerOfComponentsToBeCopy)

So far I have walked you through a tour of arrays in Java. Here’s the summary for today:

  • An array is an object.
  • Elements in an array are accessed by index (0-based).
  • Advantage of array: very fast access to elements.
  • Disadvantage of array: fixed length, not appropriate if a dynamic container is required.
  • The java.util.Arrays class provides useful utility methods for working with arrays such as filling, searching and sorting.
  • The System.arraycopy() method provides an efficient mechanism for copying elements from one array to another.

 

References Used  :-  Notes about Arrays in Java

Thursday, July 9, 2020

How to convert json values to Map in java

If  we  have  String like this

{ "POLICY_URL":"privacy-policy-page",
  "LOGIN_URL":"login",
  "CONTACT_US_URL":"contact-us-page",
  "FAQ_URL":"faqs-page",
  "TERMS_AND_CONDITION_URL":"terms-and-condition-page" }  and  have  to  convert  it to  map,

  then  we  can  use below code ,

    public  Map<String, String> convertJsonStringToMap(String  stringValueThatWeWantToConvert) {
         HashMap<String, Object> map = new HashMap<String, String>();
         ObjectMapper mapper = new ObjectMapper();
         return  mapper.readValue(stringValueThatWeWantToConvert, new TypeReference<HashMap<String, String>>() {});
    }
   



Sunday, May 31, 2020

Martin Fowler - Software Design in the 21st Century ( Code Refactoring )

Code Refactoring  

  • Break code to small methods.
  • After that, it is  easy to understand performance issues and then address  those issues.
  • Use meaningful names for those methods.
  • In team it is better  to have common naming conversion ways.
  • Consider about temporary variables.
  • Do refactoring step by step , commit that stage to you branch.
  • If some modification doesn't work then go back to early safe step.
  • Tools will faster refactoring.
  • Rewrite vs Refactoring .
  • Refactoring  >>  To  make, change easy .
  • Rewrite        >>  If we can do it better  way than old  system.


 

Some interesting things to explore more

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