Tuesday 24 December 2013

shell script to check mount point size in linux/solaries

The following shell script notifies you if any mount point is greater than 90% full
#!/bin/bash
df -h |tr "%" " " |sed -n '2,$p'| awk '{

if ( $5 > 90 ) {print $6,echo "filesystem is greater than 90% full";}

}'

Output will be something like below.
/orahome1 filesystem is greater than 90% full

Friday 20 December 2013

Unix questions and answers.

1. creating zero lenght file.
$cat /dev/null >file.txt

2. to find teh file size greater than 1000bytes.
$find ./ -size +1000

3. switching a shell
csh -s /bin/csh

4. adding user in linux.
$useradd -d /root/user1 -g owner -s /usr/bin/csh -m user1
$passwd user1

5. delete user in linux.
$userdel -r username

6. check the network status.
$netstat -ef | grep 2000

7. to configure the network status.
$ifconfig

8. display al running jobs.
$top

9. bring job to the foreground
$fg %jobnumber

10. bring the job to background.
$bg %jobnumber.

12. convertin file from dos to unix.
$dos2unix filename

13. split command
$split -option sourcedfile destinationfile
         - b bytes
         - l number of lines

14. deleting empty lines.

$sed '/s/^$/d' inputfile >outputfilee

15. creating symbolic link.
$ln -s file link

16. locate all instnce of the file.
locate file

17. to check disk space.
$df -options
        -k  kilobytes
        -m meghabytes
        h human readable

18. to get all teh links.
$ls -lrt | grep"^l"

19. display the output to multiple files.
$data | tee file1 file2

Linux important commands.

1. Display the utilization of each CPU individually.
$mpstat -P all

2. display the top 10 process which consume CPU.
$ps -eo pcpu,pid,user,args | sort -k 1 -r | head -r

3. display hte memory details.
$cat /proc/meminfo

4. display the memory usage.
$free -m
$vmstat

5 display the number of cpu.
$cat /proc/cpuinfo | grep processor | wc -l
6. display the shared memory parameters.
$ipcs -m

7. display the share memory limits.
$ipcs -lm

8. display the disk activity.
$iostat

9. display the users logged on to the system.
$w

10. display how long the system is running.
$uptime

11. display which shell is using.
$ps -P $$
$echo $SHELL
$echo $$
12. display the awk version.
$awk --version

13. display the page size.
$getconf getsize

14. free the shared memory space.
$ipcs -m     -> it gives the shm id.
$ipcrm <shmid>
$15. memory mapping of the process.
pmap -d pid

16. list all the users.
$cat /etc/passwd

17. display the mounted file system
$cat //proc/mounts

18. to know the swap allocated.
$cat ./proc/swaps

19. display the version of teh kernel.
$cat /proc/version

20 to know whether 32 bit or 64 bit.
$arch
21. to check the available shells.
$cat /etc/shells

Java most asked interview questions

1. what is transient variable?

By default all the variables in the object get converted to a persistant state, in some case you may want to avoid passing some variables, so you can declare that variable as transient variable.
Transient variables are non-serializable.

2. what will happen if we don't initialize the local variables?
COmpilation error will come.

3. Instance variables are initialized to what values?

integer- 0
float 0.0.
boolean - false
string - null.
char -  nothing.

4. how to set locale for Canada?
Locale canada = new Locale("fr","CA");

5. if a exception thrown by a try statement but no catch what is the output?
Compilation error.

6. which variable is synchronizes?
a.static
b.public
c. private

Ans:static.

7. which is the default access specifier for class?

Package

8. JVM declare how many times of memory?

stack and the heap memory.

9. what is the deamon process and whether we can ceate the deamon process?
Deamon process is the thread which is the service provider for user threads.
which will terminate after all user threads terminated.

Yes, we can create the deamon process using
setDeamon() method.

and can check isDeamon().

we need to create the deamon thread before calling the start() method.

10. what is singleton class?
we can not initialize more than one instance.

11. why implementing the runnable interface preferable over extend the thread?
thread class
a. If we extend the thread class all the threads create their own objects and associated with them.
b. if we extend thread in future we can not extend any other thread.

runnable interface.

a. we can implemetn any number of interface.
b all threads created will share same object spce.

11. which algorithem used in java garbage collection?
mark and sweep algorithem.

12. stack is faster or heap?

stack.

13. what is run time polymorpison.?
binding happens during run time, this is because of method overriding.

14. how many public classes can be present in one java file?

one class.

16. how many main mehods can be present in single java file?

more than one.

17. difference between ennumaration and Iterator?

Ennumaration.
It is read only.
it does not have remove method.

Iterator.
It can modify the collection using remove method.
it does remove methd.

18. difference between hashmap and hashtable?
hashmap.
Allows null keys and null values.
hash map is not synchronized.

hashtable
It does not allow null keys and null values.
hash table is synchronized.

19. Advantages and disadvantages of static bllock?

 Advantages.
a. used while loading the device driver.
b. for initialize the variables which requires computation.
c. security related and leaking issues.

disadvantages.

a. static initialization block should not exceed 64k.
b. cn not through checked exceptions.
c. should not try to access super since there is no such thing for static block.
 d. can not return anything from static block.

20.why interface is better than abstract class?
 java will not support class multiple inheritance  so interface is usefull.

21. what is early binding?

the data and the method which will operate on the data are separately  defined in oops, and they bind data members during compilation time.

22. difference between multi threading and multi processing?
multi threading.
a. shares same address space.
b. thread is light weight.
c. cost of communicartion is low.
d. context switching cost is very less.


multi process.
a. each process have seperate address space.
b. heavy weight component.
c. coat of intercommunication is high.
d. context switching cost is very high.

23. why jvm is platform dependenant.
JVM is developed usig the platform dependent languages like c,c++ so it is platform depedent.

24. difference between classpath and path environmen variables?
classpath referes to the user clasess whre located.
c:/programs/
path refers to the executable where located.
c:/java/jdk/bin



 





Java interview questions.