Friday, April 20, 2012

Windows command

The following commands are used in command prompt


To list the process in command prompt
   tasklist

To kill a process we can do using process id or process name
   taskkill /pid 567
   taskkill /IM w3wp.exe /F

To list the files in the directory
   dir

To know the ports used in  system
  netstat

Java Related

Why JVM
1) Platform Independent (It includes hardware and Software)
    Eg : Linux runs on 16 bit,32 bit,64 bit and the application developed in 16 bit cannot run in other bits but the application developed by java will run on 16 bit,32 bit and 64 bit also

2) Easy to install ( copy & paste)
3) Memory Management (Eg : Garbage Collector)
4) Improved Security for clients
    Before java we have security for server but we dont have security for clients.Once a client is connected to a server the server has all permissions to do on client and the server can format the disk also ,so with java we have got client side security so that server needs to authenticate with the client

 JVM is present under rt.jar

Pre-emptive multitask : Multiple threads will be loaded but only one thread will run.Threads will toggle between the themself

Muti-core Processor: This will  process multi threads at same time

Thread : Queue of executable instructions waiting for CPU time

Different Ways of creating Objects in java
a) Using new Keyword
      MyObject obj=new MyObject();

b) Using Class.forName()
      If we know the name of the class and if it has public default constructor we can create an object
      MyObject obj=(MyObject)Class.forName("Vinay.MyObject").newInstance();
      Vinay.MyObject is class name

c) Using clone
      MyObject anotherObj = new Object();
      MyObject obj = anotherObj.clone();

d) Using Deserialization
       ObjectInputStream instream=new ObjectInputStream(new FileInputStream("filename"));
       MyObject obj=(MyObject)instream.readObject();

e) Using class Loader
     this.getClass().getClassLoader().loadclass("pavan.myObject).newInstance();

What is Thread safe  ?
         Global variables are not thread safe
  
Why Java Enterprise Edition is required ?
In  standalone Java application we cannot communicate between to process.For Example If we have RAM of 2 GB and 1 GB is used by OS and 150 MB used by Notepad,250 MB used by Word and 500 MB used by Excel. Now Excel needs another  200 MB then it goes to OS and asks for it if has any free space it allocates or it will inform no memory.(if we have land of 5000 sq feet and it was divided into two as 2000 sq ft and 3000 sq ft and the owner belonging to 3000 sq ft has started constructing it and if he needs any more land he cannot take from 2000 sq ft like was if excel needs any additional memory it cannot take from other process). So in java enterprise edition we have this facility to use the process of other service so we can achieve code reuse  for invoking thse process we use RMI,EJB,JMS and WebServices.
RMI,EJB,JMS use TCP/IP so this can be used in LAN.
 To learn RMI we should know the below
   Naming Service,JNDI,JRMP,Server/Broker,URI,URL,Proxy,Dispatch,Singleton,Marshalling/UnMarshalling)
To learn WebService
 XML,XML Parsing,JAXP,JAXB,SOAP,WSDL

Creation of class
1. new
2. Class.forName
3. clone
4. newInstance
5. classLoader
6. Serilization



If we need jar while compilation from command prompt we can place the jar in current jre/lib/ext.

UpCast and DownCast

class Parent {}
class Child extend Parent {}


Parent pobj=new Child(); // Upcasting

Child cobj = (child)pobj; // DownCasting

Child chdObj= new Parent(); //Invalid Compilation Time Error
Child chdObj=pobj; //Invalid Compilation Time Error
Child chdObj=(Child)new Parent(); //Error class Cast Exception is raised

To avoid ClassCastException we can use instanceOf to identify type of object

Why we use interface in development
To develop dynamic polymorphism and Loosely coupling

Difference between new String("abc") and String str="abc";
When we use String str="abc" then the value is stored in String Constant Pooling(SCP) and this value is used for another String str1="abc" and this is the reason why String is made immutable.

String str=new String("abc") then the value is created in heap and String str1=new String("abc") will also be created in different heap.







Saturday, March 17, 2012

Unix/Linux related Commands

The following commands are used in vi editor

 

 To Display Line number for each Line
        :set number

To remove line number
      :set nonumber

To view all the set options
      :set all

To move the cursor left,right,up,down
       h - Left
       j - down
       l-right
      k-up

To move beginning of the line
      0 (zero)

To move end of the line
       $

To move beginning of next word
     w/W

To move  end of next word
      e/E

To delete current line
       dd

To delete the character under cursor
      x

For multiple deletion

Delete  5 characters : 5x
Delete 10 lines : 10dd



To copy a group of 'n' consecutive lines, use 'yy' and 'p'.

For example, to copy 4 lines (in command mode):

1. Move the cursor to the first line to be copied.
2. '4yy'
3. Move cursor to the destination.
4. 'p'

To view special characters
      :set  list


To find and replace all the occurrence
     : %s/<<actual text>>/<<replace text>>

To have the properties of vi editor to be customized for a user changeor create the file in the home directory

.exrc or .vimrc

The following of few general Commands


To know where is the command
     where is <<command>>

     Eg: where is ls


To know the size of each directory in a given directory
    du -sh *

To know the pervious commands given
     history

To remove all the files and directory and sub directory use the below command (be cautions)
    rm -rf <<directory>>

To zip a directory us the foollowing command
     zip -r <<filename.zip>> <<directory>>

To unzip  the file
     unzip <<filename.zip>>

To identify available shells in your system
     cat  /etc/shells 

To identify the currently used shell
    echo $SHELL

Shell Script can be executed in one of the following way
    bash myscript
    sh myscript
    ./myscript

Note: In the last syntax ./ means current directory, But only . (dot) means execute given command file is current shell without starting the new copy of shell. The syntax for .(dot) commands is as follows


If we want to run a command in background append '&' at the end of command
   du -sh * &

To know about re-directions
    > filename - redirects standard output to the filename - it will overwrite existing files, not append.
    >& filename - redirects standard output and standard error to the filename
    >> filename and >>& filename appends to, rather than overwrites, the file.
    < filename - redirects standard input from the file to the program
    << word - see below for the word
    | - connect the standard output of the prior command/program to the standard input of the subsequent command/program (i.e. a pipe).
    |& - same thing as | but also connects standard error to standard input


We have value for Standard input, output and error
     Stdin    - 0
     Stdout  - 1
     Stderr   - 2

To search the files under sub directories use find command
    find <<directory>> -name "*.java"

To identify the number of processors in Solaris use the following command
  psrinfo

To identify the number of processors in Linux use the following command
  cat /proc/cpuinfo | grep processor  

To identify the  Domain Name or IP address ( In result the first section specifies the server and address of that server that provided you with the domain name and IP address displayed in the second section.)
  nslookup  google.com

To send a process from foreground to background we have the following option to give ctrl + z
and give bg in the nextline

To know the process running in background
ps -ef

To know the process is started and few more details use

top -c

***************************************************

https://linuxize.com/post/less-command-in-linux/

*****************************************************

To create multiple windows/multitask inside putty use the below screen command 

reference : https://www.tecmint.com/screen-command-examples-to-manage-linux-terminals/

screen -ls --> to know the session available or created 
screen -S <<name>> --> To create a session with user defined name 
screen -r <<name>> --> to attach the /activate the session with sepcified name 
cltr+ a and then press d --> to release the session


****************************************************************
https://www.geeksforgeeks.org/netstat-command-linux/

netsat -na | grep -i time_wait | grep -c 29680 --> prod
 
 
***********************************************
 
netstat -tlnp --> gives the port and services which are running   

*****************************************

Package Manager 
https://www.makeuseof.com/tag/power-choice-power-package-management/