Showing posts with label Java Advanced. Show all posts
Showing posts with label Java Advanced. Show all posts

Java J2EE

Java is platform independent, secure, reliable, and robust language which gives developers complete independence from hardware, network, and operating system issues when developing any commercial application. Java is based on Object-Oriented Programming methodology which allows the same program to be executed on multiple operating systems. Java as a language has evolved from C++. Although the Java programming language is usually associated with the World Wide Web, its origin predates the Web. Java began life as the programming language named Oak.

Java was developed by James Gosling and his co-workers at Sun Microsystems in the early 1990s. In 1991, James Gosling began extending the C++ compiler to make it more platform independent. He realized that this approach would not be sufficient and so he developed a new interpreter. This interpreter was named Oak. In January of 1991 James Gosling, Bill Joy, Mike Sheradin, Patric Naughton, and several others met in Aspen, Colorado to discuss this project. Mike Sheradin was to focus on business development; Patrick Naughton was to begin work on the graphics system; and James Gosling was to identify the proper programming language for the project. Gosling thought C and C++ could be used to develop the project. But the problem he faced with them is that they were system dependent languages and hence could not be used on various processors, which the electronic devices might use. So he started developing a new language. This language was called Oak which was registered by some other company, later it was changed to Java. Following table showcases the various versions of java developed over times.

VersionDescriptionCode Name
JDK 1.0Released on January 23, 1996---
JDK 1.1 Released on February 19, 1997---
J2SE 1.2 Released on December 8, 1998Playground
J2SE 1.3 Released on January 8, 2000Kestrel
J2SE 1.4Released on February 6, 2002Merlin
J2SE 5.0 Released on September 30, 2004. This release was originally numbered 1.5Tiger-
Java SE 6 A beta version was released on February 15, 2006Playground

Java platform consists of a Java Virtual Machine and implementations of standard libraries. Sun Microsystems refers to their implementation of the Java platform as the Java Runtime Environment (JRE). There are three version of Java to develop applications.

a) Java Micro Edition (J2ME)
b) Java Standard Edition (J2SE)
c) Java Enterprise Edition (J2EE)

Java Servlets

About Java Servlets

Java Servlets is a server side technology to build internet based comercial applications developed by Sun Microsystems. Servlets are platform independent java technology that run on set of standard interfaces and JVM (Java Virtual Machine). Servlets are built, written in java. Regardless of Servlets written in java, their clients may have written in any languages. Java Servlets provide an object-oriented and extensible middle tier for web server based, distributed java applications. Java Servlets is a technology that can access all of the java APIs such as JDBC, JNDI, RMI, EJB so on.
Web Server itself is not able to dynamically create web page content by pulling data from database. Web Server needs help of Java Servlets to get access to the data table, make accessible for users via internet to the client's browsers. Java Servlets is tied up with HTTP, and commonly referred to HTTP Servlet. Servlets is small portion of java code which is executed at the web Server in response to an HTTP request from a client's Browsers. Servlets can be used as a plug-in for instance a search engine or semi-customized applications such as web-based banking systems.

Java Servlet's work is mostly done behind the scene and not visible to the users. Servlets are run within a Web Server's namespace. Only the results of Servlet's processing such as data from database table which is converted to suit into the html form, are visible to the users via Graphical User Interface (GUI). Java Servlet's life-cycle (created & destroyed) is managed by Servlet Engine (Servlet Container). Servlet Container provies the runtime environment where servlets are executed. Java Servlet is supported by many popular web servers such as Appache, IIS, Netscape so on. Servlets run on server side whereas Applets run only on the Client side java enbled browser.

Java Servlets Work Flow

Servlets always run behind the scene on the Web Server. Servlets provide a framework to create applications that implement a HTML request/response. For intance, a Browser sends a request to the Webserver for HTML page content. The Webserver forward this request to Servlet via its extender software. Servlet processes the request by pulling data from data table, converting them in HTML format, and sending back to the Web Server. Then, Web Server forward the result back to Web Browser who initiated the request for HTML page content, hence displaying result on the GUI.

How to create Servlets

Java Servlets are created just like other java source file on the ASCII Editor. Compiled and run in a Java Virtual Machine.

<filename>.java (Source Code)
MyFirstServlet.java
<filename>.class (Compiled)
MyFirstServlet.class

import java.servlet.*;
public class MyFirstSerlet extends HttpServlet
    {
       public void service(ServletRequest request, ServletResponse response) 
      throws ServletException, IOException
      {
      ...
      }
      ...
   }
The service() method comes with two parameters: request and response. These parameters encapsulate data sent by the Browser client and provide access to parameters and allow Servlets to process result status, including errors.

How to run Servlets

Servlets are run using Web Servers such as Apache in the production environment. The Servlet Engine (Servlet Container) provides runtime environment to Servlets. Servlet Engine come as Standalone and Add-on. Some Web Server support Servlets right out of the box, meaning no need to install Third-party Add-on. This kind of Web Servers are called a Standalone Servlet Engine. Standalone Servlet Engine is a server that includes biult-in support for Servlets. Some example of Standalone Servlet Engines are Oracle Weblogic Application Server or Tomcat Server from Project Jakarta or WebSphere Application Server from IBM so on. On the other hand, Add-On Servlet Engine requires a third party Add-on installed such as Apache do not support Servlets right out of the box.

←Return To Menu

Oracle Weblogic




Learn Java in just 5 weeks...
Creating a WebLogic Domain and Server

In this tutorial you use the WebLogic Server Configuration Wizard to create a domain and server to deploy and run the MedRec applications.The tutorial also shows you how to start the server. The Avitek Medical Records Development Tutorials guide you through the process of developing, packaging, and deploying real-world J2EE applications with WebLogic Server. MedRec is an educational tool for all levels of J2EE developers; it showcases the use of each J2EE component, and illustrates best practice design patterns for component interaction and client development Requirement: Have Weblogic Application server installed of your choice may be weblogic 10 latest version available as of today. Go to this link: Click Here!


Proc 1: Create the MedRec domain and MedRec server.
The MedRec domain includes a single server that will host the MedRec back-end services, the MedRec Administration application, and the Patient application (both applications are Web applications). 1. Launch the Configuration Wizard:
Start—>All Programs—>BEA Products—>Tools—>Configuration Wizard
2. In the Welcome window, select Create a new WebLogic domain.
3. Click Next.
4. In the Select Domain Source window, select the option that begins Generate a domain configured automatically ...
5. Click Next.
6. In the Configure Administrative Username and Password window, enter:
  • weblogic for User Name
  • weblogic for User Password and Confirm user Password
  • An optional description.
7. Click Next. 8. In the Configure Server Start Mode and JDK window, select:
  • Development Mode for WebLogic Domain Startup Mode
  • Sun SDK 1.5.0_XX @ JDK_location, under the BEA Supplied JDKs option, for JDK Selection
9. Click Next. 10. In the Customize Environments and Services Settings window, select Yes. 11. Click Next. 12. In the Configure the Administration Server window, enter or select:
  • MedRecServer for Name.
  • All Local Addresses for Listen Address.
  • 7101 for Listen Port.
  • The SSL Enabled check box.
  • 7102 for SSL Listen Port.
13. Click Next. 14. Select Next in the following windows without making any changes:
  • Configure Managed Servers
  • Configure Machines
15. In the Review WebLogic Domain window, click on MedRecServer in the left pane and review your choices, then click Next. 16. In the Create WebLogic Domain window:
  • Enter MedRecDomain as the Domain Name.
  • Click Create to create the MedRec domain in the folder displayed in the Domain Location text box. When the Configuration Wizard finishes creating the domain, the Domain Created Successfully! message is displayed.
17. Click Done to close the Configuration Wizard.
  • Do not check Start Admin Server.

Proc 2: Enable log4j for logging application messages.

The MedRec application suite uses log4j for logging application messages. You must copy the log4j properties file from the pre-configured MedRec domain and identify it using a startup option in MedRecServer startup script. You also need to copy the log4j jar files to the lib directory of the MedRec domain. To complete these steps: 1. Copy the log4j properties file from the pre-configured MedRec domain (under the main WebLogic Server installation directory) to the new domain you just created. For example, if you installed WebLogic Server in the c:\bea directory, then enter the following in a command-line shell: prompt> copy c:\bea\weblogic91\samples\domains\medrec\log4jConfig.xml c:\bea\user_projects\domains\MedRecDomain

2. Open the setDomainEnv.cmd script, located in the bin directory of your newly created domain directory, for your new domain in a text editor. For example: prompt> notepad c:\bea\user_projects\domains\MedRecDomain\bin\setDomainEnv.cmd

3. Find the following line in the setDomainEnv.cmd script: if NOT "%LOG4J_CONFIG_FILE%"=="" (

4. Add the following two lines immediately before the line specified in the preceding step: set LOG4J_CONFIG_FILE=c:\bea\user_projects\domains\MedRecDomain\log4jConfig.xml for %%i in ("%LOG4J_CONFIG_FILE%") do set LOG4J_CONFIG_FILE=%%~fsi It is assumed in the preceding text that the MedRecDomain directory is c:\bea\user_projects\domains\MedRecDomain; enter your exact domain directory if it is different.

5. Save the file and exit your text editor.

6. Copy the log4j JAR files from the lib directory of the pre-configured MedRec domain to the lib directory of the new domain you just created: prompt> copy c:\bea\weblogic91\samples\domains\medrec\lib\*.jar c:\bea\user_projects\domains\MedRecDomain\lib All JAR files in the lib subdirectory of a domain directory are automatically added to the WebLogic Server system CLASSPATH when the servers in the domain start up.


Java Webservice



Java Webservice Tutorial will be comming soon...

Eclipse Tutorial

Eclipse Tutorial will be comming soon...

Unix/Solaris Basics

Learn Java in just 5 Weeks

---
Unix/Solaris Introduction
Managing File and Directory Goto Week Two Tutorial→ Goto Week Three Tutorial→
Working with Shell
File Archive and Remote transfer
Searching and Process Manipulation

1. UNIX/Solaris Introduction.

UNIX was originally developed in 1969 by AT&T Bell laboratories. It was modified and made distributable by University of California at Berkeley in the Berkeley Software Distribution (BSD) UNIX. Sun's SunOS is also originated from BSD UNIX. Later on AT&T, BSD, and other OS Systems incorporated and developed SVR4 UNIX. SVR4 is the basis of current Sun's SunSolaris.

UNIX comes with three major components: Kernel, Shell, Directory.
Kernel is the core of the any UNIX/SunOS system. It manages physical resources of the computer including CPU, devices, processes, file systems, and memory. Shell is an interface which gives user an access to interact between user and kernel. It is a command interpreter which accepts commands that user enters, interprets those commands and sends them to kernal and it is executed by the kernel and output is dispalyed on the standard output. UNIX including SunSolaris support three major type of shells: Bourne Shell, Korn Shell, and C Shell. The Command-Line Interface (CLI) syntax comprises of:

 command  option(s) arguement(s)
UNIX commands are basically come with the single word such as ls, pwd, date, who, uname so on. Option(s) gives more precise result from the command such as:
ls -l 
where -l options will give list of files and directories with detail informations such as file permission, owner, file size, file names so on.

An argument in the UNIX command will allow to filter or define precise result you want to get such as

ls -l <filename> 
this will allow user to search exact file name he/she wants to display. The CLI allows to enter multiple commands in a signle line by using semicollon seperator such as
ls -ltr <filename>; pwd; 
Shell executes command from left to right.

Few basic commands used in UNIX/SunSolaris.

Command NamesDescription
pwdDetermines current working directory
lsLists files and directories
ls -laLists hidden and detail informaion of the files and directories
ls -ldLists directory without its contents
ls -RLists the content of direcory(s) recursively
ls -FLists the file types
file <filename>Lists the file and directory types
cd <directoryname>Changes directory
cd ..Moving back to parent directory
cd ../..Moving back to multiple level parent directory
cd <directoryname>Relative Path
cd /<directoryname>Absolute Path
cdReturn to Home directory
cd ~Return Home directory
cd /Retrun to root directory
cat <filename>Displays file contents
more <filename>View files one page/screen at a time
head <filename>Displays first 10 line of a file
tail <filename>Displays last 10 lines of a file
wc -w <filename>Counts words of a file
lp <filename>Submit print request
lpstat -option <printer>Displays the status of print request
lp <filename>Submit print request
lp <filename>Submit print request

←Return Menu

2. Managing File and Directory.

Copy, move, and rename files and directories

   $ cp options sources target
   $ cp -i file1 file2
   $ cp -i file1 /home/dir1
   $ pwd
     /export/home/user1
   $ cp -r dir1 dir2
   $ cp -r dir1 ../dir2/dir3
   $ ls ../dir2/dir3
     file1 file2 file3
   $ mv file1 file2 (rename file1 to file2)
   $ mv file1 /export/home/user1 (move file1 to home directory)
   $ mv file1 ~ (move file1 to current directory)
   $ mv dir1 dir2 (move conetent of dir1 to dir2)
   $ mv dir1 newdir (rename directory)
   $ mkdir dir1 dir2 dir3 (create multiple directories)
   $ mkdir dir1/sub_dir1 (create a directory/sub_directory)
   $ rmdir dir1 (delete an empty directory)
   $ rm -r dir1 (delete directory and its files)
   $ touch file1 file2 file3 (create file(s) )
   $ rm -i file1 (delete file1)
Using symbolic links

Symbolic link is a pointer which contains the path name to another directory or file. It is used to link files that are residing in different file system. It helps moving file to new location and provides a easy file name rather than its original name.

   $ ln -s source_file target_file 
   $ ln -s /export/home/user1/file1 file1_link (create symbolic link file)
   $ ls -F file1_link (view symbolic file)
   $ rm file_link (delete symbolic file)
    

VI Editor to create/modify files

VI Editor is command line, interactive text editor which is used to create and modify text (ASCII) files in UNIX system. VI Editor comes with three major modes:

Command Mode
Edite Mode
LastLine Mode
Command Mode helps perform text change, delete, copy, move operation. Importantly, it will allow to search text string by using slash "/" and question mark symbol "?". Edit Mode will allow to add/type text and save the contents. Last Line Mode will allow advanced users to work extensively. Type collon ":" to go to LastLine Mode from the command line mode.

     $ vi filename (create a file in vi editor)
       type i or a to add text in vi editor which takes you to Edit Mode
       press Escape to go to Command Line
       :wq (save and quit the vi editor)
     $ view (view file in read-only mode)    

Key SequencesCursor Movement
i, aadd/append text in Edit Mode
b, wback one word/forward one word
G, 1GLast/First line of the file
Control-F, Control-BOne page forward/backward
-R, rOverrites/Replaces characters
xdelete a character
dddelete a line
/StringSearch string forward
?stringSearch string backward
n, NSearch next occurence
yyYanks a copy of a line
p, Ppaste abpve yanked copy under a line containing the cursor
:wq!Save and Quit from Edit Mode
:q!Quit without saving

Shell Metacharacters and Korn Shell Variables

Korn Shell metacharacters are specific characters, usually symbols which have special meaning to the shell. Metacharacters are catagorized in three parts:
→ Pathname Metacharacter
→ Filename Substitute metacharacter
→ Quota Metacharacter

Pathname Metacharacter simplifies the location changes within the directory structure. Pathname Metacharacter use symbols like Tilde (~) and Dash (-). Tilde "~" represents home directory. Filename substitution metacharacter allows to substitute shell metacharacter for other characters to ease to use commands. Symbols such as Asterisk (*), Question mark (?), Square braket ([]) are used as filename substitution metacharacters. Quota Metacharcter uses symbols such as single quota (' '), or double quota (" "), Back slash(/), dollar sign ($) etc. Quotation mark instructs shell to ignore or mask the all enclosed metacharacters. As we can use following commands to learn more about these Metacharacters.

  $ cd ~/dir1 
  $ pwd
  $ /export/home/user/dir1 
  $ cd - (Navigate to previous directory)
  $ ls *.sh (List all files ending with .sh extension
  $ ls dir? (List all directory dir following one character i.e. dir1, dir2)
  $ ls [a-d]* (List set of files/directories starting with "a" To "d")
  $ (' ') (single forward quot ignore all enclosed metacharacters)
  $ (') (single backward quot execute and display the output)
  $ echo “Date: ‘date ‘”
  $ echo “The user pwd is: $(pwd). "
  $ (" ") (Ignore all except for single backward quot, backslash, and dollar sign)
  $ (\) (Do not interpret next character as metacharacters) 
  $ (& (command) ) (Execute and display output of the command enclosed)
  $ echo $SHELL
    

What is Korn Shell Variables

A temporary storage in memory is referred to a shell variable. Shell allows storage of values in variables. Variables contains information that is needed to function for other processes and it also allows to customize the shell.

Action:Commands
Set a variableVAR=value, export VAR=value
Unset variableunset VAR
Display all variablesset, env, export
Values stored in variableecho $VAR

  
  $ echo $SHELL
  $ set (Display all variables
  $ export (Display variables and thier values
  $ var=value (set variable and assign value)
  $ private=/export/home/private (set a variable private)
  $ unset var (delete the value(s) stored in the variable)
  $ unset private (unset the private variable)
  $ EDITOR, FCEDIT, HOME, LOGNAME, PATH, PS1, PS2, SHELL  (default variables assigned)
  $ echo $EDITOR
  $ PS1 = “$LOGNAME@ ‘uname -n' \$PWD $ ” (Changing value of PS1 variable)
  $ echo $PATH
  $ PATH=$PATH:~ (Extend value of variable PATH)
  $ echo $PATH
  $ history -10
  $ history -r (Display reverse history)    

What is File Descriptor?

File Descriptors work with the processes created by shell. File Descriptor determines where input originated and where output and error message are sent. Three major types of File Descriptors are:

File Des #File Desc AbbriviationDefinition
0stdinStandard Command Input
1stdoutStandard Command Output
2stderrStandard Command Error

What is PIPE (|) command?

Pipe character is used to redirect standard output to the standard input of another command. A pipe character is inserted between two commands. The first command writes the output to the standard output. The second command reads standard output from previous command as standard input. Overall, use of pipe helps to connect multiple commands.

  
  $ < (Read the input from a file)
  $ < <filename>
  $ > (Send output to a file)
  $ ls -ltr > filename (Redirect the list result to a file)
  $ command 2> filename (Redirect the Standard Error to a file)
  $ find /etc -type f -exec grep PASSREQ {} \; -print 2> /dev/null
  $ --Use of Pipe (|) Character
  $ command | command
  $ ls -ltr | wc -w
  $ ps -ef (list all the processes and details)    

View and modify file and directory permissions

There are three type of users in UNIX/Solaris. Owner, Group, and Other. /etc/passwd and /etc/shadow files contain user's permissions. Each type of user has three set of permissions: Read, Write, Execute. First permission set represents owner, second group and third other respectively.

PermissionFile Access
Read (r)View permission
Write (w)write/modify file/directory contents
Execute (e)Execute executable files i.e. shell script

To modify file/directory permssion for users,

chmod
command is used. chmod command will change permssion based on the symbolic mode and octal mode. Symbolic Mode uses combination of letters and symbols to change user's file/directory permissions. Octal Mode uses octal numbers to change the permissions of files and directories. Octal mode consists of three octal numbers from 0-7 which uses comination of numbers for the file/directory permssion.

Octal ValuePermission
4Read
2Write
1Execute

Octal table with combined set of permssions:

Permission SetOctal ValueBinary Value
rwx7111(4+2+1)
rw-6110(4+2+0)
r-x5101(4+0+1)
r--4100(4+0+0)
-wx3011(0+2+1)
-w-2010(0+2+0)
--x1001(0+0+1)
---0000(0+0+0)

This table represents a combined octal values and set of permissions.

Octal ModePermission
777rwxrwxrwx
775rwxrwxr-x
755rwxr-xr-x
644rw-r--r--

  
  $ ls -l filename (view file and directory permission)
  $ -rwx------ (read, write, execute permission for owner)
  $ ls -n (view UIDs and GIDs)
  $ chmod symbolic_mode filename
  $ ls -l file1
  $ chmod o+r file1 (Add read permission for "other" user)
  $ chmod o-r file1 (Remove read permission for "other" user)
  $ chmod octal_mode filename
  $ chmod 755 file1
  $ ls -l file1
  $ umask 027

←Return Menu

3. Working with Shell.

How to manage jobs in Shell?

A job is a process that runs in the shell.

Command SetDescription
jobsList all jobs currently running
bg %135Run current job at the backgroud
fg %135Pull jobs from background to foreground
stops %135Stop a job running at background
sleep 2000 &Running sleep command at background
aliasList all aliases currently running
alias h=historyCreate alias 'h" for history command
alias info='uname -a;id; date'Create alias 'info" for system info
unalias hRemove alias 'h" of history command

What is Function & Options in Korn Shell?

A function is set of ogranized commands which helps perform multiple task quicker and in a efficient ways. For example:the following function "num" creates a function that will help display total number of word counts redirected the output from first command
function num {ls -ltr | wc -w}

Option are referred to "Switches" in which controls the shell's behavior and Options are regarded as boolean value such as true/false or On/Off.

  
  $ typeset -f (display all the current running fuctions)
  $ typeset +f (Display only fuction name)
  $ set -o (view current options)
  $ set -o option_name
  $ set -o noclobber (Turn on noclobber option)
  $ set +o noclobber (Turn Off noclobber option)
  $ ls -l > log (list and redirect the result to log file)  

What is a Shell Script?

Shell Scripts are nothing more than text files which contains UNIX-based commands and comments. This great advantage of script is an ability to automate command sequences such that a script that can be repeatedly used while stopping or starting the system. Hash "#" sign is used to comment text on shell to provide more information about the script. and comments begining with "#" hash sign will be ignored by shell. Kernel reads "#!" first to indentify the program which interpret the line in the script. Shell Scripts are run line by line and users need read and execution permission to be able to run a script

  
  $ # this is comment (comment not read by shell)
  $ ls -ltr # list all the files with long list and permission (command and comments)
  $ chmod u+rx myScript.sh
  $ ./myScript.sh (Run the script) 

Create Conditional Commands if/fi

Shell Script uses variety of conditional commands while creating scripts. Most used conditional commands are:

Conditional Constructs: && and ||
Conditional Commands: if 
Conditional Commands: while
Conditional Commands: case
"&&" conditional construct is used to show that second command will be performed only if precceeding command is successful. For example:
mkdir /export/home/user1 && cd /export/home/user1
In this case, user will navigated to user1 directory only if first command is successfully performed. "||" double pipe is used in script to develop a logic that if first command fails then go and execute second commands such that:
mkdir /export/home/user1 || mkdir /export/home/user2

"if" command is used to evaluate first command, if passes then execute else go to next command and perform the same steps as the previously steps.Syntax to perform if conditional commands is

if expression
then
command1
else
command2
fi

Here is an example how we can perform if else conditional command to test if user has a read "r" permission on /etc/passwd file

$ if test -r /etc/passwd
> then
> echo "You have Read permission on /etc/passwd file"
> else
> echo "Sorry, you don't have Read permission on /etc/passwd file"
> fi
"while" command loops the commands until it meets its condition(s). Syntax to use while command is:
while expression
do
command
done

←Return Menu


4. File Archive and Remote Transfer.

Compressing & Archiving files and directories

By compressing and archiving files and directory will safeguard files and directories in an archive. It can be retrieved if they are accidentally deleted or lost. It can be archived in removable media such as external hard drive, USB Flash drive so on. We use two popular command to archive files and directories.
"tar" command and "jar" command. tar command archives file to and extract file from a single file called tar file. jar command combines multiple files and in addition to that it also compresses files. The following table applies to both tar, and jar commands.

Command SetDescription
xExtract file from tar
vExecute in verbose mode, write to the standard output
fSpecifies the archive file
cCreate a new tar file
tList the table of contents of tar file

  
  $ tar functions archivefile filename(s)
  $ tar cvf mytarfile.tar file1 file2 file3 (archive file1, file2, file3 in mytarfile.tar file)
  $ mt -f /dev/rmt/0 status (check system has tape device mounted)
  $ tar cvf /dev/rmt/0 . (archive everything on tape device from current directory)
  $ cp mytarfile.tar /export/home/user1/dir1 (copy mytarfile.tar to directory dir1)
  $ tar tf /dev/rmt/0 (View content of tar file in tape device)
  $ tar tf mytarfile.tar (view content of the tar files) 
  $ tar xvf /dev/rmt/0 (retrieve/extract tar file from tape device)
  $ tar xvf mytarfile.tar (Extract files from mytarfile.tar)
  $ jar options destination filenames
  $ jar cvf /export/home/user1/bundle.jar * (Archive everything to specified directory)
  $ compress -v mytarfile.tar (compress mytarfile.tar using -v option)
  $ zcat mytarfile.tar.Z (View compressed file)
  $ uncompress -v mytarfile.tar.Z (uncompress mytarfile.tar.Z file)
  $ gzip file1 file2 (compress files using gzip command)
  $ gunzip file1.gz file2.gz (uncompress file using gunzip command)
  $ gzcat file1.gz (view commpressed file)
  $ zip file.zip file1 file2 file3 (compress file1, file2, file3 in file.zip file)
  $ unzip file.zip (extract from file.zip)

Establish Remote login session

Remote login session allows user to access remote host from your current desktop allowing access to use resources in the remote computers. The ~/.rhost file provides user's access authentication for user to access the local host.

  
  $ rlogin hostname
  $ uname -n (View the hostname)
  $ rlogin -l user1 hostname
  $ rlogin host3 (login to remote host to kill the corrupted session)
  $ pkill shell (kill the process remotely)
  $ telnet hostname (Type User/Passwd to remote host)
  $ vncserver options (Accessing X VNC window)
  $ rcp source_file hostname:destination_file
  $ rcp file1 remote_host:/tmp (copy file from localhost to remotehost)
  $ rcp remote_host:/tmp/file1 /export/home/user (copy file1 from remote host to local host)
  $ rcp -r ~/dir1 remote_host:/tmp (copy dir1 directory from local machine to remote machine)
  $ ftp hostname (Create ftp login session at remote_host)
  $ cd (Change the current directory at ftp remote session)
  $ lcd (Change the current directory at local system)
  $ mget (transfer multiple file from remote to local directory)
  $ mput (transfer multiple files from local to remote)
  $ bye (ends the ftp session)
  

←Return Menu

5. Search and Process Manipulation.

Search for content in files and directories

  
  $ grep option pattern filename
  $ grep -n success /home/user1 (search all the lines that contains string "success")
  $ egrep '[a-m]+root' /export/home/user1 (Search string root preceeding letter a to m)
  $ fgrep success *.sh (search string "success" in all files whose extension is .sh)
  $ egrep 'failure| success' file1 (display all the lines that contains either failure or success)
  

Search for files and directories

  
  $ find pathname expression action
  $ find ~ -name file1 (find a file by file name on home directory)
  $ find ~ -name file1 -ok rm {} \; (find a file "file1" and delete it) or
  $ find ~ -name *.sh -exec rm {} \; (find all files with .sh ext and delete them) 
  $ find . -name file1 (find a file "file1" on current directory)
  $ find . -mtime +3 (find files Not modified in last 3 days on current directory)
  $ find ~ -size +20 (find files that is larger than block 20)
  $ find . -mtime +3 (find files Not modified in last 3 days on current directory)
  $ find / -name file1 (find file1 starting from root (/) directory)
  

View and search for a specific process

When one logs in or open an application or run command, UNIX/Solaris systems create processes. It is called a daemon and these provide services and runs on the backgroud. Each process comes with an unique Process Identification called "PID" and which is used by the kernel to manage and track processes. Also, each process includes an User ID "UID" and Group ID "GID" which reflects who owns the process(s). Processes have children processes and child process is executed first than the parent process.

  
  $ ps option(s)
  $ ps -ef | more (display all the current running processes with uid, pid)
  $ ps -e | grep lp (search list of ps and send to grep which searches a text "lp") 
  $ pgrep lp (search process "lp")
  $ ptree 135 (List process in tree hierachy structure following the child processes)
  $ find . -mtime +3 (find files Not modified in last 3 days on current directory)
  $ kill -option PIDs
  $ pkill -option PIDs
  $ kill -9 135
  

Processes respond to signal messages such that if you hit "Control+C", this will send signal 2 which means interrupt the current process. So signal are identified by signal number and thier names. The following table will display some very essential signals, their names, and associated actions:

Signal #Signal NameDefinition
1SIGHUPHang Up or drop terminal conection
2SIGINTInterrupt (Control+C)
9SIGKILLKill processes
15SIGTERMTerminate a process

←Return Menu


Unix/Solaris Advanced

Learn Java in just 5 Weeks

Unix/Solaris Introduction
Managing File and Directory Goto Week Two Tutorial→ Goto Week Three Tutorial→
Working with Shell
File Archive and Remote transfer
Searching and Process Manipulation

1. UNIX/Solaris Introduction.

UNIX was originally developed in 1969 by AT&T Bell laboratories. It was modified and made distributable by University of California at Berkeley in the Berkeley Software Distribution (BSD) UNIX. Sun's SunOS is also originated from BSD UNIX. Later on AT&T, BSD, and other OS Systems incorporated and developed SVR4 UNIX. SVR4 is the basis of current Sun's SunSolaris.

UNIX comes with three major components: Kernel, Shell, Directory.
Kernel is the core of the any UNIX/SunOS system. It manages physical resources of the computer including CPU, devices, processes, file systems, and memory. Shell is an interface which gives user an access to interact between user and kernel. It is a command interpreter which accepts commands that user enters, interprets those commands and sends them to kernal and it is executed by the kernel and output is dispalyed on the standard output. UNIX including SunSolaris support three major type of shells: Bourne Shell, Korn Shell, and C Shell. The Command-Line Interface (CLI) syntax comprises of:

 command  option(s) arguement(s)
UNIX commands are basically come with the single word such as ls, pwd, date, who, uname so on. Option(s) gives more precise result from the command such as:
ls -l 
where -l options will give list of files and directories with detail informations such as file permission, owner, file size, file names so on.

An argument in the UNIX command will allow to filter or define precise result you want to get such as

ls -l <filename> 
this will allow user to search exact file name he/she wants to display. The CLI allows to enter multiple commands in a signle line by using semicollon seperator such as
ls -ltr <filename>; pwd; 
Shell executes command from left to right.

Few basic commands used in UNIX/SunSolaris.

Command NamesDescription
pwdDetermines current working directory
lsLists files and directories
ls -laLists hidden and detail informaion of the files and directories
ls -ldLists directory without its contents
ls -RLists the content of direcory(s) recursively
ls -FLists the file types
file <filename>Lists the file and directory types
cd <directoryname>Changes directory
cd ..Moving back to parent directory
cd ../..Moving back to multiple level parent directory
cd <directoryname>Relative Path
cd /<directoryname>Absolute Path
cdReturn to Home directory
cd ~Return Home directory
cd /Retrun to root directory
cat <filename>Displays file contents
more <filename>View files one page/screen at a time
head <filename>Displays first 10 line of a file
tail <filename>Displays last 10 lines of a file
wc -w <filename>Counts words of a file
lp <filename>Submit print request
lpstat -option <printer>Displays the status of print request
lp <filename>Submit print request
lp <filename>Submit print request

←Return Menu

2. Managing File and Directory.

Copy, move, and rename files and directories

   $ cp options sources target
   $ cp -i file1 file2
   $ cp -i file1 /home/dir1
   $ pwd
     /export/home/user1
   $ cp -r dir1 dir2
   $ cp -r dir1 ../dir2/dir3
   $ ls ../dir2/dir3
     file1 file2 file3
   $ mv file1 file2 (rename file1 to file2)
   $ mv file1 /export/home/user1 (move file1 to home directory)
   $ mv file1 ~ (move file1 to current directory)
   $ mv dir1 dir2 (move conetent of dir1 to dir2)
   $ mv dir1 newdir (rename directory)
   $ mkdir dir1 dir2 dir3 (create multiple directories)
   $ mkdir dir1/sub_dir1 (create a directory/sub_directory)
   $ rmdir dir1 (delete an empty directory)
   $ rm -r dir1 (delete directory and its files)
   $ touch file1 file2 file3 (create file(s) )
   $ rm -i file1 (delete file1)
Using symbolic links

Symbolic link is a pointer which contains the path name to another directory or file. It is used to link files that are residing in different file system. It helps moving file to new location and provides a easy file name rather than its original name.

   $ ln -s source_file target_file 
   $ ln -s /export/home/user1/file1 file1_link (create symbolic link file)
   $ ls -F file1_link (view symbolic file)
   $ rm file_link (delete symbolic file)
    

VI Editor to create/modify files

VI Editor is command line, interactive text editor which is used to create and modify text (ASCII) files in UNIX system. VI Editor comes with three major modes:

Command Mode
Edite Mode
LastLine Mode
Command Mode helps perform text change, delete, copy, move operation. Importantly, it will allow to search text string by using slash "/" and question mark symbol "?". Edit Mode will allow to add/type text and save the contents. Last Line Mode will allow advanced users to work extensively. Type collon ":" to go to LastLine Mode from the command line mode.

     $ vi filename (create a file in vi editor)
       type i or a to add text in vi editor which takes you to Edit Mode
       press Escape to go to Command Line
       :wq (save and quit the vi editor)
     $ view (view file in read-only mode)    

Key SequencesCursor Movement
i, aadd/append text in Edit Mode
b, wback one word/forward one word
G, 1GLast/First line of the file
Control-F, Control-BOne page forward/backward
-R, rOverrites/Replaces characters
xdelete a character
dddelete a line
/StringSearch string forward
?stringSearch string backward
n, NSearch next occurence
yyYanks a copy of a line
p, Ppaste abpve yanked copy under a line containing the cursor
:wq!Save and Quit from Edit Mode
:q!Quit without saving

Shell Metacharacters and Korn Shell Variables

Korn Shell metacharacters are specific characters, usually symbols which have special meaning to the shell. Metacharacters are catagorized in three parts:
→ Pathname Metacharacter
→ Filename Substitute metacharacter
→ Quota Metacharacter

Pathname Metacharacter simplifies the location changes within the directory structure. Pathname Metacharacter use symbols like Tilde (~) and Dash (-). Tilde "~" represents home directory. Filename substitution metacharacter allows to substitute shell metacharacter for other characters to ease to use commands. Symbols such as Asterisk (*), Question mark (?), Square braket ([]) are used as filename substitution metacharacters. Quota Metacharcter uses symbols such as single quota (' '), or double quota (" "), Back slash(/), dollar sign ($) etc. Quotation mark instructs shell to ignore or mask the all enclosed metacharacters. As we can use following commands to learn more about these Metacharacters.

  $ cd ~/dir1 
  $ pwd
  $ /export/home/user/dir1 
  $ cd - (Navigate to previous directory)
  $ ls *.sh (List all files ending with .sh extension
  $ ls dir? (List all directory dir following one character i.e. dir1, dir2)
  $ ls [a-d]* (List set of files/directories starting with "a" To "d")
  $ (' ') (single forward quot ignore all enclosed metacharacters)
  $ (') (single backward quot execute and display the output)
  $ echo “Date: ‘date ‘”
  $ echo “The user pwd is: $(pwd). "
  $ (" ") (Ignore all except for single backward quot, backslash, and dollar sign)
  $ (\) (Do not interpret next character as metacharacters) 
  $ (& (command) ) (Execute and display output of the command enclosed)
  $ echo $SHELL
    

What is Korn Shell Variables

A temporary storage in memory is referred to a shell variable. Shell allows storage of values in variables. Variables contains information that is needed to function for other processes and it also allows to customize the shell.

Action:               Command:
--------             -----------------------------
Set a variable          VAR=value, export VAR=value
Unset variable          unset VAR
Display all variables       set, env, export
Values stored in variable     echo $VAR

  
  $ echo $SHELL
  $ set (Display all variables
  $ export (Display variables and thier values
  $ var=value (set variable and assign value)
  $ private=/export/home/private (set a variable private)
  $ unset var (delete the value(s) stored in the variable)
  $ unset private (unset the private variable)
  $ EDITOR, FCEDIT, HOME, LOGNAME, PATH, PS1, PS2, SHELL  (default variables assigned)
  $ echo $EDITOR
  $ PS1 = “$LOGNAME@ ‘uname -n' \$PWD $ ” (Changing value of PS1 variable)
  $ echo $PATH
  $ PATH=$PATH:~ (Extend value of variable PATH)
  $ echo $PATH
  $ history -10
  $ history -r (Display reverse history)    

What is File Descriptor?

File Descriptors work with the processes created by shell. File Descriptor determines where input originated and where output and error message are sent. Three major types of File Descriptors are:

File Des #       File Desc Abbr             Definitions
---------        -------------------           ---------------
0             stdin               Standard Command Input
1             stdout              Standard Command Output
2             stderr              Standard Command Error
What is PIPE (|) command?

Pipe character is used to redirect standard output to the standard input of another command. A pipe character is inserted between two commands. The first command writes the output to the standard output. The second command reads standard output from previous command as standard input. Overall, use of pipe helps to connect multiple commands.

  
  $ < (Read the input from a file)
  $ < <filename>
  $ > (Send output to a file)
  $ ls -ltr > filename (Redirect the list result to a file)
  $ command 2> filename (Redirect the Standard Error to a file)
  $ find /etc -type f -exec grep PASSREQ {} \; -print 2> /dev/null
  $ --Use of Pipe (|) Character
  $ command | command
  $ ls -ltr | wc -w
  $ ps -ef (list all the processes and details)    

View and modify file and directory permissions

There are three type of users in UNIX/Solaris. Owner, Group, and Other. /etc/passwd and /etc/shadow files contain user's permissions. Each type of user has three set of permissions: Read, Write, Execute. First permission set represents owner, second group and third other respectively.

Permission        File Access
-------------     ---------------
Read (r)       View permission
Write (w)       write/modify file/directory contents
Execute (e)      Execute executable files i.e. shell script
To modify file/directory permssion for users,
chmod
command is used. chmod command will change permssion based on the symbolic mode and octal mode. Symbolic Mode uses combination of letters and symbols to change user's file/directory permissions. Octal Mode uses octal numbers to change the permissions of files and directories. Octal mode consists of three octal numbers from 0-7 which uses comination of numbers for the file/directory permssion.

Octal Value              Permission
------------            ---------------
4                    Read
2                    Write
1                    Execute

Octal table with combined set of permssions:

Permission SetOctal ValueBinary Value
rwx7111(4+2+1)
rw-6110(4+2+0)
r-x5101(4+0+1)
r--4100(4+0+0)
-wx3011(0+2+1)
-w-2010(0+2+0)
--x1001(0+0+1)
---0000(0+0+0)

This table represents a combined octal values and set of permissions.

Octal Mode      Permissions
---------------    ----------------
777          rwxrwxrwx
775          rwxrwxr-x
755          rwxr-xr-x
644          rw-r--r--

  
  $ ls -l filename (view file and directory permission)
  $ -rwx------ (read, write, execute permission for owner)
  $ ls -n (view UIDs and GIDs)
  $ chmod symbolic_mode filename
  $ ls -l file1
  $ chmod o+r file1 (Add read permission for "other" user)
  $ chmod o-r file1 (Remove read permission for "other" user)
  $ chmod octal_mode filename
  $ chmod 755 file1
  $ ls -l file1
  $ umask 027

←Return Menu

3. Working with Shell.

How to manage jobs in Shell?

A job is a process that runs in the shell.

Command SetDescription
jobsList all jobs currently running
bg %135Run current job at the backgroud
fg %135Pull jobs from background to foreground
stops %135Stop a job running at background
sleep 2000 &Running sleep command at background
aliasList all aliases currently running
alias h=historyCreate alias 'h" for history command
alias info='uname -a;id; date'Create alias 'info" for system info
unalias hRemove alias 'h" of history command

What is Function & Options in Korn Shell?

A function is set of ogranized commands which helps perform multiple task quicker and in a efficient ways. For example:the following function "num" creates a function that will help display total number of word counts redirected the output from first command
function num {ls -ltr | wc -w}

Option are referred to "Switches" in which controls the shell's behavior and Options are regarded as boolean value such as true/false or On/Off.

  
  $ typeset -f (display all the current running fuctions)
  $ typeset +f (Display only fuction name)
  $ set -o (view current options)
  $ set -o option_name
  $ set -o noclobber (Turn on noclobber option)
  $ set +o noclobber (Turn Off noclobber option)
  $ ls -l > log (list and redirect the result to log file)  

What is a Shell Script?

Shell Scripts are nothing more than text files which contains UNIX-based commands and comments. This great advantage of script is an ability to automate command sequences such that a script that can be repeatedly used while stopping or starting the system. Hash "#" sign is used to comment text on shell to provide more information about the script. and comments begining with "#" hash sign will be ignored by shell. Kernel reads "#!" first to indentify the program which interpret the line in the script. Shell Scripts are run line by line and users need read and execution permission to be able to run a script

  
  $ # this is comment (comment not read by shell)
  $ ls -ltr # list all the files with long list and permission (command and comments)
  $ chmod u+rx myScript.sh
  $ ./myScript.sh (Run the script) 

Create Conditional Commands if/fi

Shell Script uses variety of conditional commands while creating scripts. Most used conditional commands are:

Conditional Constructs: && and ||
Conditional Commands: if 
Conditional Commands: while
Conditional Commands: case
"&&" conditional construct is used to show that second command will be performed only if precceeding command is successful. For example:
mkdir /export/home/user1 && cd /export/home/user1
In this case, user will navigated to user1 directory only if first command is successfully performed. "||" double pipe is used in script to develop a logic that if first command fails then go and execute second commands such that:
mkdir /export/home/user1 || mkdir /export/home/user2

"if" command is used to evaluate first command, if passes then execute else go to next command and perform the same steps as the previously steps.Syntax to perform if conditional commands is

if expression
then
command1
else
command2
fi

Here is an example how we can perform if else conditional command to test if user has a read "r" permission on /etc/passwd file

$ if test -r /etc/passwd
> then
> echo "You have Read permission on /etc/passwd file"
> else
> echo "Sorry, you don't have Read permission on /etc/passwd file"
> fi
"while" command loops the commands until it meets its condition(s). Syntax to use while command is:
while expression
do
command
done

←Return Menu


4. File Archive and Remote Transfer.

Compressing & Archiving files and directories

By compressing and archiving files and directory will safeguard files and directories in an archive. It can be retrieved if they are accidentally deleted or lost. It can be archived in removable media such as external hard drive, USB Flash drive so on. We use two popular command to archive files and directories.
"tar" command and "jar" command. tar command archives file to and extract file from a single file called tar file. jar command combines multiple files and in addition to that it also compresses files. The following table applies to both tar, and jar commands.

Command SetDescription
xExtract file from tar
vExecute in verbose mode, write to the standard output
fSpecifies the archive file
cCreate a new tar file
tList the table of contents of tar file

  
  $ tar functions archivefile filename(s)
  $ tar cvf mytarfile.tar file1 file2 file3 (archive file1, file2, file3 in mytarfile.tar file)
  $ mt -f /dev/rmt/0 status (check system has tape device mounted)
  $ tar cvf /dev/rmt/0 . (archive everything on tape device from current directory)
  $ cp mytarfile.tar /export/home/user1/dir1 (copy mytarfile.tar to directory dir1)
  $ tar tf /dev/rmt/0 (View content of tar file in tape device)
  $ tar tf mytarfile.tar (view content of the tar files) 
  $ tar xvf /dev/rmt/0 (retrieve/extract tar file from tape device)
  $ tar xvf mytarfile.tar (Extract files from mytarfile.tar)
  $ jar options destination filenames
  $ jar cvf /export/home/user1/bundle.jar * (Archive everything to specified directory)
  $ compress -v mytarfile.tar (compress mytarfile.tar using -v option)
  $ zcat mytarfile.tar.Z (View compressed file)
  $ uncompress -v mytarfile.tar.Z (uncompress mytarfile.tar.Z file)
  $ gzip file1 file2 (compress files using gzip command)
  $ gunzip file1.gz file2.gz (uncompress file using gunzip command)
  $ gzcat file1.gz (view commpressed file)
  $ zip file.zip file1 file2 file3 (compress file1, file2, file3 in file.zip file)
  $ unzip file.zip (extract from file.zip)

Establish Remote login session

Remote login session allows user to access remote host from your current desktop allowing access to use resources in the remote computers. The ~/.rhost file provides user's access authentication for user to access the local host.

  
  $ rlogin hostname
  $ uname -n (View the hostname)
  $ rlogin -l user1 hostname
  $ rlogin host3 (login to remote host to kill the corrupted session)
  $ pkill shell (kill the process remotely)
  $ telnet hostname (Type User/Passwd to remote host)
  $ vncserver options (Accessing X VNC window)
  $ rcp source_file hostname:destination_file
  $ rcp file1 remote_host:/tmp (copy file from localhost to remotehost)
  $ rcp remote_host:/tmp/file1 /export/home/user (copy file1 from remote host to local host)
  $ rcp -r ~/dir1 remote_host:/tmp (copy dir1 directory from local machine to remote machine)
  $ ftp hostname (Create ftp login session at remote_host)
  $ cd (Change the current directory at ftp remote session)
  $ lcd (Change the current directory at local system)
  $ mget (transfer multiple file from remote to local directory)
  $ mput (transfer multiple files from local to remote)
  $ bye (ends the ftp session)
  

←Return Menu

5. Search and Process Manipulation.

Search for content in files and directories

  
  $ grep option pattern filename
  $ grep -n success /home/user1 (search all the lines that contains string "success")
  $ egrep '[a-m]+root' /export/home/user1 (Search string root preceeding letter a to m)
  $ fgrep success *.sh (search string "success" in all files whose extension is .sh)
  $ egrep 'failure| success' file1 (display all the lines that contains either failure or success)
  

Search for files and directories

  
  $ find pathname expression action
  $ find ~ -name file1 (find a file by file name on home directory)
  $ find ~ -name file1 -ok rm {} \; (find a file "file1" and delete it) or
  $ find ~ -name *.sh -exec rm {} \; (find all files with .sh ext and delete them) 
  $ find . -name file1 (find a file "file1" on current directory)
  $ find . -mtime +3 (find files Not modified in last 3 days on current directory)
  $ find ~ -size +20 (find files that is larger than block 20)
  $ find . -mtime +3 (find files Not modified in last 3 days on current directory)
  $ find / -name file1 (find file1 starting from root (/) directory)
  

View and search for a specific process

When one logs in or open an application or run command, UNIX/Solaris systems create processes. It is called a daemon and these provide services and runs on the backgroud. Each process comes with an unique Process Identification called "PID" and which is used by the kernel to manage and track processes. Also, each process includes an User ID "UID" and Group ID "GID" which reflects who owns the process(s). Processes have children processes and child process is executed first than the parent process.

  
  $ ps option(s)
  $ ps -ef | more (display all the current running processes with uid, pid)
  $ ps -e | grep lp (search list of ps and send to grep which searches a text "lp") 
  $ pgrep lp (search process "lp")
  $ ptree 135 (List process in tree hierachy structure following the child processes)
  $ find . -mtime +3 (find files Not modified in last 3 days on current directory)
  $ kill -option PIDs
  $ pkill -option PIDs
  $ kill -9 135
  

Processes respond to signal messages such that if you hit "Control+C", this will send signal 2 which means interrupt the current process. So signal are identified by signal number and thier names. The following table will display some very essential signals, their names, and associated actions:

Signal #        Signal Name          Definition 
--------        --------------        ----------------------    
1            SIGHUP         Hang Up or drop terminal conection 
2            SIGINT         Interrupt (Control+C)   
9            SIGKILL        Kill processes 
15           SIGTERM        Terminate a process       

←Return Menu


Hyper Text Markup Language



HTML/XML Tutorial will be comming soon...

Cascading Style Sheet



Learn Java in just 5 weeks

CSS stands for Cascading Style Sheets. In web development, Cascading Style Sheets (CSS) is a stylesheet language used to control the layout of web pages. Its most common application is to style web pages written in HTML and XHTML, but the language can be applied to any kind of XML document, including SVG and XUL. CSS is used to help readers of web pages to define colors, fonts, layout, and other aspects of document presentation.

Style Sheet are simply text file (.css) compose of lines that tells browsers how to display a html page. It is designed primarily to enable the separation of document content (written in HTML or a similar markup language) from document presentation (written in CSS). This separation can improve content accessibility, provide more flexibility and control in the specification of presentation characteristics, and reduce complexity and repetition in the structural content.
In CSS, a style is a grouping of different properties given a common name. If you were to re-create this paper for the web, you could define styles for the text on your title page, outline page, and so on. For example, you can create a style called myHeadings and specify its font properties to be bold and have a font-size of 14pt. A specification of a property is known as a rule. With a style established, whenever you type in text for a my heading, you can set it to the myHeading style and all of that style's properties are applied to the selected text in one step. Later, if you decide to change the font color or some other aspect of the style, you can just change its definition or specification in the style sheet and the appearance of all text marked with that style will change throughout the webpage or website.

OTN Discussion Forums: Message List - Database - General

Ask Tom HOT ARTICLES

 
© Copyright 2008 - 2011. All rights reserved to dba-sansar.blogspot.com.
All other blogs, posts and entries are the property of their respective authors.
Please email us for your comments and suggessions Click Here