Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

What apsects of Java are the most diificult to learn when coming from such a background? What common mistakes do people make ? What are the top timesaving and produtivtity increasing tricks ?

If you had a room of C/PHP coders who were about to start development using Java what advise would you give ?

This is my list of topics so far (in no particular order):

  • Use jodatime instead of the standard library , and also less importantly the guava library.

  • Arrays are zero indexed

  • I'd also highlight the pass-by-value/reference aspects of Java, and the fact that

    String s1 = new String("test"); 
    String s2 = new String("test"); 
    if(s1 == s2) // will be false 
    if(s1.equals(s2)) // will be true
    
  • Introduce the concept of design patterns and give a quick overview.

  • Introduce Spring (it will be used) and the concept of dependency injection

Is there anything obvious I am missing.

share|improve this question

closed as not constructive by gnat, Walter, Glenn Nelson, Martijn Pieters, GlenH7 Jan 21 '13 at 14:40

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

4  
Array's are zero indexed in C as well. –  Joe D Dec 6 '10 at 17:53
add comment

5 Answers

up vote 10 down vote accepted

The automatic garbage collecting doesn't mean that you should give up memory usage optimization.

share|improve this answer
add comment

Few points that PHP developer needs to know to code in Java:

  • Different type of collections are available in Java, in PHP only arrays is most commonly used so many PHP developers won't be aware of collections concepts.
  • Packaging : packaging is not generally used in PHP so they need to understand concepts like jar, war etc
  • Threads & Thread safety : if PHP is the only language they know threads is going to be entirely new concept.
  • Different application servers in Java, in PHP world it's just Apache.
  • Design patterns: Java world much emphasis is given for design patterns than in php.
share|improve this answer
    
There are ways to run PHP in a multi-threaded way. Not everything in PHP is inherently thread-safe though. There's also not just Apache. –  DanMan Feb 2 at 0:19
add comment

Not using proper Object-Oriented design but procedural. A classical example is switch or many if/else versus polymorphism:

//procedural way of computing the salary of an employee    
if(employeeType == JUNIOR) {
    salary = //junior salary calculation logc;   
} else if(employeeType == MID_LEVEL)
    salary = //mid_level salary calculation logc;   
} else if(employeeType == SENIOR) {
    salary = //senior salary calculation logc;   
}


//OOP way
Employee employee = EmployeeFactory.getEmployee(JUNIOR);
salary = employee.calculateSalary();
//where employee is an interface having calculateSalary method; 
//also there are classes for JuniorEmployee, MidLevelEmployee and SeniorEmployee
share|improve this answer
1  
+1 for touching on this very important issue. I'd give you more +s if I could :) –  Knownasilya Jan 21 '13 at 14:22
add comment

The biggest thing about Java compared with the languages you are talking about is the whole deal with Object Orientation. You can get by as a C or PHP programmer working almost entirely in a procedural way and if you want to be any good at Java you need to understand Object Orientation and understand it well.

If you can make sure they have learned that, not only will it make them better Java programmers, but it will be useful to them with any other languages they learn in future.

share|improve this answer
    
Is there a good simple example anywhere, a program written procedurally and then compared to OO. I guess I could write one myself, but is there a nice clear already available example around ? –  NimChimpsky Dec 6 '10 at 13:09
    
I don't know of one in particular but I do remember back when I was learning to use Java I learned a lot from the "Essence Of OOP Using Java" tutorials here: dickbaldwin.com/tocint.htm –  glenatron Dec 6 '10 at 13:11
    
Actually a problem for many PHP programmers is that they overcompensate with in-your-face-OOP coding styles (instead of nice APIs and object graphs) to make up for the perceived lack of object-orientation capabilities in PHP. –  mario Dec 6 '10 at 13:20
    
@mario: that sounds interesting, care to elaborate? –  Javier Dec 6 '10 at 14:15
1  
@Javier: Recent language changes brought some Javaisms onto PHP, which are not often senseful in a hybrid language. With a grain of salt: PHP Cargo Cult Programming. Also some PHP frameworks take the design patterns idea too far and can lead to suboptimal/obscure application structures. –  mario Dec 6 '10 at 16:46
add comment

For two of your remarks :

I'd also highlight the pass-by-value/reference aspects of Java, and the fact that ...

One of the best books to deeply understand coding problems is :"Extreme Java" by Joshua Bloch so:

String s1 = new String("test"); // bad coding

String s1 = "test"; // sufficient

Many and many other samples inside.

If you are obliged to code tomorrow, read inside concerned paragraph before coding, and take a pause to understand that Java is another mind world, even if it C children.

First time it seems very difficult, but soon it is more clear, and powerful.

Introduce the concept of design patterns and give a quick overview.

THE book designed for beginners to understand Java and OOP problems : Head First Design Patterns.

Tips/sample

Have a look at Collections or Pattern in Java package classes to understand good writing,

share|improve this answer
1  
could you please expand on why you recommend suggested resources as an answer to the question asked? –  gnat Jan 21 '13 at 13:41
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.