Having a strong background in C++, its not that difficult to dive into the world of Java. I started reading the book “Thinking in Java by Bruce Eckel”. The book is fine (not for beginners). Concepts are described really well with examples. Being a C++ programmer, i am facing no difficulty in understanding. Most of the things looks similar. For example:
A simple program in java
// HelloDate.java import java.util.*; public class HelloDate { public static void main(String[] args) { System.out.println("Hello, it’s: "); System.out.println(new Date()); } }
- import statements bring in extra libraries or class you’ll need for the code in that file. (* indicates all classes in util library are included)
- like C++ , Java also has a main function.
- public keyword means that the method is available to the outside world same as in C++
- like ‘printf’ or ‘cout’ statements in C++, Java uses ‘System.out.println’ for output(‘ln’ after print stands for a space of line after the output, else simply print can also be used)
- ‘new’ operator is used to invoke an object of ‘Date’ class which is in util library which we included at the top.
- static – even if you’ve never created an object of the class you can call a static method or access a static field by using the class name. e.g.
class StaticTest { static int i = 47; }
we can write as “StaticTest.i++;”
If there are more than one objects of StaticTest class then they will share the same i means there will be only one piece of storage for StaticTest.i. Any change in i will be reflected in all the objects of the class.
There is still more to learn.Java is really interesting. It’s exception handling, concurrent programming, client/server programming,use in Hadoop makes it better than C++. I have just started learning it. Hope to complete it soon and get a hand on programming experience in the same.
HAVE FUN 🙂