Posts tagged Java
Java Rant #1
Feb 17th
Once apon a time, I to some extent spent time learning Java. It was not a lot of Java, and it wasn’t extremely indepth. It was more of a “get to know the language”; doing some simple database hits, very basic console and windows app. This was all back in 2000-2001 so much has changed since then. I have since learnt and worked with c#, Python, Ruby and have for the most part been happy with what these languages bring to the table.
In recent days I have been contemplating over working on a few personal projects, some being “desktop apps” and others being web apps. Normally I would have written any desktop apps with C#, but with my recent migration away from just windows I feel it might be a good time to give Java another chance.
It seems a lot of the things I really wasn’t a fan of are still there today, things that other languages have been able to overcome several years ago and Java still can’t seem to handle.
Properties
Why is it that a language as “young” as C# not only has been able to handle properties in a nice way but they have also been able to change it a second time allowing for “automatic” generation of “basic” properties…
Simple “Person” Class in C#
public class Person {
public string Name { get; set; }
public string Email { get; set; }
}
Similar class in Java.
public class Person {
protected String name;
protected String email;
public String getName() {
return name;
}
public String getEmail() {
return email;
}
public void setName(String value) {
name = value;
}
public void setEmail(String value) {
email = value;
}
}
I guess you could expose the values in Java as protected to be public and change them directly, But if you need to make a change down the road where you need to add some sort of validation or something to these values, your left to putting it outside of the class that is responsible for the properties.
I am not turning away from Java, but I would think after so many years and so many implementations in other languages that something would have been implemented. Unless there is some hidden command I have not been able to find online or in documenation.
