<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4357047353136420609</id><updated>2024-09-05T10:07:25.650-07:00</updated><category term="Java"/><category term="Database"/><category term="JDK 7 Features"/><category term="Databse"/><category term="Hibernate"/><category term="Websites"/><title type='text'>Java Boots</title><subtitle type='html'>Java articles for developers</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>20</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-8138210230396741935</id><published>2019-08-17T18:33:00.000-07:00</published><updated>2019-08-17T18:33:39.906-07:00</updated><title type='text'>AWS Notes of training</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Listing some notes from my learning. I hope it is useful for everybody.&lt;br /&gt;
&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;AWS is a secure cloud service platform offering computation power, database storage, content delivery and other useful functionalities that help the business to scale.&lt;/li&gt;
&lt;li&gt;We have different domains in AWS:&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;Compute (EC2, Light Sails, Lamda)&lt;/li&gt;
&lt;li&gt;Storage (Disk, SSD) : S3 low cost storage&lt;/li&gt;
&lt;li&gt;Database (SQL/NoSQL): RDS&lt;/li&gt;
&lt;li&gt;Network and Content delivery: Route53 (DNS system)&lt;/li&gt;
&lt;li&gt;Management Tools: Manage AWS services (Cloud Watch)&lt;/li&gt;
&lt;li&gt;Security and Identity Compliance: &quot;Iam&quot; accounts (authenticate user access to AWS )&lt;/li&gt;
&lt;li&gt;Messaging: Email Service, PubSub,&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Migration (Transfer GB of data to AWS. Snowball (sending physical data to AWS)&amp;nbsp; )&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;AWS Compute Services:&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;EC2: Raw server configured to anything&lt;/li&gt;
&lt;li&gt;Lamda: To host background tasks and not hosting. Listen to triggers and execute the code.&lt;/li&gt;
&lt;li&gt;Elastic Beanstalk: Advanced of EC2. Here we don&#39;t need to set up the env manually. You select what you need and AWS installs every s/w require for you like java, tomcat, load balance, and Nginx. One needs to upload the code and its autoscale depends on autoscale settings.&lt;/li&gt;
&lt;li&gt;Elastic Load Balancer: Distribute the workload on deployed resources.&lt;/li&gt;
&lt;li&gt;Autoscaling: Scale up the infra automatically. say if CPU usage above 70%, launch a new server.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;AWS Storage Domain&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;S3: Object-Oriented File System. All files are treated as objects and stored in a bucket(folder). Root has to be a bucket and upload files (object)&lt;/li&gt;
&lt;li&gt;CloudFront: Content delivery Network&lt;/li&gt;
&lt;li&gt;Elastic Block Storage: Hard Drive to EC2. EC2 is backed by EBS volumes. One EBS instance can be connected to one EC2 instance, just like 1 HDD connect to one computer.&lt;/li&gt;
&lt;li&gt;Glacier: A Data archiving server (magnet tapes). Data which is not frequently used. Retrieval time is more but cheap.&lt;/li&gt;
&lt;li&gt;Snowball: Transferring data to AWS and back from the AWS server using the SNOWBALL device. Use case transfer petabyte of data as physically transferring data.&lt;/li&gt;
&lt;li&gt;Storage Gateway: Provides on-premise servers access to virtually unlimited cloud storage. Move tape backups to cloud, provide backup dB files and pure files, AWS data sync.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;AWS Database Service&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;RDS: Relation DB mgmt service (Oracle, Mysql, MariaDB, SQL Server, Amazon aurora). Updates DB engines, install security patches automatically&lt;/li&gt;
&lt;li&gt;Aurora: DB developed by Amazon&lt;/li&gt;
&lt;li&gt;DynamoDB: Mgmt service for Non-relational DB (NO SQL). It&#39;s a NoSQL DB which managed automatically. If more data comes, DB automatically scales.&lt;/li&gt;
&lt;li&gt;Elastic Cache: Amazon ElastiCache offers fully managed&amp;nbsp;&lt;a href=&quot;https://aws.amazon.com/redis/&quot; style=&quot;box-sizing: border-box; color: #005b86; font-family: AmazonEmberLight, &amp;quot;Helvetica Neue Light&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; outline: 0px; text-decoration-line: none;&quot;&gt;Redis&lt;/a&gt;&lt;span style=&quot;color: #333333; font-family: AmazonEmberLight, &amp;quot;Helvetica Neue Light&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px;&quot;&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://aws.amazon.com/memcached/&quot; style=&quot;box-sizing: border-box; color: #005b86; font-family: AmazonEmberLight, &amp;quot;Helvetica Neue Light&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; outline: 0px; text-decoration-line: none;&quot;&gt;Memcached&lt;/a&gt;&lt;span style=&quot;color: #333333; font-family: AmazonEmberLight, &amp;quot;Helvetica Neue Light&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px;&quot;&gt;. Seamlessly deploy, run, and scale popular open source compatible in-memory data stores&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Redshift: Data Warehouse service(Analytics). Data fed from RDS, DynamoDB and do analysis.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;AWS Networking Service&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;VPC: Virtual Private Cloud. If AWS instance is configured for 1 VPC, so all instances/resources are visible to each other and can interact. Provide security and communication made easy.&lt;/li&gt;
&lt;li&gt;Direct Connect: It&#39;s a leased line which you can directly connect to AWS. Instead of the internet, we can direct connect service.&lt;/li&gt;
&lt;li&gt;Route 53: is a DNS. Redirect traffic from URL to IP address&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;AWS Management Services&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;CloudWatch: Monitoring tool to monitor AWS resources. Creates an alarm.&lt;/li&gt;
&lt;li&gt;CloudFormation: used to templatize the AWS infra.&lt;/li&gt;
&lt;li&gt;CloudTrail: is a logging service backed by S3&lt;/li&gt;
&lt;li&gt;CLI: CLI tool for AWS&lt;/li&gt;
&lt;li&gt;OpsWorks: A configuration mgmt tool. Layers and stack.&lt;/li&gt;
&lt;li&gt;TrustedAdvisor: is a personal advisor in the AWS. Advises on certain best practices, Iam policies.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;AWS Security Service&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;IAM: Identification and Authentication Mgmt tool.&lt;/li&gt;
&lt;li&gt;KMS: Key Mgmt Service: Public key with AWS and user log in with the private key.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;AWS Application Services&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;SES: Simple Email Service. Manage auto-reply.&lt;/li&gt;
&lt;li&gt;SQS: Simple queue service. The server reads the queue and executes them.&lt;/li&gt;
&lt;li&gt;SNS: Simple notification service to send notification to related AWS service.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;AWS Pricing&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;Pay as you Go: Pay what you use&lt;/li&gt;
&lt;li&gt;Pay less by using more: Bills you for the hour&lt;/li&gt;
&lt;li&gt;Save when you reserve: Reserving your instance for specific time frame.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ol&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;/ol&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/8138210230396741935/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2019/08/aws-notes-of-training.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/8138210230396741935'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/8138210230396741935'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2019/08/aws-notes-of-training.html' title='AWS Notes of training'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-1513099884484320087</id><published>2013-05-02T06:22:00.000-07:00</published><updated>2013-05-02T06:22:23.419-07:00</updated><title type='text'>How generics can be used in Class Factories</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Lets see how generics can be used to create generic interface for class factories.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public class GenericFactory &amp;lt;E&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Class&amp;lt;E&amp;gt; thisClass=null;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public GenericFactory (Class iclass)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;this.thisClass = iclass;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public E createInstance() throws IllegalAccessException,InstantiationException{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return(E)this.thisClass.newInstance();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The &amp;lt;E&amp;gt; is a type token that signals that this class has a type set when instantiated.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public class Myclass {&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;void print()&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;Hellooo&quot;);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public class Main {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static void main(String[] args) throws IllegalAccessException, InstantiationException {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;GenericFactory&amp;lt;Myclass&amp;gt; factory = new GenericFactory&amp;lt;Myclass&amp;gt;(Myclass.class);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Myclass myclass= factory.createInstance();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;myclass.print();&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;u style=&quot;font-weight: bold;&quot;&gt;Output:-&lt;/u&gt;&amp;nbsp;&amp;nbsp;Hellooo&lt;br /&gt;
&lt;br /&gt;
We can see that, it is not necessary to cast the object returned from the factory.createInstance().&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/1513099884484320087/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2013/05/how-generics-can-be-used-in-class.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/1513099884484320087'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/1513099884484320087'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2013/05/how-generics-can-be-used-in-class.html' title='How generics can be used in Class Factories'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-5662223510579814598</id><published>2013-05-02T06:00:00.002-07:00</published><updated>2013-05-02T06:00:23.393-07:00</updated><title type='text'>When to use getClass() and instanceOf in Java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;b&gt;getClass()&lt;/b&gt; only gives equality if two objects belong to same class whereas &lt;b&gt;instanceOf works for subtype also.&lt;/b&gt;&lt;div&gt;
&lt;div&gt;
If two objects of different classes are checked for equal, then we use instanceOf . But once you use instanceOf at some level in the class hierarchy everything below it must use instanceOf or you will violatate the symmetry clause of equals contract.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
e.g. any list can be equal to any list as long they have same elements iun the same order. So any List implementation equals() method must do instanceOf and not getclass() and then compare.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
On the other hand, it only make sense for na instance of class X to be equal to another instance of class X ( and not any subclass ) , then use getClass().&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/5662223510579814598/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2013/05/when-to-use-getclass-and-instanceof-in.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/5662223510579814598'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/5662223510579814598'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2013/05/when-to-use-getclass-and-instanceof-in.html' title='When to use getClass() and instanceOf in Java'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-1989518884209008497</id><published>2013-04-30T10:31:00.003-07:00</published><updated>2013-04-30T10:31:45.387-07:00</updated><title type='text'>Java Interview Points</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Java Interview Points&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Uses of finalizer :-&amp;nbsp;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;It acts as a safety net. It may be better to free the resources than never e.g. FileInputStream, Connection etc.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Object with native peers, the garbage collector doesn&#39;t know about it when it reclaimed the java peer. If native peer hold some critical resources, we can use this method to free the resources.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;Clone will not work if the array fields are final because clone would be prohibited from assigning a new value to the field.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;A method in an interface can’t be native, synchronized, strictfp but in the implementation class it can be since these keywords describe implementation properties rather than interface properties. Same is true for final.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Only data associated with specific instances of a class is serialized, because static data is associated with a class as opposite to an instance, so it’s not serialized automatically. To serialize static data, one must provide class specific serialization.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Array implementation in Java: - Java treats an array as an object. When we declare an array as&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; long[] temp = new long[10] ;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; the jvm creates a long[] class with temp as its object.  When we print the name as &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SOP(temp.getClass().getName()), it prints&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;[J&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Definition of this class is:&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public abstract final class [J extends java.lang.Object implements Cloneable,Serilizable {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;6 . Abstract class constructors are frequently used to enforce class constraints as invariants such as: &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;minimum fileds requiredto set up the class.&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; 7. The foreach loop can be applied to any Object that implements Iterable&amp;lt;E&amp;gt; which in turn refers to &amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Iterator&amp;lt;E&amp;gt;. Methods Iterstor, hasNext, next which are used by during the transalation of the loop.&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 8. The &amp;lt; ? extends Animal&amp;gt; means that you can take any subtype of animal, the subtype can be either a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sublass of a class (Abstract or concrete) or a type that implemetsthe interface after the word extends. &amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Also, it can be assigned a collection that is subtype of Animal or anything that extends &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Animal and I promise that I will not add into the collection.&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;9. List&amp;lt;? &amp;gt; means that it can support any type but does not support Add.&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; 10. You cannot put anything into a type declared with extends wildcard except for values as NULL,&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;which belongs to every ref type.&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; 11.&amp;nbsp;Extends wildcard does not ensure immutability since we can still add null to it. Also you can remove, &amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; remove all, retain swap, shuffle etc.&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; 12. Get and Put Principle tells us that if a structure contains a wildcard, we should get the values of it(if it &amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; extends wildcard) or put values into it (if it is super wildcard). For a strucutr to be usefull, we must do &amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; both.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;e.g List &amp;lt;Number&amp;gt; nums = new ArrayList&amp;lt;Number&amp;gt;();&lt;br /&gt;&lt;br /&gt;List&amp;lt;? Super Number&amp;gt; sink = number   // put&lt;br /&gt;&lt;br /&gt;List&amp;lt;? Extends Number&amp;gt; source = nums; //get&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;/ol&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/1989518884209008497/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2013/04/java-interview-points.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/1989518884209008497'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/1989518884209008497'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2013/04/java-interview-points.html' title='Java Interview Points'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-7882180422860531748</id><published>2013-04-12T11:29:00.001-07:00</published><updated>2013-04-12T11:29:21.880-07:00</updated><title type='text'>Why we have Runtime Exceptioons in Java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;a href=&quot;http://docs.oracle.com/javase/tutorial/essential/exceptions/definition.html&quot; target=&quot;_blank&quot;&gt;Oracle &lt;/a&gt;&amp;nbsp;defines Exception as&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&quot;An&amp;nbsp;&lt;em&gt;exception&lt;/em&gt;&amp;nbsp;is an event, which occurs during the execution of a program, that disrupts the normal flow of the program&#39;s instructions.&quot;&lt;br /&gt;
&lt;br /&gt;
We have three&amp;nbsp;categories of exception as:-&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Checked Exceptions&lt;/u&gt;&lt;/b&gt; , which are subject to catch .&amp;nbsp;All exceptions are checked exceptions, except for those indicated by&amp;nbsp;&lt;code&gt;Error&lt;/code&gt;,&amp;nbsp;&lt;code&gt;RuntimeException&lt;/code&gt;, and their subclasses&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Runtime Exceptions&lt;/u&gt;&lt;/b&gt; are internal to the application and system does not expect to recover from. NullPointerException is type of RunTime Exception&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Error &lt;/u&gt;&lt;/b&gt;are exceptions which are external to applications like OutOfMemory Exception, StackOverFlow Exception.&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;br /&gt;
The class diagram of Exception is as follows:-&lt;br /&gt;
&lt;img alt=&quot;Java Exceptions&quot; src=&quot;http://www.tutorialspoint.com/images/exceptions.jpg&quot; /&gt;&lt;br /&gt;
This discussion is regarding why we have Runtime type of exceptions in Java.&lt;br /&gt;
&lt;br /&gt;
When exception was first designed, there was worry about conditions that occur because of&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;problems with the machine on which the program being run&lt;/li&gt;
&lt;li&gt;bugs in VM&amp;nbsp;&lt;/li&gt;
&lt;li&gt;security violations.&lt;/li&gt;
&lt;/ul&gt;
These sort of things can occur any time. But it would only clutter up the language to require every method declare that it can throw an exception for these reasons.&lt;br /&gt;
Generally, it would not be the method that throw such an exception, it would be the underlying VM. &amp;nbsp;It would just make the code longer and less robust &amp;nbsp;To clear this , a special sort of exception, called RunTime Exception was build into the Java. Since RunTimeException can be thrown any time and need not to be declared as part of method signature.&lt;br /&gt;
&lt;u style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/u&gt;
&lt;u style=&quot;font-weight: bold;&quot;&gt;Use:&lt;/u&gt;&amp;nbsp;Sometime in the midst of writing the&amp;nbsp;implementation&amp;nbsp; programmer discovers that there is an exception condition&amp;nbsp;that&amp;nbsp;hadn&#39;t&amp;nbsp;thought in the original design. One way , is to&amp;nbsp;declare&amp;nbsp;the exception as Exception as subclass of Runtime Exception. That way, one need not to change the calling code.&lt;br /&gt;
But , it will result more work and headache in future, when you try to find out why system is failing, Since it not mandate to catch.....&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/7882180422860531748/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2013/04/why-we-have-runtime-exceptioons-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/7882180422860531748'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/7882180422860531748'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2013/04/why-we-have-runtime-exceptioons-in-java.html' title='Why we have Runtime Exceptioons in Java'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-8013560389986016972</id><published>2012-08-24T13:50:00.001-07:00</published><updated>2012-08-24T13:50:25.385-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Database"/><title type='text'>How class.forName loads the Database Driver in JDBC</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
When Class.forName() is called with an argument like this:&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;&lt;br /&gt;
&lt;code&gt;Class.forName(&quot;org.gjt.mm.mysql.Driver&quot;);&lt;/code&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
the classloader attempts to load and link the &lt;code&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;Driver&lt;/span&gt;&lt;/code&gt; class in the “org.gjt.mm.mysql” package and if
successful, the static initializer is run. The MySQL &lt;code&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;Driver&lt;/span&gt;&lt;/code&gt; static initializer looks like
this:&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;&lt;br /&gt;
&lt;code&gt;static {&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;&amp;nbsp;try {&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;java.sql.DriverManager.registerDriver(new
Driver());&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;&amp;nbsp;} catch (SQLException E) {&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;throw new RuntimeException(&quot;Can&#39;t register
driver!&quot;);&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;&amp;nbsp;}&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;}&lt;/code&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
So it calls a static method in the &lt;a href=&quot;http://java.sun.com/j2se/1.4.2/docs/api/java/sql/DriverManager.html&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;java.sql.DriverManager&lt;/span&gt;&lt;/a&gt;
class which apparently registers a copy of itself when it loads.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;To understand the why you have to
look at the next line in the initial code example:&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;&quot;&gt;&lt;br /&gt;
&lt;code&gt;Connection con = DriverManager.getConnection(url,&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;&amp;nbsp;&quot;myLogin&quot;, &quot;myPassword&quot;);&lt;/code&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
The &lt;code&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;DriverManager&lt;/span&gt;&lt;/code&gt; class
returns a database connection given a JDBC URL string, a username and a
password. In order to create that connection, the DriverManager class has to
know which database driver you want to use. It does that by iterating over the
array (internally a Vector) of drivers that have registered with it (ie: the &lt;code&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;registerDriver(Driver driver)&lt;/span&gt;&lt;/code&gt; method
illustrated above) and calls the &lt;code&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;acceptsURL(url))&lt;/span&gt;&lt;/code&gt;
method on each driver in the array, effectively asking the driver to tell it
whether or not it can handle the JDBC URL. &lt;br /&gt;
&lt;br /&gt;
First the &lt;code&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;DriverManager&lt;/span&gt;&lt;/code&gt;
tries to use each driver in the order it was registered. (The drivers listed in
&lt;code&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;jdbc.drivers&lt;/span&gt;&lt;/code&gt; are always
registered first.) It will skip any drivers that are untrusted code unless they
have been loaded from the same source as the code that is trying to open the
connection. &lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.blogger.com/null&quot; name=&quot;998422&quot;&gt;&lt;/a&gt;It tests the drivers by calling the method &lt;code&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;Driver.connect&lt;/span&gt;&lt;/code&gt; on each one in turn,
passing them the URL that the user originally passed to the method &lt;code&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;DriverManager.getConnection&lt;/span&gt;&lt;/code&gt;. The first
driver that recognizes the URL makes the connection. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin: 0in 0in 10pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;All &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;DriverManager&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;
methods are declared &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;, which means that they operate on the class as a whole
rather than on particular instances. In fact, the constructor for &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;DriverManager&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt; is declared &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;private&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt; to
prevent users from instantiating it. Logically, there is one instance of the &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;DriverManager&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt; class. &lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/8013560389986016972/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2012/08/how-classforname-loads-database-driver.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/8013560389986016972'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/8013560389986016972'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2012/08/how-classforname-loads-database-driver.html' title='How class.forName loads the Database Driver in JDBC'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-8228834396044321782</id><published>2012-06-22T01:47:00.001-07:00</published><updated>2012-07-18T04:27:57.968-07:00</updated><title type='text'>Problems on Bit Manipulations</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;strong&gt;&lt;u&gt;Check if two numbers have opposite sign&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #7f0055; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #7f0055; font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div align=&quot;left&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;We can use the operation &lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;left&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;strong&gt;if&amp;nbsp;&amp;nbsp;&amp;nbsp; (x ^ y) &amp;lt; 0&lt;/strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where x and y are non zero numbers&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;left&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div align=&quot;left&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;{&amp;nbsp; True&amp;nbsp;&amp;nbsp; --- if numbers of opposite sign&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;left&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;{&amp;nbsp; False&amp;nbsp; --- if numbers of same sign&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;left&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div align=&quot;left&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;int&lt;strong&gt;&amp;nbsp;&lt;em&gt; &lt;/em&gt;&lt;/strong&gt;&lt;span style=&quot;color: black;&quot;&gt;x=-10,y=2;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;System.out&lt;span style=&quot;color: black;&quot;&gt;.println(((x ^ y) &amp;lt; 0));&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Output &lt;/u&gt;:-&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;False&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;strong&gt;Check if number is power of 2&lt;/strong&gt;&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;We can use&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;strong&gt;x &amp;amp; (x - 1)) == 0&lt;/strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; True&amp;nbsp;&amp;nbsp; --- if numbers is a power of 2&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; False&amp;nbsp; --- if numbers is not a power of 2&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div align=&quot;left&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;int&amp;nbsp; x=16;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;color: black;&quot;&gt;System.out.println((x &amp;amp; (x - 1))==0);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;em&gt;&lt;/em&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;strong&gt;&lt;u&gt;Output &lt;/u&gt;:-&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;True&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;More bitwise tricks&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
x&amp;amp;(x-1)&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;:---------------- Returns number x with the lowest bit set off&lt;br /&gt;
x ^ ( x &amp;amp; (x-1 ) &amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;:----------------&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Returns the lowest bit of a number x&lt;/span&gt;&lt;br /&gt;
x &amp;amp; 1&amp;lt;&amp;lt;n&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;:---------------- &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Returns 1&amp;lt;&amp;lt;n if the n-th bit is set in x&lt;/span&gt;&lt;br /&gt;
x | 1&amp;lt;&amp;lt;n&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;:---------------- &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Returns the number x with the n-th bit set&lt;/span&gt;&lt;br /&gt;
x ^ 1&amp;lt;&amp;lt;n&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;:---------------- &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Toggles the state of the n-th bit in the number x&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Displaying all subsets of a subset.&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Consider a number 10110&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Required&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;Output :-&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
00000&lt;br /&gt;
00010&lt;br /&gt;
00100&lt;br /&gt;
00110&lt;br /&gt;
10000&lt;br /&gt;
10010&lt;br /&gt;
10100&lt;br /&gt;
10110&lt;br /&gt;
&lt;br /&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;Algorithm&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
start&lt;br /&gt;
&amp;nbsp; &amp;nbsp; N; //an integer&lt;br /&gt;
&amp;nbsp; &amp;nbsp; X = N&lt;br /&gt;
&amp;nbsp; &amp;nbsp; while true&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print X&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if( X == 0 )&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X = (X-1) &amp;amp; N;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; end while&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/8228834396044321782/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2012/06/problems-on-bit-manipulations.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/8228834396044321782'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/8228834396044321782'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2012/06/problems-on-bit-manipulations.html' title='Problems on Bit Manipulations'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-7841946140505470553</id><published>2012-06-03T12:13:00.000-07:00</published><updated>2012-06-03T12:13:42.574-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Immutability in java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
In Java, Object can be of two types :-&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Mutable&lt;/li&gt;
&lt;li&gt;Immutable&lt;/li&gt;
&lt;/ol&gt;
&lt;b&gt;Mutable objects&lt;/b&gt; are the ones whose state can be changes during its lifetime. This is in contrast with &lt;b&gt;Immutable objects&lt;/b&gt;, whose state cannot be changed once created. We have many classes in Java which provide immutable objects like String, Integer etc. In this post, I will discuss the immutability in detail, with its features and where can we use this.&lt;br /&gt;
&lt;br /&gt;
In basic terms, Immutable objects are the ones, whose state cannot be changed.e.g&lt;br /&gt;
&lt;br /&gt;
Integer i = new Integer(10) ;&lt;br /&gt;
&lt;br /&gt;
The &lt;b&gt;Integer &lt;/b&gt;class provides us no method which can change the state/value of i. So we say Integer is an immutable class &amp;amp; object i is an immutable object.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;We have many benefits for it:&lt;/b&gt;-&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;&lt;u&gt;They are good candidates to cache&lt;/u&gt;&lt;/b&gt; :- Since immutable objects do not change their state, we can share or cache them and retrieve them in future, without copying and cloning the object. &lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;u&gt;Solid keys&lt;/u&gt;&lt;/b&gt; :- Immutable objects makes the best keys for Hash classes. HashCode() method depends on the state variables. In case of immutable, state is consistent, the key would always return the same value. For mutable, if state changes after storing in Hash class, the hash algorithm gets confused and will return the wrong or null value.&lt;/li&gt;
&lt;li&gt;&lt;u&gt;&lt;b&gt;Provides Thread Safety&lt;/b&gt;&lt;/u&gt; :-&amp;nbsp; In muti-threaded applications, Many issues arises due to read-write conflicts. Say, one thread going to read a object state while other simultaneously changes the state OR two threads want to write a value at the same time. To prevent this, either we use synchronize the access or can use locks, to prevent object from an inconsistent state. Its not advisable to synchronize everything as it may affect the concurrency. Here we can use &lt;b&gt;Immutable objects&lt;/b&gt; that can be shared between threads. Since their state cannot be changed, they can used without any synchronization and simplify the writing, documentation and helps in reducing potential concurrent errors.&lt;/li&gt;
&lt;/ul&gt;
&lt;b&gt;Everything not come as free and So as immutability. Follows are its drawbacks&lt;/b&gt; :-&lt;/div&gt;
&lt;div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Creating a lot immutable objects will have impact on the memory and may result in frequent GC. One way to avoid this is use Flyweight pattern for sharing objects whenever required. &lt;/li&gt;
&lt;li&gt;Since the class is final and so as the methods, which prevent to &lt;b&gt;scale the class.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;b&gt;How to create a perfect Immutable class&lt;/b&gt;:-&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Class declared as final&lt;/li&gt;
&lt;li&gt;All of its fields are final and private&lt;/li&gt;
&lt;li&gt;&lt;i&gt;this&lt;/i&gt; reference is not allowed to escape during construction.&lt;/li&gt;
&lt;li&gt;If fields contains mutable objects like arrays,collections then they&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;should marked private&lt;/li&gt;
&lt;li&gt;should never return or expose to callers&amp;nbsp;&lt;/li&gt;
&lt;li&gt;should not provide methods to change state&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;b&gt;One Imp Note&lt;/b&gt;:&amp;nbsp; If a class is final. then all its methods are implicitly final as well and the method is guaranteed not to be over-ridden as well. &lt;/div&gt;
&lt;div&gt;
&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;b&gt;When to use Immutable Classes&lt;/b&gt; :- &lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Ideal for defining abstract data types like Integer, BigDecimal, DaysOfWeek, Colors.&lt;/li&gt;
&lt;li&gt;When your object needs security from outside interference. One way hacker use to control your class is by subclassing your class and access your private data and methods. Sting class is final for this reason.&lt;/li&gt;
&lt;li&gt;Depends on the application like how often the objects would change (defines the synchonization level). If they change, would it meant something for the application. Application is single threaded or multi-threaded.&lt;/li&gt;
&lt;/ul&gt;
In case of doubts or corrections, please post a comment. In my future post, I will discuss how to use arrays in immutable class. &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/7841946140505470553/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2012/06/immutability-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/7841946140505470553'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/7841946140505470553'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2012/06/immutability-in-java.html' title='Immutability in java'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-7775540121263951693</id><published>2012-05-04T07:51:00.000-07:00</published><updated>2012-05-04T07:54:17.467-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Generate Heap Dump in Unix</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Heap dump provides the&amp;nbsp;insight&amp;nbsp;into the JVM - shows live objects on the heap (reachable and unreachable) along with their types and values. In addition it also&amp;nbsp;provides&amp;nbsp;no of objects and their size as %age of total heap size.We have many ways to get the heap dump in Windows. Some are as follows:-&lt;br /&gt;
&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;jconsole&lt;/li&gt;
&lt;li&gt;jVisual VM&lt;/li&gt;
&lt;li&gt;Eclipse MAT ....and it goes on&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
Out of above , i like jVisualVM the most due to its monitoring capability,&amp;nbsp;interactive&amp;nbsp;display, and easy to use. But the problem comes with the unix. Even though we can monitor the application&amp;nbsp;remotely&amp;nbsp;&amp;nbsp;but we cannot see the live objects, their size and number i.e we cannot get the heap dump&amp;nbsp;remotely.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
To get the heap dump on Unix machine, we can use &lt;b&gt;j&lt;/b&gt;&lt;b style=&quot;font-style: italic;&quot;&gt;map.&lt;/b&gt;&amp;nbsp;To use &lt;b&gt;jmap&lt;/b&gt;, we need the &lt;b&gt;process id &lt;/b&gt;of java application. At times, we have lot many java process running in unix and its difficult to identify. Java provides &lt;b&gt;jps&lt;/b&gt; tool which list the JVM with the process Id which it got the access . The steps are as follows:-&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Type &lt;b&gt;&lt;a href=&quot;http://docs.oracle.com/javase/1.5.0/docs/tooldocs/share/jps.html&quot; target=&quot;_blank&quot;&gt;jps &lt;/a&gt;&lt;/b&gt;on unix. This will list down all java process running on Unix&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Use jmap as &amp;nbsp;jmap -dump:file=&amp;lt;filename&amp;gt; &amp;lt;processid&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;e.g. jmap -dump:file=heap1.hprof 6771&lt;/li&gt;
&lt;li&gt;File created would be read only. If you want to copy, you have the chnage the acess rights. to use we can use chmod as &amp;nbsp;:- &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;chmod 777 heap.
hprof &amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
We can copy the dump to windows machine and run jvisualVM. Goto File --&amp;gt; Load&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjdZp3ug4RQ3_5zPJxEv4QPoRNGC9dmQ4gV04G_C4Ih0EGpmPs9zHO7Djm0x7kYc_Ee4mexd1Tkry0vbehWT1egNzdLIzNUYSlJJUpFC-E8itxPvQeuzICDw1aMyyQ7Kz63FedXKaFEt68/s1600/load.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;497&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjdZp3ug4RQ3_5zPJxEv4QPoRNGC9dmQ4gV04G_C4Ih0EGpmPs9zHO7Djm0x7kYc_Ee4mexd1Tkry0vbehWT1egNzdLIzNUYSlJJUpFC-E8itxPvQeuzICDw1aMyyQ7Kz63FedXKaFEt68/s640/load.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Browse the file in windows as shown and click ok.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOfg4_a1OLRI2kqC7VJWA655PsSAYDB6hDoz55khhHeurNhWpr0lOIZOiAg71hHSgj7CRUUPB4rYp5mC4GsfrYmlKC7TB2SlgxFSMA89BDyErj1Ul5pml8ZZV03pC2uWdnk2g-znJ1i3LS/s1600/heapselect.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;529&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOfg4_a1OLRI2kqC7VJWA655PsSAYDB6hDoz55khhHeurNhWpr0lOIZOiAg71hHSgj7CRUUPB4rYp5mC4GsfrYmlKC7TB2SlgxFSMA89BDyErj1Ul5pml8ZZV03pC2uWdnk2g-znJ1i3LS/s640/heapselect.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Now the dump is loaded in jvisual VM. Next screem shows the summary, classes and instances. summary shows the objects,classes and instances loaded into JVM, classes shows all the classes loaded with no of instances and size as shown.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;u&gt;Summary View:-&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjj0l0kAD933Zt5C99TJM1xqS5lbglRm7HcAts-koPa3sQD0T56rlXCOnvjy4TsDEtFqJYEy3fgrdNJYJuTwLZLOUxJcjBRS1yzs5kmpvwAeuh2NFMaf51kecHOlulF7h56iG_Gkg10nvDW/s1600/summery.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;636&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjj0l0kAD933Zt5C99TJM1xqS5lbglRm7HcAts-koPa3sQD0T56rlXCOnvjy4TsDEtFqJYEy3fgrdNJYJuTwLZLOUxJcjBRS1yzs5kmpvwAeuh2NFMaf51kecHOlulF7h56iG_Gkg10nvDW/s640/summery.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;u&gt;Class View:-&amp;nbsp;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglIf6-Mwtwwz6pSEN0y-MxzML0bZzQzpoDjeTluDlHIw6ETnPpOy2BIoaCw8dDGDMai45Fh-ovsHQLXYJ3wlrJO5X3ldNgQLggqpnnY74SA7KDHcD4lXvraLhcM5pmaSGC18AnC275noF9/s1600/hibernate.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglIf6-Mwtwwz6pSEN0y-MxzML0bZzQzpoDjeTluDlHIw6ETnPpOy2BIoaCw8dDGDMai45Fh-ovsHQLXYJ3wlrJO5X3ldNgQLggqpnnY74SA7KDHcD4lXvraLhcM5pmaSGC18AnC275noF9/s1600/hibernate.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
In my Next post, I will be discussing how to analyse heap dump in &lt;b&gt;Eclipse MAT&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;u&gt;Resource:-&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;a href=&quot;http://www.lshift.net/blog/2006/03/08/java-memory-profiling-with-jmap-and-jhat&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;http://www.lshift.net/blog/2006/03/08/java-memory-profiling-with-jmap-and-jhat&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://visualvm.java.net/index.html&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;http://visualvm.java.net/index.html&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/1.5.0/docs/tooldocs/share/jps.html&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;http://docs.oracle.com/javase/1.5.0/docs/tooldocs/share/jps.html&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/1.5.0/docs/tooldocs/share/jmap.html#options&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;http://docs.oracle.com/javase/1.5.0/docs/tooldocs/share/jmap.html#options&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docwiki.cisco.com/wiki/How_to_analyze_heap_dumps&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;http://docwiki.cisco.com/wiki/How_to_analyze_heap_dumps&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/7775540121263951693/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2012/05/generate-heap-dump-in-unix.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/7775540121263951693'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/7775540121263951693'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2012/05/generate-heap-dump-in-unix.html' title='Generate Heap Dump in Unix'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjdZp3ug4RQ3_5zPJxEv4QPoRNGC9dmQ4gV04G_C4Ih0EGpmPs9zHO7Djm0x7kYc_Ee4mexd1Tkry0vbehWT1egNzdLIzNUYSlJJUpFC-E8itxPvQeuzICDw1aMyyQ7Kz63FedXKaFEt68/s72-c/load.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-3034026185985715818</id><published>2012-02-06T09:05:00.000-08:00</published><updated>2012-08-24T13:51:13.045-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Database"/><category scheme="http://www.blogger.com/atom/ns#" term="Databse"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Why Time gets truncated with ResutSet getDate() function.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Recently I stuck in an issue on populating date from stored procedure. I am reading a date from a resultset using rs.getDate(), storing in a java.util.Date instance variable and displaying on the screen. &lt;br /&gt;
&lt;br /&gt;
Java.util.Date&amp;nbsp; mydate = rs.getDate(1);&lt;br /&gt;
&lt;br /&gt;
Output is only date while time is truncated.&amp;nbsp; But why …! &lt;br /&gt;
That confused me a lot. So I google it. Spending lot of time in reading blogs, oracle docs and trying different things on oracle server like checking&amp;nbsp; NLS_DATE_FORMAT, I am not able to get the time.&lt;br /&gt;
Next I come across a Timestamp thing in Resultset class.&lt;br /&gt;
&lt;br /&gt;
Rs.getTimestamp (int colIndex)&lt;br /&gt;
&lt;br /&gt;
When I use it, I immediately get the time.&amp;nbsp; Now, the important question, why the resultset function getDate() does not return the Time. Now my search is preety narrow. What I found is :-&lt;br /&gt;
&lt;br /&gt;
In java, we have java.util.Date for java.sq.Date . So functionalities available in sql.Date are also available in util.Date. But there is one difference, sql.Date stores only Date and not Time of date. To get the time, we have to use java.sql.Timestamp class. We can store into util.Date object since Timestamp, in both java.util and java.sql , extends Date class of respective packages. &lt;br /&gt;
&lt;br /&gt;
To verify, I ran the following simple program which verifies my explanation.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&#39;brush: java&#39;&gt;
public class DateProb {        

       public static void main(String[] args) {

              long time = System.currentTimeMillis();
              java.sql.Date sqlDate = new java.sql.Date(time);
              System.out.println(sqlDate);
              java.sql.Timestamp timestamp = new java.sql.Timestamp(time);
              System.out.println(timestamp);
              java.util.Date utilDate = new java.util.Date(time);
              System.out.println(utilDate);     
       }       
}

Output:-

2012-02-06
2012-02-06 22:33:36.946
Mon Feb 06 22:33:36 IST 2012
&lt;/pre&gt;

&lt;br /&gt;
Please share your thoughts on this.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/3034026185985715818/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2012/02/why-time-gets-truncated-with-resutset.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/3034026185985715818'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/3034026185985715818'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2012/02/why-time-gets-truncated-with-resutset.html' title='Why Time gets truncated with ResutSet getDate() function.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-4410538265950490990</id><published>2011-11-15T06:08:00.001-08:00</published><updated>2012-02-07T03:06:29.987-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Where to declare Constants in Java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Its been an topic of debate where should constants be declared. Let look at&amp;nbsp;approaches :-&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Declared in an Interface.&lt;/li&gt;
&lt;li&gt;Declared in a Class.&lt;/li&gt;
&lt;li&gt;Enums&lt;/li&gt;
&lt;/ol&gt;
Going through google, i found number of explanation for both of these. Each have their pros and cons. I&#39;ll try to summarise and share my thoughts on it.&lt;br /&gt;
&lt;br /&gt;
Lets start with &lt;strong&gt;interface&lt;/strong&gt;. In Java, Interfaces are used as abstract type, that contain method signatures, constants and nested types as&amp;nbsp;&lt;a href=&quot;http://download.oracle.com/javase/tutorial/java/IandI/createinterface.html&quot; target=&quot;_blank&quot;&gt;according to Oracle&lt;/a&gt;. We can use interfaces to defined a contract or for communication&amp;nbsp; &lt;a href=&quot;http://javaboots.blogspot.com/2011/09/why-java-supports-multiple-interface.html&quot; target=&quot;_blank&quot;&gt;as explained in my previous article&lt;/a&gt;. If we define constants here, we can have the following consequences:-&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;We cannot stop a class to not implement an interface.So a Global constant interface can be used for subtype which is not advisable.&lt;/li&gt;
&lt;li&gt;We cannot give define constants&amp;nbsp;depend on certain state condition.&lt;/li&gt;
&lt;li&gt;All the constants would stay in memory all the time.&lt;/li&gt;
&lt;/ol&gt;
Although, we can define constants in interfaces, we have the above constraints. Lets look how we overcome all of this in &lt;strong&gt;Class&lt;/strong&gt;.&lt;br /&gt;
&lt;br /&gt;
We can declare a &lt;em&gt;UtilConstant&lt;/em&gt; class. Make it final and make the constructor private. With this, we can overcome the problem (&lt;strong&gt;1&lt;/strong&gt;)&lt;strong&gt; &lt;/strong&gt;of interfaces. &lt;br /&gt;
Also if constants to be declared need some computation or a function call, we can do in class as defined below:-&lt;br /&gt;
&lt;pre class=&#39;brush: java&#39;&gt;
public class constantClassExample {
static final int BATCH_SIZE=getBatchsize();

   private static int getBatchsize() {
   // User defined computation
   return 0;
  }
}
&lt;/pre&gt;
So we have seen that we can define constants at runtime i.e (&lt;strong&gt;2&lt;/strong&gt;).&amp;nbsp; &lt;br /&gt;
So&amp;nbsp;to overcome&amp;nbsp;&lt;strong&gt;(3)&lt;/strong&gt; problem in interfaces, we can make use of &lt;a href=&quot;http://download.oracle.com/javase/1,5.0/docs/guide/language/static-import.html&quot; target=&quot;_blank&quot;&gt;static imports&lt;/a&gt;. It allows you&amp;nbsp;to import one or two members as per requirement.&amp;nbsp;Be aware, if you import all the constants using &#39;&lt;strong&gt;*&lt;/strong&gt;&#39;&amp;nbsp;, it can polluter your class space.&lt;br /&gt;
Afcourse, if the constants are relevent to current class, it will help&amp;nbsp;keeping the code encapsulated.&lt;br /&gt;
&lt;br /&gt;
Last comes the &lt;strong&gt;Enums&lt;/strong&gt;. If the constants can be clubbed to one single type or we need to enumerate , we can use Enums.&lt;br /&gt;
&lt;br /&gt;
For futher readings -&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/66066/what-is-the-best-way-to-implement-constants-in-java&quot; target=&quot;_blank&quot;&gt;What is the best way to implement constants in Java --- StackOverflow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.theserverside.com/discussions/thread.tss?thread_id=19221&quot; target=&quot;_blank&quot;&gt;Use Interface for declaring Constants&lt;!-- Breadcrumb comes here--&gt;&lt;!--div &quot;contentHeader&quot; ends--&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/4410538265950490990/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2011/11/where-to-declare-constants-in-java.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/4410538265950490990'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/4410538265950490990'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2011/11/where-to-declare-constants-in-java.html' title='Where to declare Constants in Java'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-3540020871215650742</id><published>2011-10-07T06:43:00.000-07:00</published><updated>2012-02-07T03:06:42.609-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>More About Java Arrays</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
With the addition of Collections in Java, the use of primitives and primitive arrays decreases day by day. But at the API level or framework design level, primitives are highly used even today as they are fast and does’t include method chaining.&amp;nbsp; &lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Arrays class in Java, provides the basic to advanced functionality to arrays. &lt;strong&gt;Java 6&lt;/strong&gt; adds a couple of more functions to this class. They are&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;

&lt;/div&gt;
&lt;li&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;
 &lt;strong&gt;copyOf ( T[ ] original,  int newLength&amp;nbsp; )&lt;/strong&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;

&lt;/div&gt;
&lt;li&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;copyOfRange( int[ ] original,  int from, int to&amp;nbsp; )&amp;nbsp;&lt;/strong&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;

&lt;/div&gt;
&lt;/ul&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
CopyOf copies the array and allows to explicitly defined the size of new array, padding with zeroes (in case of int, float, double, short), null (in case of char) and false (in case of boolean). Its similar to System.arraycopy() but&amp;nbsp;&amp;nbsp;doesnt allows to&amp;nbsp;specify the size of output array. Simple but useful functionality.&lt;/div&gt;
&amp;nbsp; &lt;br /&gt;
Lets understand with the example:-&lt;br /&gt;
&lt;pre class=&#39;brush: java&#39;&gt;
public class Test {
 public static void main(String[] args) {
  
  int[] orig={1,2,3,4,5,6,6,7,77,8,8};
  int[] copyOf = Arrays.copyOf(orig, 20);
  System.out.println(&quot;CopyOf---&amp;gt; &quot;+copyOf.length + &quot;   &quot; +Arrays.toString(copyOf));
  
  int[] copyOfRange= Arrays.copyOfRange(orig, 0, 7);
  System.out.println(&quot;CopyOfRange---&amp;gt; &quot;+ copyOfRange.length + &quot;   &quot; +Arrays.toString(copyOfRange));   
 }
}
 Output:-
CopyOf---&amp;gt; 20   [1, 2, 3, 4, 5, 6, 6, 7, 77, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0]
CopyOfRange---&amp;gt; 7   [1, 2, 3, 4, 5, 6, 6]
&lt;/pre&gt;
&lt;br /&gt;Keep looking the space for more tips and tricks.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/3540020871215650742/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2011/10/more-about-java-arrays.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/3540020871215650742'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/3540020871215650742'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2011/10/more-about-java-arrays.html' title='More About Java Arrays'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-3635200568881073205</id><published>2011-10-01T21:11:00.000-07:00</published><updated>2011-10-01T21:12:12.649-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Websites"/><title type='text'>Pay Packets of BIG IT Giants</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
What Apple is paying for a Software developer..? How much is facebook, Twitter, linkedin paying to Analysts?&lt;br /&gt;
&lt;br /&gt;
Mentioned above are few Big Tech IT Companies where everybody likes to work. Well few of us got an opportunity. But&amp;nbsp;at least everybody&amp;nbsp;likes to know what they are paying....!&lt;br /&gt;
&lt;br /&gt;
Few days back, I come across a&amp;nbsp; website &lt;a href=&quot;http://techcompanypay.com/&quot;&gt;http://techcompanypay.com/&lt;/a&gt;&amp;nbsp;,which shows the average salary of IT companies as per their designation.&amp;nbsp;The company claims that it had collected the information publicily available on the internet, so no comment on the authenticity. But at least one can have the idea... Do check it out.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/3635200568881073205/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2011/10/pay-packets-of-big-it-giants.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/3635200568881073205'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/3635200568881073205'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2011/10/pay-packets-of-big-it-giants.html' title='Pay Packets of BIG IT Giants'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-610521115470744149</id><published>2011-09-28T06:27:00.000-07:00</published><updated>2012-02-07T03:07:18.633-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="JDK 7 Features"/><title type='text'>Learning JDK 7 Features Part 3: Try With Resource</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Today we follow some standard&amp;nbsp;coding conventions so that code should easy to read and maintainable &lt;strong&gt;or&lt;/strong&gt;&amp;nbsp; i can say &quot; &lt;strong&gt;&lt;em&gt;Code should&amp;nbsp;look beautiful&lt;/em&gt;&lt;/strong&gt;&amp;nbsp;&quot;. But there are some cases where we&amp;nbsp;find our code is cluttered or&amp;nbsp;duplicated. Its more often&amp;nbsp;with &lt;strong&gt;&lt;em&gt;Exception Handlers&lt;/em&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;em&gt;Streams&lt;/em&gt;&lt;/strong&gt; and &lt;em&gt;&lt;strong&gt;JDBC&lt;/strong&gt;&lt;/em&gt;&amp;nbsp;calls i.e. opening and closing streams/connections and multiple catch handlers. Java&amp;nbsp;7 comes to rescue us from this duplication and is succeeded in it. &lt;br /&gt;
&lt;br /&gt;
Before Java 7, to cloase a resource, we write a final block and close every resource in it. but some times the finally block become large and cluttered.&amp;nbsp;Take a look&amp;nbsp;at the code&amp;nbsp;below:-&lt;br /&gt;
&lt;pre class=&#39;brush: java&#39;&gt;
finally {
            try {
                if (resultSet != null)
                    resultSet.close();
            }
            catch(Exception e) {}
            finally {
                try {
                    if (statement != null)
                        statement.close();
                }
                catch(Exception e) {}
                finally {
                    connection.close();
                }
            }
        }&lt;/pre&gt;
So here&amp;nbsp;we see that we close the every stream and write catch&amp;nbsp;block for every close which makes the code cluttered. Also there is good chance that one forget to close the resource and it stays in memory forever. &lt;br /&gt;
&lt;br /&gt;
With Java 7, there is no need to close the resource manually . Java do it for you. But there is catch. One must aware of catching mechanism, which&amp;nbsp;I&#39;ll discuss later. Lets look at updated code:-&lt;br /&gt;
&lt;pre class=&#39;brush: java&#39;&gt;
public static void printEmployees(Connection con) 
 {
  String query = &quot;select ID, NAME, Location, Employee&quot;;

  try (Statement stmt = con.createStatement();
    ResultSet resultset = stmt.executeQuery(query);)
  {
   while (resultset.next()) {
    String id = resultset.getString(&quot;ID&quot;);
    String name = resultset.getString(&quot;NAME&quot;);
    String loc = resultset.getString(&quot;Location&quot;);
    System.out.println(id + &quot;, &quot; + name + &quot;, &quot; + loc);
   }

  } catch (SQLException e) {
   e.printStackTrace();
  }
 }
}&lt;/pre&gt;
&lt;br /&gt;
We declare the objects/resources in try, as shown in code. Now, there is no need to write finally block to close the resources. Now the question arises, what type of object should consider as resource. Java comes up with a new interface to solve the problem; is &quot;&lt;strong&gt;&lt;em&gt;&lt;a href=&quot;http://download.oracle.com/javase/7/docs/api/java/lang/AutoCloseable.html&quot;&gt;AutoCloseable&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;&quot;. &lt;em&gt;Those classes which implements the interface is considered as a resource&lt;/em&gt;,&amp;nbsp;can used inside try. Below is an example to declare a class as resource and&amp;nbsp;used&amp;nbsp;&lt;em&gt;try as resource&lt;/em&gt;&amp;nbsp;:-&lt;br /&gt;
&lt;pre class=&#39;brush: java&#39;&gt;
public class  TestNewTryCatch{

 public static void main(String[] args) {

  try(MyResource res = new MyResource())
  {
   res.execute();
  }  
  catch (Exception e  ) {}
 }
}

class MyResource implements AutoCloseable
{
 @Override
 public void close() throws Exception {
  System.out.println(&quot;In close&quot;);
 }
 public void execute() throws Exception
 {
  System.out.println(&quot;In Execute&quot;);
 }
}&lt;/pre&gt;
&lt;br /&gt;
Exception handling handles differently. If an exception is thrown in try block and one or more exceptions are thrown from try with resource than exceptions that corresponds to try with resource are &lt;strong&gt;&lt;em&gt;surpressed.&lt;/em&gt;&lt;/strong&gt; We can retrieved the surpressed exceptions using throwable.getSuppressed() . Lets see with an example:-&lt;br /&gt;
&lt;pre class=&#39;brush: java&#39;&gt;
public class TestNewTryCatch{

 public static void main(String[] args) {
  try(MyResource res = new MyResource() )
  {
   res.execute();
  }  
  catch (Exception e  ) {
   System.out.println(&quot;In exception--&amp;gt;&quot; + e.getMessage());
   Throwable ht[] =e.getSuppressed();
   for(Throwable t:ht)
   {
    System.out.println(t.getClass());
    System.out.println(t.getMessage());
   }
  }
 }
}
class MyResource implements AutoCloseable
{
 @Override
 public void close() throws Exception {
  System.out.println(&quot;In close&quot;);
  throw new MyException(&quot;Test2&quot;);
 }

 public void execute() throws Exception
 {
  throw new RuntimeException(&quot;EXECUTE Test&quot;);
 }

}

class MyException extends Exception
{
 public MyException(String string) {
  super(string);
 } 
}
Output:-
In close
In exception--&amp;gt;EXECUTE Test
class MyException
Test2&lt;/pre&gt;
Hope this article puts some light into the new try feature. Throw a comment in case i miss something or have some query.
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/610521115470744149/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2011/09/learning-jdk-7-features-part-3-try-with.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/610521115470744149'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/610521115470744149'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2011/09/learning-jdk-7-features-part-3-try-with.html' title='Learning JDK 7 Features Part 3: Try With Resource'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-4271512057325438452</id><published>2011-09-27T03:39:00.000-07:00</published><updated>2011-09-27T03:40:01.402-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Why java supports Multiple Interface Inheritance</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Java does not support multiple class inheritance i.e. we cannot extend multiple classes at one time in a class. But we can implememt multiple interfaces in a class. Lets start with the benefits of inheritance. &lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Interfaces are user for two reasons :- &lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
1) Contract &lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
2) Communication &lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;Contract&lt;/strong&gt; ,is an aggrement between the interface and the implementing class, that the class will provide the implementation of the methods of the interface&#39;s. On has to adhere to the contract.&amp;nbsp;Collections in java&amp;nbsp;has many interfaces like &lt;em&gt;Set, List, Map. &lt;/em&gt;These interfaces provide the basic set of&amp;nbsp;methods for the class depending on its interface type.We have their implementation classes like&amp;nbsp;HashSet for Set, ArrayList for List and HashMap for Map. &lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;Communication &lt;/strong&gt;, is used to communicate certain functionality of a class to the outside world. This is very usefull when you want to expose a class but we dont want that one should know all the methods , variables and other class information. Instead we expose the interface which has some defined methods and one can call those methods only. This technique are highly used in frameworks and remote applications. Lets understand with a example.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LinkedList&lt;/em&gt; class in java implements two interfaces. List and Queue. Each interface has its own set of methods but the use case is differant for each. List is used to store elements as list while queue is based on FIFO or LIFO but the use the same class LinkedList. So, when we wan to use LinkedList as List, we expose as List interface and when we require a LIFO/ FIFO type functionality, we expose the Queue Interface.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Now come to the question i.e. multiple inheritance part. As discussed in Communication part, we can expose a class with a interface. If Java doesnt support multiple inheritance, we have to write different classes for each interface, where each class has the same code, but method names would be different which increase the duplication of code.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;Wonderfull, isnt it......!&lt;/strong&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/4271512057325438452/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2011/09/why-java-supports-multiple-interface.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/4271512057325438452'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/4271512057325438452'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2011/09/why-java-supports-multiple-interface.html' title='Why java supports Multiple Interface Inheritance'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-3999480301416055387</id><published>2011-09-25T01:13:00.000-07:00</published><updated>2012-02-07T03:07:42.110-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Fix double check locking in Java 5</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
We can fix the double check locking&amp;nbsp; using &lt;em&gt;volatile&lt;/em&gt; keyword. In Java 5, the JRE system will not allow a write of volatile to be reordered i.e read and write of volatile cannot be reordered w.r.t any previous read and write. So the volatile always gives the latest value.
&lt;pre class=&#39;brush: java&#39;&gt;
class Foo{
               private volatile Helper helper=null;
               public Helper getHelper(){
                  if(helper=null){
                      synchronized(this){
                          if(helper=null)
                              helper=new Helper();
                   }
               }
               return helper;
          }
}&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/3999480301416055387/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2011/09/fix-double-check-locking-in-java-5.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/3999480301416055387'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/3999480301416055387'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2011/09/fix-double-check-locking-in-java-5.html' title='Fix double check locking in Java 5'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-5404679003379354265</id><published>2011-09-23T08:47:00.000-07:00</published><updated>2011-10-05T04:00:22.859-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="JDK 7 Features"/><title type='text'>Learning JDK 7 Features Part 2: Updated Generic Instance Creation</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Prior to Java 7, we create the generic instance as follows:- &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;List&amp;lt;String&amp;gt; list = new ArrayList&amp;lt;String&amp;gt;( );
&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This syntex tunrs urgly in complex situations in which the length of type parameters increases. As mentioned in &lt;a href=&quot;http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683/&quot;&gt;Effective Java (2nd Edition) chapter 2&lt;/a&gt; ,   Joshua suggest us a way which can reduce the verbosity of generic instance creation; as follows&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;public class TypeInference {&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[ ] args)&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; List list = TypeInference.newInstance();
 list.add(&quot;str&quot;);&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static ArrayList newInstance( )&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return new ArrayList( );&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; }&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Even the previous method has an limitation that u have to insert a static method for each implementaion class.&lt;br /&gt;
&lt;br /&gt;
Oracle with Java 7 comes out a way which take of this redundancy with some limitations. As suggested in &lt;a href=&quot;http://download.oracle.com/javase/7/docs/technotes/guides/language/type-inference-generic-instance-creation.html&quot;&gt;oracle documenation &lt;/a&gt;, we can create objects with empty type parameter(&amp;lt;&amp;gt;) as long as compiler can understand the defined type at compile time. This pair of backets defined informally diamond by Oracle.&lt;br /&gt;
&lt;br /&gt;
Lets understand with an example prior to Java 7:-&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Map &amp;lt;String,HashMap&amp;lt;String,List&amp;lt;String&amp;gt;&amp;gt;&amp;gt; map = new&amp;nbsp; HashMap&amp;lt;String,HashMap&amp;lt;String,List&amp;lt;String&amp;gt;&amp;gt;&amp;gt;( );&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In Java 7 , we can substitute the parametrized constructor with empty brackets as shown:-&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Map&amp;lt;String,HashMap&amp;lt;String,List&amp;lt;String&amp;gt;&amp;gt;&amp;gt; map = new HashMap( );&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Everything doesnt come free. So as Java. We cannot use subtitute the empty bracktes (&amp;lt;&amp;gt;) everywhere instead of type paramters. Lets look a at the example&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;List list = new ArrayList( );&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;
list.add(&quot;A&quot;);&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;// The following statement would not compile since addAll expects &lt;i&gt;Collection&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;
list.addAll(new ArrayList( ));&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Error Msg :-The method addAll(Collection&amp;lt;? extends String&amp;gt;) in the type List&amp;lt;String&amp;gt; is not applicable for the arguments (ArrayList&amp;lt;Object&amp;gt;) . &lt;b&gt;FYI &lt;/b&gt;: syntax for addAll &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;boolean addAll(Collection c);
&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
But the following line will compile:-&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt; 
list.addAll(new ArrayList( ));&lt;/b&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/5404679003379354265/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2011/09/learning-jdk-7-features-part-2-updated.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/5404679003379354265'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/5404679003379354265'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2011/09/learning-jdk-7-features-part-2-updated.html' title='Learning JDK 7 Features Part 2: Updated Generic Instance Creation'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-4329374602556589644</id><published>2011-09-23T03:23:00.000-07:00</published><updated>2012-02-07T03:09:23.438-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="JDK 7 Features"/><title type='text'>Learning JDK 7 Features Part 1 : Strings in switch Statements</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Switch statement is enhanced in JDK 7 with the support of String Object. Prior to it JDK 7 release, switch only supports&amp;nbsp; &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;short&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, and &lt;code&gt;int&lt;/code&gt;&amp;nbsp; litearls. With this release onwards, we use string objects in switch expressions. Its is same as comparing String.equals method for each case. Please note the comparison is &lt;em&gt;CASE- SENSITIVE.&lt;/em&gt;&amp;nbsp; Let see how it works :- &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&#39;brush: java&#39;&gt;
private static String getTypeOfSeasonFromSwitch(String monthArg) {
  
  String typeOfSeason = null;
      switch (monthArg) {
       case &quot;December&quot;:    
       case &quot;January&quot;:
       case &quot;Febuary&quot;:
           typeOfSeason = &quot;Winter&quot;;
              break;
          case &quot;March&quot;:
          case &quot;April&quot;:
          case &quot;May&quot;:
           typeOfSeason = &quot;Spring&quot;;
              break;
          case &quot;June&quot;:
          case &quot;July&quot;:
          case &quot;August&quot;:
           typeOfSeason = &quot;Summer&quot;;
              break;         
          case &quot;September&quot;:
          case &quot;October&quot;:
          case &quot;November&quot;:
           typeOfSeason = &quot;Autumn&quot;;
              break;          
          default:
              throw new IllegalArgumentException(&quot;Invalid month: &quot; + typeOfSeason);
      }
      return typeOfSeason;
 }
&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/4329374602556589644/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2011/09/learning-jdk-7-features-part-1-strings.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/4329374602556589644'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/4329374602556589644'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2011/09/learning-jdk-7-features-part-1-strings.html' title='Learning JDK 7 Features Part 1 : Strings in switch Statements'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-638226734479498291</id><published>2011-09-21T06:53:00.000-07:00</published><updated>2012-08-24T13:51:13.049-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Database"/><category scheme="http://www.blogger.com/atom/ns#" term="Databse"/><category scheme="http://www.blogger.com/atom/ns#" term="Hibernate"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Generate Java POJO and Hibernate XML from database tables</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;/span&gt;&lt;/strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Today we have frameworks to persist java objects to database without writing DAO&#39;s and hibernate is one which is widely used. But for nascent developers, creating its mapping to database tables is still difficult.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Recently I come across a way to generate Java&amp;nbsp; POJO and hibernate mapping XML&amp;nbsp; from database tables&amp;nbsp; using a Jboss Hibernate Tools. Its as easy as a click &amp;nbsp;and magic, mapping XML is generated and &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;corresponding POJO &#39;s are generated. Listed down the steps :-&lt;/span&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;1. Install the hibernate-tools jar using Eclipse&#39;s Install New software, selecting URL from &lt;/span&gt;&lt;/strong&gt;&lt;a href=&quot;http://www.jboss.org/tools/download.html&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;http://www.jboss.org/tools/download.html&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt; depending upon the eclipse version.&lt;br /&gt;&lt;br /&gt;2. Click on [File -&amp;gt; New -&amp;gt; Other -&amp;gt; Hibernate -&amp;gt; Hibernate Configuration File] and create a cfg file. The following properties should be specified : jdbc url , username, password, DB schema, driver class and dialect.&lt;br /&gt;&lt;br /&gt;3. Click on [File -&amp;gt; New -&amp;gt; Other -&amp;gt; Hibernate -&amp;gt; Hibernate Console Configuration ] and create a new console configuration. Add the jar file that contains your DB driver in the classpath section at the bottom.&lt;br /&gt;&lt;br /&gt;4. Enter the name of the console configuration. Click Browse button against the Configuration file and select the cfg.xml file created in step 3&lt;br /&gt;&lt;br /&gt;5. Click on [File -&amp;gt; New -&amp;gt; Other -&amp;gt; Hibernate -&amp;gt; Hibernate Reverse Engineering File(reveng.xml) and select the location of the file.&lt;br /&gt;&lt;br /&gt;6. Select the cfg.xml file created in step 3 as the Console Configuration. Click on include button and specify the schema and table name(s) to reverse engineer. Multiple table names can be specified using sql wild char (eg: TBL_%). Click Finish&lt;br /&gt;&lt;br /&gt;7. Switch to the Hibernate perspective and Click on the Hibernate icon in the tool bar and select the [Hibernate Code Generation ..] option.&lt;br /&gt;&lt;br /&gt;8. Right click on the [Hibernate Code Generation]tree node and select New.&lt;br /&gt;&lt;br /&gt;9. Give the name of the configuration and select the console configuration created in step 5 and reveng.xml created in step6-7. Also select the Output Directory and a relevant package.&lt;br /&gt;&lt;br /&gt;10. Go to the Exporters tab and check Generate domain code(.java) and Generate mappings (hbm.xml). Click run. &lt;br /&gt;&lt;br /&gt;11. The hibernate mapping xml files and Java classes will be created in the output directory specified in step 9.&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 0pt; text-indent: -19pt;&quot;&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/638226734479498291/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2011/09/generate-java-pojo-and-hibernate-xml.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/638226734479498291'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/638226734479498291'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2011/09/generate-java-pojo-and-hibernate-xml.html' title='Generate Java POJO and Hibernate XML from database tables'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4357047353136420609.post-8562307890609223155</id><published>2011-09-21T06:13:00.000-07:00</published><updated>2011-09-21T06:13:35.326-07:00</updated><title type='text'>My first Post</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Welcome you at the &lt;span style=&quot;color: #4c1130;&quot;&gt;&lt;em&gt;JAVA BOOTS&lt;/em&gt;&lt;/span&gt;.&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Its a place where u find,discuss,share common problems,coding strategies, design principles etc in java and related technologies. I keep sharing my learnings here. Hope it will be helpful to all.&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaboots.blogspot.com/feeds/8562307890609223155/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaboots.blogspot.com/2011/09/my-first-post.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/8562307890609223155'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4357047353136420609/posts/default/8562307890609223155'/><link rel='alternate' type='text/html' href='http://javaboots.blogspot.com/2011/09/my-first-post.html' title='My first Post'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>