Why String is Immutable in Java ?

String pool (String intern pool) is a special storage area in Java heap. When a string is created and if the string already exists in the pool, the reference of the existing string will be returned, instead of creating a new object and returning its reference.

The following code will create only one string object in the heap.

1.String string1 = “abcd”;
2.String string2 = “abcd”;

If string is not immutable, changing the string with one reference will lead to the wrong value for the other references.
java-string-pool

SAAS vs PAAS vs IAAS

SaaS (Software as a Service) model you are provided with access to application softwares often referred to as on-demand softwares. You don’t have to worry about the installation, setup and running of the application. Service provider will do that for you. You just have to pay and use it through some client. Examples: Google Apps, Microsoft Office 365.

PaaS (Platform as a Service), as the name suggests, provides you computing platforms which typically includes operating system, programming language execution environment, database, web server etc. Examples: AWS Elastic Beanstalk, Windows Azure, Heroku, Force.com, Google App Engine, Apache Stratos.

IaaS (Infrastructure as a Service), as the name suggests, provides you the computing infrastructure, physical or (quite often) virtual machines and other resources like virtual-machine disk image library, block and file-based storage, firewalls, load balancers, IP addresses, virtual local area networks etc. Examples: Amazon EC2, Windows Azure, Rackspace, Google Compute Engine

Ugly Numbers Program

Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence
1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, …
shows the first 11 ugly numbers. By convention, 1 is included.
Write a program to find and print the 150’th ugly number.

# include
# include
 
/*This function divides a by greatest divisible 
  power of b*/
int maxDivide(int a, int b)
{
  while (a%b == 0)
   a = a/b; 
  return a;
}   
 
/* Function to check if a number is ugly or not */
int isUgly(int no)
{
  no = maxDivide(no, 2);
  no = maxDivide(no, 3);
  no = maxDivide(no, 5);
   
  return (no == 1)? 1 : 0;
}    
 
/* Function to get the nth ugly number*/
int getNthUglyNo(int n)
{
  int i = 1; 
  int count = 1;   /* ugly number count */
 
  /*Check for all integers untill ugly count 
    becomes n*/
  while (n > count)
  {
    i++;      
    if (isUgly(i))
      count++; 
  }
  return i;
}
 
/* Driver program to test above functions */
int main()
{
    unsigned no = getNthUglyNo(150);
    printf("150th ugly no. is %d ",  no);
    getchar();
    return 0;
}

This method is not time efficient as it checks for all integers until ugly number count becomes n, but space complexity of this method is O(1)

Methods to use involve dynamic programming, google it

Pendrive dosent show files even though storage is occupied

Check if the files are not in hidden mode.

Click on “Start” –>Run –> Type cmd and press Enter.

Here I assume your pendrive drive letter as G:

Enter this command.

attrib -h -r -s  /s  /d  g:\*.* –> Press Enter

You can copy the above command –> Right-click in the Command Prompt and

paste it.

Note : Replace the letter g with your pen drive letter.

Now check your pen drive for the files.

What is Deadlock ?

  • Program 1 requests resource A and receives it.
  • Program 2 requests resource B and receives it.
  • Program 1 requests resource B and is queued up, pending the release of B.
  • Program 2 requests resource A and is queued up, pending the release of A.