Friday, November 29, 2013

Java vs Python - Which Programming Language Should Learn First

Java and Python are two of most popular and powerful programming language of present time. Beginner programmer often get confused, one of the most frequently asked question is should I learn Java or Python, Is Python is good programming language to start with, Which programming language would you recommend for beginners to learn first etc. Since I am a Java developer, my opinion is biased, I will always suggest you to start with Java and then learn Python, but if you ask this question to a Python developer, you might get just opposite answer. I have well documented  my reasons as Why Java is best Programming language and Why a programmer should learn Java. One of the most important reason you would see on that blog post is strong Java community, which will help you though out your Java career. You can ask some beginner stuff starting from how to set PATH and classpath to advanced stuff about debugging Java program in Eclipse, no matter what kind of question is, there is always some one is Java community, who is ready to answer and help you. This is one of the reason that StackOverflow is full of Java questions. By the way Python is not spring chicken anymore, it has fully grown and giving strong competition to main stream language like Java and C++.  When I first come across Python, I thought it's a scripting language, but that is an understatement. You can do object oriented programming in Python as well. On beginners point of view, I always suggest pick a language which is easier to learn, powerful to attract you and have strong community support, now both Java and Python fits this bill, and until you do some really good comparative analysis, you can not decide which language to learn from Java vs Python. Thankfully, we have an infographic, which highlights some important difference between Python and Java, I am sure after taking a look on this Infographic, you will be able to decide which is the right programming language to start with.

Thursday, November 28, 2013

Difference between static vs non static method in Java

In this article, we will take a look at difference between static and non static method in Java, one of the frequently asked doubt from Java beginner. In fact, understanding static keyword itself is one of the main programming fundamental, thankfully it's well defined in Java programming language . A static method in Java belongs to class, which means you can call that method by using class name e.g. Arrays.equals(), you don't need to create any object to access these method, which is what you need to do to access non static method of a class. Static method are treated differently by compiler and JVM than non static methods, static methods are bonded during compile time, as opposed to binding of non static method, which happens at runtime. Similarly you can not access non static members inside static context, which means you can not use non static variables inside static methods, you can not call non static methods from static ones, all those will result in compile time error. Apart from these significant differences between static and non static methods, we will also take a look at few more points in this Java tutorial, with a code example, which shows some of these differences in action.By the way this is the second article on static method, in first article, we have learned about when to use static method in Java

Monday, November 25, 2013

Java 8 Tutorials, Resources, Books and Examples to learn Lambdas, Stream API and Functional Interfaces

While release of Java 8 is still a few month away, GA is scheduled is in early next year (March 2014), Java community is already buzzing with expectation of functional programming and lambda expression. Many developers, programmers and bloggers has already shared lots of  really good tutorial to learn lambda expressions, , probably the next big thing in Java world . While the term "lambda expression" may sound abstract and academic, Java 8 Lambdas can have a big impact on how you program every day. Java 8 is coming up with  Lambda expressions, Stream API, Functional interfaces and default methods, which is eagerly waited through out the world. As a professional Java developer, you will have to learn Java 8 one day, and it's better to do sooner than later. One thing is sure that It's definitely going to change how you use Collection framework classes e.g. ArrayList or HashMap  in your Java program, especially on high performance applications. Not surprisingly, I am also started learning Java 8 new features and I am grateful to all these peoples, who has shared wonderful tutorials on lambdas. These are the people who have downloaded nightly builds, work through specification and initial draft to create, easy to understand Java 8 tutorials and examples. Since I am personally following them, it make a lot of sense for me to share all these resources with you guys, my readers. Earlier, when I shared some differences between Java and Scala, I had mentioned about some cool features of Scala, which makes code concise, clear and more readable, Java 8 is bringing parity on that as well. So stay tuned and follow these Java 8 Lambdas, Stream API and functional interfaces tutorial to get a feel of, what is going to be biggest change in Java programming language since it's first launch; probably even bigger than Generics from Java 1.5.

Friday, November 22, 2013

Difference between char, varchar, nchar and nvarchar data type in SQL Server database

What is difference between char and varchar in SQL, followed by nchar and nvarchar, is one of the popular SQL interview question, and surprisingly not every programmer knows this basic difference. If you go with name, which you should, than you can figure out that char is a fixed length data type while varchar should be variable length data type. Though all char, varchar, nchar, and nvarchar are used to store text or String data there are subtle differences between them. As I said char is fixed length, which means a variable or a column e.g. Zipcode char(10) will take only 10 bytes to store data, including space. On the other hand a varchar variable or column will take variable space, depending upon data you store + 2 additional bytes for storing length. For example a varchar column name varchar name(20) will take 6 bytes if you store "Jack" (4 + 2) and 7 bytes if you store "Jones" (5 + 2). In order to get better performance, you should use char for fixed length columns e.g. zipcode, where every row are under certain length e.g. 6 for India, and 5 + 4 digits postal codes for USA. On the  other hand, for a variable length column it's better to use varchar data type to save the space,  which is lost in case of char type, if actual data is always way less than capacity. In particular this question is next in series of couple of popular SQL interview question, e.g. difference between WHERE and HAVING clause and  writing SQL query to join three tables. If you come across any other interesting SQL queries than you can also share with us, if you don't know answer, we will try to find out together.

Wednesday, November 20, 2013

Scala vs Java - Differences and Similarities

Scala is new generation JVM language, which is generating popularity as alternative of arguable one of the most popular language Java. It's not yet as popular as Java, but slowly getting momentum. As more and more Java developers are learning Scala and inspired by Twitter, more and more companies are using Scala, it's future looks very bright. To start with, Scala has several good feature, which differentiate it from Java, but same time it has lot of similarities as well e.g. both Scala and Java are JVM based language, You can code Scala in Java way and Scala can use any Java library, which in my opinion a great decision made by designers of Scala. Since tremendous works has already been done in form of open source framework and library in Java, it's best to reuse them, rather than creating a separate set for Scala. Out of several differences, one of the main difference between Scala and Java is it's ability to take advantage of Functional programming paradigm and multi-core architecture of current  CPU. Since current CPU development trend is towards adding more cores, rather than increasing CPU cycles, it also favors functional programming paradigm. Though this differences may not be significant, once Java 8 will introduce lambdas, but it might be too early to comment. Apart from functional programming aspect, there are many other differences as well. One of the obvious one is improved readability and succinct code. Java is always on firing line for being too verbose, I thing Scala does take care of that and code which took 5 to 6 lines in Java, can be written in just 2 to 3 lines in Scala. Well Grounded Java Developer has some nice introduction on JVM languages like Scala, Groovy and Closure, which is worth reading.  In this article, we will see such kind of similarities and differences between Scala and Java.

Monday, November 18, 2013

Do you need to pass OCAJP before taking OCPJP - Java Certification for SE 7

One thing, which I certainly noticed after Oracle's acquisition of Sun Microsystems is creating confusion around Java certifications like hell. I used to remember those days, where Java Certifications are well defined and well known e.g. SCJP, SCWCD, SCBCD etc, but currently Java certification for SE 7 is known as either SCJP 7, OCJP 7 or even OCPJP 7. By the way official name of two most sought after Java certifications are Oracle Certified Associate, Java SE 7 Programmer ( Code : 1Z0-803) and Oracle Certified Professional, Java SE 7 Programmer ( Code 1Z0-804 ).  I receive lots of questions regarding Java Certifications for Java SE 6 and 7, with range of queries from how to prepare for exam, to suggestions on books, resources and mock exam simulators. One of the questions, which lot of my reader email me is about, whether taking OCAJP is mandatory for giving OCPJP or not?  Many of them have doubt about whether OCA is required for taking OCP or not? Well, answer is both Yes and No. If  you are appearing for Java SE 7 certification and haven't done any Java certification before than you need to first clear OCAJP and only than you can take OCPJP, but if you are upgrading from an earlier version e.g. you have already passed Oracle Certified Professional, Java SE 6 or SE 5 Programmer (OCPJP 6 or OCPJP 5) or any version of Sun Certified Java programmer exam ( SCJP) than you don't need to go through OCA path. You can directly appear for OCPJP 7. By the way exam code is different for upgrade version, you need to take 1Z0-805, Upgrade to Java SE 7 Programmer. On similar note, if you are appearing for Java SE 6 certification than you don't need to pass OCA, you can directly take Java 1.6 certification.

Thursday, November 14, 2013

Java Array Tutorial and Example for Beginners

Array is one of the most important data structure in any programming language, at same time different programming languages implement and treat array differently. Any one who is done some programming knows value of array and importance of knowing about array type, using them in there program. Together with linked list, array forms a set of basic data-structures. Though Java offers excellent Collection API and some of collection classes like ArrayList and  HashMap , they are internally based on array.  If you are coming from C or C++ background then you will find some difference about how array behaves there and how it does in Java, most notable difference between array in C and array in Java is bounds checking. C compiler doesn't check if program is accessing valid array index, while in Java, JVM does that and throws ArrayIndexOutOfBoundException, if program tries to access invalid array index. In this Java article, we will take a look on array in Java, both primitive and object arrays. It's a collection of important things about Java array and there properties.