• Post Reply Bookmark Topic Watch Topic
  • New Topic

Migrating from C to java  RSS feed

 
John Pike
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is my first post at the ranch. I learnt a bit of c in my school. I am a newbie in android so I think java would help me understand programming android better. I got the book Head First Java and Java Language Specification. I started learning Head First Java in the beginning and found java very interesting and lovely. I thought that inheritance is primarily for code reuse but after search I found that its for polymorphism and composition should be used for code reuse. Also I thought of using a default implementation in interface and overriding them wherever necessary so that generic code is reused but came across the fact that interfaces don't implement the methods(but it seems to be available in java 8). I keep writing C in java . Most of the time whenever I come with a doubt I post them in StackOverflow but they say its bad OO design always and its not OOP and I get discouraged. So I turned to java ranch as I thought it will be a more friendly place. So what will be a good advice to start good programming practices in java. Do I need to study object oriented patterns before starting java or its a common problem faced by those coming from C. I fear if I start developing bad practices from beginning then it will hit me in the long run. So how can I change my mindset and program in java style? Any advice and link will be helpful.
 
Akash Sharma
Greenhorn
Posts: 7
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John ,

Welcome to the Ranch . Yes, it is very common for programmers migrating, from structured languages to Object Oriented Programming languages, to find it a little uneasy in the beginning.So, RELAX.

- I will suggest you reading Head First Object Oriented Analysis and Design book. It will make you understand the Object Oriented concepts with ease.
- I will suggest you that you first understand how a method in java accesses variables and methods in other classes in Java (understand the difference between a reference variable and an object and how methods and variables can be accessed using the dot operator )
- Then you can start with coding small programs in java which apply the Object Oriented concepts.

Let me assure you that Head First Java is a wonderful book and I was in the same situation as you are today some time ago, when I was migrating from good old C to Java.

There are a lots of tutorials available on the net to start learning java and why not give a try to Beginning Java series at the Java Ranch.

You are always welcome to ask your doubts here at Java Ranch. Happy Learning
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Pike wrote: . . . Do I need to study object oriented patterns before starting java or its a common problem faced by those coming from C. . . .
This does appear to be a common problem; many people find it difficult to learn object‑orientation and particularly those who have programmed in a procedural language, e.g. C.

You can usually tell good OO design because there are lots of classes, and each class takes care of its own innards, and other classes don't “see” those innards. You find yourself writing myObject.method(...); all the time.
Short methods. Rarely use the keyword static, (which BTW means something different from in C).
Don't study things, but write lots of code and show us it. We shall tell you in no uncertain terms if you use non‑OO design, but we shall allow you to try again shall try not to be rude to you …


and welcome to the Ranch
 
Christopher McKay
Ranch Hand
Posts: 50
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Pike wrote:Hi,

This is my first post at the ranch. I learnt a bit of c in my school. I am a newbie in android so I think java would help me understand programming android better. I got the book Head First Java and Java Language Specification. I started learning Head First Java in the beginning and found java very interesting and lovely. I thought that inheritance is primarily for code reuse but after search I found that its for polymorphism and composition should be used for code reuse. Also I thought of using a default implementation in interface and overriding them wherever necessary so that generic code is reused but came across the fact that interfaces don't implement the methods(but it seems to be available in java 8). I keep writing C in java . Most of the time whenever I come with a doubt I post them in StackOverflow but they say its bad OO design always and its not OOP and I get discouraged. So I turned to java ranch as I thought it will be a more friendly place. So what will be a good advice to start good programming practices in java. Do I need to study object oriented patterns before starting java or its a common problem faced by those coming from C. I fear if I start developing bad practices from beginning then it will hit me in the long run. So how can I change my mindset and program in java style? Any advice and link will be helpful.

First of all, welcome to the Ranch . I haven't had much experience with C/C++ but when I had a look at some of the syntax, I found that it was very similar to java. I have heard that Head First Java is one of the best java books around, so that should be helpful for looking at good practice etc. And if you run into any problems, everyone here at the Ranch will gladly help.
 
John Pike
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks akash, campbell, chris for your humble and helpful replies. Happy to be at ranch. I will keep learning and disturbing you all at ranch:-)
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christopher McKay wrote: . . . when I had a look at some of the syntax, I found that it was very similar to java. . . .
There are two sides to that story. One is that the similarity encouraged people to make the jump from C++ to Java, ensureing early uptake and contributing to Java's popularity.
The other is that there are great differences hiding behind the similarities. C is a procedural language and Jav an object language. People think two constructs which look the same in the two languages are the same. Examples:-
gcc -o swap swap.c
… ./swap 123 456
i = 123 j = 456. Later, …
javac Swap.java
&hellip java Swap 123 456
i = 123, j = 456. Later, i = …
This is a notorious example about trying to translate C code to Java.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!