Java is the future !

Tuesday, August 16, 2011

Quiz of the day | OCPJP - Aug 16, 2011

What will be the result of compiling and running the following code:

Options :
a) true
b) false
c) false
d) None of the above

Solution: Correct choice is option B.
Creating a new instance of the class File, you're not yet making an actual file, you're just creating a filename. So file.exists() return false.
createNewFile() method created an actual file. So file.exists() return true.

How to become a Java developer?

"I want to be a java developer, What are the all skills that I need to have. I have learned the core java in college but what now?"
Does this sound a familiar question! You too may have a similar question in your mind. Don't worry, This article explains what are all the skills that you will need to be a Java web developer, and what are the skills that you are expected to have when you appear for an interview for a Java/J2EE web developer.

Java developer! But what kind of?

Let me clarify, this article is about the Java web development. As most of the time, when beginner say, 'I want to be a java developer', he actually means he wants to be a java web developer and wants to get involved in developing web applications. Otherwise, Java development in general is a vast field, today Java is used in many types of platforms, that includes Personal computers, Main frames, Hand held portable devices, Mobiles, Smart cards, Games and many more thing. But the biggest stream of java development that creates more jobs than any other stream is the JavaEE platform. The JavaEE platform is used to create the enterprise applications (It includes web applications as well).
So be clear in your mind, This article is about java web development or enterprise application development. Most of the time when you read a job classified for skills, “Spring, Spring MVC, Struts, Hibernate, EJB” they are for java web development.
So, now it’s clear that you want to be a Java web developer and looking for a jump start. So here are the skills that will get you going.

Step 1 : First thing first, know the basics, learn core Java

The first thing you must learn is Core Java. Having a solid foundation in core java will help you when you jump into the advanced java. No matter what Java technologies you plan to work on, you will need to use the core java every day. So it is absolutely must to have a good understanding of the core concepts. Learn the basic programming concepts like variables, branching and looping, logical conditions, data types etc.

Good understanding of core java library is a must

Learn core java library, especially collection framework, Threads, java.lang, packages. If you are targeting the web development, you may not want to waste time on the swing.
Get yourself a good core java book that covers the latest java edition JDK 1.6. (When I was a beginner, I read “The complete reference java”)

Step 2 : Learn to use an IDE (Integrated Development Environment)

While working as a professional, you won’t use the plain text editors to write the code, you will have to know how to use IDE. IDE A.K.A code editor will greatly improve your productivity, and make your life easier. Code editors are used to write, compile, run and debug code. They provide features like syntax highlighting, auto completion, can identify the problems in code even before compiling. These are some of the most common features, but there are many more than just these. I will recommend you to learn eclipse which is one of the most popular IDE amongst java developer, and its free.

Step 3 : Your first step towards web development, HTML, CSS and JavaScript

I will not explain what HTML or CSS is, there are plenty of resources available on the internet. But understand, this is the most important parts of any web application. Second most important thing to learn is JavaScript, let me clarify, the JavaScript is not java, the similarity in name is for historical reasons. Get yourself into the world of web applications with this three skills, learn some tutorials on the internet or get some good book.

Step 4 : The java web components, Servlet API and JSP

Almost every web application running on internet or intranet which is developed in Java has their roots in Servlet API. So next thing to learn is servlets. Servlet API is the only standard API for java web application development. JSP is also based on the servlet API. Almost all the web frameworks, like Spring MVC, Struts, Wicket uses the servlet API under the hood. Get yourself a good book like “head first servlet”. Having the solid understanding of the Servlet API is quite important. Understand the core concepts like, life cycle, request, response, filters, session, config, context etc.

Step 5 : Learn a web container

Web container is a run time environment or server that is used to deploy and run the web applications or more specifically Web components (Eg servlets or JSP)
Web containers does not know how to run struts or Spring MVC, they just understand the servlet API, but still you can run them on a web container, because ultimately they are based on the Servlet API. You can learn the tomcat, that would be sufficient initially.

Step 6 : Learn JDBC

Almost every web application will need to connect to a database for storing and retrieving persistent data. JDBC is the standard API for database connectivity. So it is quite important that you understand the JDBC well.

Step 7 : Learn a web application framework and an ORM framework

A web application framework is actually a set of libraries that makes developing web applications easier. Struts and Spring MVC are good choices. If you are just starting, I would recommend going with Spring MVC.
ORM stands for object to relational mapping, they are based on JDBC and used for storing and querying the database. But unlike JDBC, ORM frameworks operates on objects and provides ways for storing and retrieving objects. (But be clear, they are ultimately using JDBC under the hood). ORM frameworks reduces lots of boilerplate code, improves productivity and makes developers life easier. Hibernate is the best choice. If you are just starting, read and understand JPA (Java persistence API) which is the standard java ORM API. You can use hibernate for running your JPA code.
That's it. If you know everything I mentioned above well, you are all set to get a job as java web developer.

Step 8 : What next!

Once you are familiar with the things mentioned above, The next step would be to learn the JavaEE (Java enterprise edition). Learn EJB (Enterprise java beans), JSF (Java server faces) and other APIs that are part of the JavaEE. Get a good book that covers the latest JavaEE edition 1.6


Quiz of the day | OCPJP - 16 Aug 2011

What is the output for the above code ?

Options :
a) Compile with error - Not allowed to override the return type of a method with a subtype of the original type.
b) class A - return C
c) class B - return D
d) Runtime Exception

Saturday, May 14, 2011

char a = '\u000A'. Why is this invalid?

Unicode escape characters of the form '\Uxxxx', where xxxx is a hexadecimal value, are processed very early in the translation process (see JLS 3.10.4 ). As a result, the special characters '0A' (line feed) and '0D' (carriage return) are interpreted literally as "end of line."
For example, the expression...

char A = '\u000A';
...therefore becomes...

char A =;
...which results in a compile-time error.
To avoid this error, always use the special escape characters '\n' (line feed) and '\r' (carriage return).

Is it allowed to declare the main method private?

Former JVM versions (pre-1.4) allowed the main method to have any accessibility (private, etc). This incompatibility with Section 12.1.4 of the Java Language Specification has been fixed as of version 1.4. In order to invoke a main method from the command-line, it is now mandatory to declare the main method as follows:

public static void main (String[] args)
If the main method has any access level other than public, it will no longer run from the command-line.