Sunday, July 6, 2014



Singleton Factory  Pattern is a design solution where an application wants one and only instance of an class,in all possible scenarios


Steps to create a Singleton Object
-----------------------------------

  • create a default private constructor.
  • create a method which returns an object.
  • make the method accessible by only one thread at a time by adding synchronized keyword.
  • override the clone method i.e throw Clone not support Exception.


Creating an object from a connection pool is a best example for Singleton

Links
------
http://www.javabeginner.com/learn-java/java-singleton-design-pattern
http://howtodoinjava.com/2012/10/22/singleton-design-pattern-in-java/

Saturday, June 21, 2014

SWAP SPACE MANAGEMENT IN LINUX
=======================================

What is Swap Space?


Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory.




There are 2 ways to add/remove the swap space in Linux.


  • One way is to add the swap space if u have any free disks.
  • Second way is to add the swap space by creating a file on hard disk and making it as a swap space.
First method i have not tried it,as i don't have any free disks.

"free -m"  will the details of the free memory in mb in which it shows the free swap space as well.


Creating a swap file

To add a swap file:
  1. Determine the size of the new swap file in megabytes and multiply by 1024 to determine the number of blocks. For example, the block size of a 512 MB swap file is 65536.
  2. At a terminal with root privileges (sudo -s), type the following command with count being equal to the desired block size:
    dd if=/dev/zero of=/swapfile bs=1024 count=524288
  3. Setup the swap file with the command:
    mkswap /swapfile
  4. To enable the swap file immediately but not automatically at boot time:
    swapon /swapfile
  5. To enable it at boot time, edit /etc/fstab to include the following entry:
    /swapfile swap swap defaults 0 0
    The next time the system boots, it enables the new swap file.
  6. After adding the new swap file and enabling it, verify it is enabled by viewing the output of the command cat /proc/swaps or free.




Tuesday, December 24, 2013

JAVAP,JAVAH,JDB Usage



  • javap - The Java Class File Disassembler




For example javap -c  -classpath  C:\Users\Srikanth\Desktop\blog MyInput


  • jdb - The Java Debugger

jdb helps you find and fix bugs in Java language programs.



  • javah - C Header and Stub File Generator

javah produces C header files and C source files from a Java class. These files provide the connective glue that allow your Java and C code to interact.


For example javah -classpath C:\Users\Srikanth\Desktop\blog MyInput

Monday, December 23, 2013


Java is one of the widely used programming languages for developing all kinds of applications.
It might be because of the following reasons

  • Simple  --it is  very simple to use /implement
  • Robust  --it is 
  • Platform Independent 
  • Portable

When we write a java program which is in human readable format(.java file) is converted to machine readable format(.class file) and this process is called compilation.
javac is java compiler which does this process.


JAVA Installation and Setup


  • Download the jdk latest version from oracle.com
  • After downloading the jdk(java development kit)  if you try to execute the javac in command line it will not work because operating system does not know where the javac is present.



  • Set the required environment variables

I have installed my JDK in F drive.So i have appended the location value of javac to PATH environment variable as set PATH=%PATH%;F:\JDK\bin
So,In order to inform operating we need to set the  path variable to location of javac.

But one disadvantage of this method is every time you  open a new window you have to execute the above command.

So ,the better option is to add PATH environment variable ,by following this
 "My Computer" > "Properties" > "Advanced" > "Environment Variables" > "Path". I saved it.





Make sure that there are no extra spaces after the required path(if extra  space is there then it will not recognize javac command).

And there is also another option just save the command set PATH=%PATH%;F:\JDK\bin   in .bat file
and execute it every time when you tried to run javac command or any java program.







Message

Hi All,

I'm writing this blog in order to share my knowledge and also to stay in touch of all the concepts based on the advice of one my dearest friend.