Non-programming question about Java...
-
There are large areas where .NET is just not very efficient, e.g. in passing around structs to methods. In theory it could be made efficient (like the java VM), but MS has shown little interest in doing so. Have a look here for some numeric performance measurements: http://www.itu.dk/people/sestoft/papers/numericperformance.pdf[^].
Wout
-
So I've made my first aquintance with Java since I need it for my study at OU. I've heard some colleagues and friends say that Java is absolutely terrible, so I wasn't to happy about having to use Java. I started using JCreator (which looks nice, but is quite limited in features). After that I was introduced to Eclipse which looks a lot better. Of course the editor has nothing to do with the language, but it makes programming in it a lot more pleasant. So what did I think of Java? It's not bad. Missing the Properties of C# and the Namespace Imports (using), but they're stuff I can get used to. I could run it on my desktop or in my browser without much trouble. Am I missing something or is Java just not the horrible language I was told it is?
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}It's not horrible. That's typical 'language war' overstatement. But it is just a bit worse than C# in pretty much every way (I really can't think of a single advantage now that Mono/Moonlight clears up most of the 'cross platform' thing that Java used to have over everyone else):
- No properties; code looks less tidy and you get 'paren fatigue' trying to read it
- LINQ is awesome
- Java's generics are a bad post-hoc hack that don't really work properly (for example you can't use T.class or have two method overloads which take different types of List)
- Package visibility is much less useful than internal in .Net
- csc directly produces a usable DLL/EXE; javac produces something you need a build tool to turn into something runnable
- lambdas and delegates
- proper events as a language feature
- Lots of minor things that make code nicer to read (typeof(T), is and as instead of instanceof, upper case convention etc)
- Much better UI libraries in the framework (AWT and Swing are notoriously awful; WinForms and WPF are both pretty good)
- Better thought out collections in the framework (see also Generics, above)
There's also the community, which isn't really the fault of the language, but Java is the source of most of the 'factory factory factory pattern' type of thinking.
-
The only test that C# loses on in there, if you look at the MS JIT'd version not the Mono one (which is not a fair comparison with the commercial Sun JVM) is the matrix multiplication one and using double[,] is known to be a bad idea for performance.
Hmm, that's right, that was a rubbish reference! I ran accross articles about the jvm being quite fast several times though, but I never bothered to bookmark them, so can't find them quite quickly. .NET's passing around structs still sucks though.
Wout
-
So I've made my first aquintance with Java since I need it for my study at OU. I've heard some colleagues and friends say that Java is absolutely terrible, so I wasn't to happy about having to use Java. I started using JCreator (which looks nice, but is quite limited in features). After that I was introduced to Eclipse which looks a lot better. Of course the editor has nothing to do with the language, but it makes programming in it a lot more pleasant. So what did I think of Java? It's not bad. Missing the Properties of C# and the Namespace Imports (using), but they're stuff I can get used to. I could run it on my desktop or in my browser without much trouble. Am I missing something or is Java just not the horrible language I was told it is?
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}Personally speaking, I find it a fine and extensible language. Fairly elegant, and with MASSES of freely available code available means it is very easy to learn, and use to actually do something useful. BUT, outside of the language itself, I find it to be despicable to actually deploy and use in an enterprise environment. The tuning is dire, permgen growth is unacceptable, and I much, much prefer the .net framework. If it wasn't for the fact that it is the easiest way to program on posix based systems I probably wouldn't use it at all...
-
Hmm, that's right, that was a rubbish reference! I ran accross articles about the jvm being quite fast several times though, but I never bothered to bookmark them, so can't find them quite quickly. .NET's passing around structs still sucks though.
Wout
-
So I've made my first aquintance with Java since I need it for my study at OU. I've heard some colleagues and friends say that Java is absolutely terrible, so I wasn't to happy about having to use Java. I started using JCreator (which looks nice, but is quite limited in features). After that I was introduced to Eclipse which looks a lot better. Of course the editor has nothing to do with the language, but it makes programming in it a lot more pleasant. So what did I think of Java? It's not bad. Missing the Properties of C# and the Namespace Imports (using), but they're stuff I can get used to. I could run it on my desktop or in my browser without much trouble. Am I missing something or is Java just not the horrible language I was told it is?
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}Java is not horrible and the runtime has been very stable through all of the updates. You can probably take code compiled fifteen years ago by the 1.1 compiler and run it under the 1.7 runtime. Have fun with inner classes inside methods that automatically "clone" final stack variables from the containing method; one feature of Java that I wish C# would copy. The IDE should handle all of your imports for you. I have only had one time in the last fifteen years of working with Java where I really needed a pointer to help with some data structure manipulation. I managed to get something working but it was inefficient.
-
Some things are sub optimal, like mentioned a very long ago to MS here: https://connect.microsoft.com/VisualStudio/feedback/details/93858/struct-methods-should-be-inlined#tabs[^] Also see here for some comparisons between struct, passing by val/ref. Passing a struct by value has issues, as the CLR is not smart enough to handle that properly. http://www.kynosarges.de/StructPerformance.html[^] Also the java server VM seems to be better behaved in these tests. Passing a struct containing two doubles by value should be as fast as passing just a two separate doubles, but it's definitely slower (on x64 only at the moment presumably).
Wout
-
So I've made my first aquintance with Java since I need it for my study at OU. I've heard some colleagues and friends say that Java is absolutely terrible, so I wasn't to happy about having to use Java. I started using JCreator (which looks nice, but is quite limited in features). After that I was introduced to Eclipse which looks a lot better. Of course the editor has nothing to do with the language, but it makes programming in it a lot more pleasant. So what did I think of Java? It's not bad. Missing the Properties of C# and the Namespace Imports (using), but they're stuff I can get used to. I could run it on my desktop or in my browser without much trouble. Am I missing something or is Java just not the horrible language I was told it is?
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}So I taught myself Java about a month ago after running through runtime hell for a week with my current project (where I have no 'real' need for C++). I have a semester's worth of experience with C# and my degree was primarily C++ with a splattering of other languages where appropriate. It took about a week to be comfortable in Java. I am now tutoring Java to first years, I ran into the flaws of JCreator which is a very familiar environment from a visual studio background but ultimately only the pro version is good enough when you compare against netbeans (my primary java ide) and eclipse. I have also found JGrasp adequate but not ideal due to the lack of intellisense (excuse the microsoft term). Netbeans window flexibility makes it my choice over eclipse although I still like the visual studio IDE. There are problems with Java but they aren't that noticeable for the most part. Language wars seem futile as compilers improve and cpu power available increases. The language design is however old, Scala is a more modern language for example and still works on the JDK. I also like the ability of Java to integrate with C through the JNI while not ideal, it provides potential optimizations. As for your queries: Properties are nice but certainly not necessary, import replaces using but I miss the idea of things belonging to namespaces (as done in C++ where std::vector != mycontainers::vector), while the ide resolves these I don't enjoy reading code where I can't tell what package things are from. I feel Java is better than C# because of greater portability however this doesn't mean C# doesn't have areas where it is better e.g. Unity3D and XNA are great C# based tools. Also I would like delegates as C# implements them in Java.
-
Some things are sub optimal, like mentioned a very long ago to MS here: https://connect.microsoft.com/VisualStudio/feedback/details/93858/struct-methods-should-be-inlined#tabs[^] Also see here for some comparisons between struct, passing by val/ref. Passing a struct by value has issues, as the CLR is not smart enough to handle that properly. http://www.kynosarges.de/StructPerformance.html[^] Also the java server VM seems to be better behaved in these tests. Passing a struct containing two doubles by value should be as fast as passing just a two separate doubles, but it's definitely slower (on x64 only at the moment presumably).
Wout
Well then pass 2 Doubles, why create a struct for that? I just did this test on .Net 4 x64 where I made 10 million calls on 2 different methods, one that accepts a struct and one that accepts 2 Doubles. The one that accepts Doubles ran in 336 ms and the one that accepts a struct ran in 325 ms. It was consistently between 5 and 20 ms difference, hardly something to be concerned about.
-
So I've made my first aquintance with Java since I need it for my study at OU. I've heard some colleagues and friends say that Java is absolutely terrible, so I wasn't to happy about having to use Java. I started using JCreator (which looks nice, but is quite limited in features). After that I was introduced to Eclipse which looks a lot better. Of course the editor has nothing to do with the language, but it makes programming in it a lot more pleasant. So what did I think of Java? It's not bad. Missing the Properties of C# and the Namespace Imports (using), but they're stuff I can get used to. I could run it on my desktop or in my browser without much trouble. Am I missing something or is Java just not the horrible language I was told it is?
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}It depends on the point of view. When Java was introduced, it brought to production a lot of great ideas (including garbage collection). But, after 6 years of almost no evolution and the horrible handling of the Sun acquisition by Oracle, it's been left behind. The fact that there are a lot of legacy libraries not ready to use later language developments and the object-oriented dogmatism of the java community just add insult to injury. At a language (not platform) level, there is almost nothing java can do that c# cannot do, while there are plenty of things C# can do with much less code than java (think of dynamic types, lambdas and other functional programming consrtucts, implicit strong typing and all things that make for example ASP.NET MVC so wonderfull concise). In the end, most Java programs I've seen are very verbose. Some of the best professionals know when to use other languages based on the JVM (like groovy) to make coding more concise, but it's not a widespread practice. Java's slowly becoming the new COBOL.
-
Well then pass 2 Doubles, why create a struct for that? I just did this test on .Net 4 x64 where I made 10 million calls on 2 different methods, one that accepts a struct and one that accepts 2 Doubles. The one that accepts Doubles ran in 336 ms and the one that accepts a struct ran in 325 ms. It was consistently between 5 and 20 ms difference, hardly something to be concerned about.
Here's a test I just did:
static void Main(string\[\] args) { int n = 10000000; for (int i = 0; i < 5; ++i) { TestStructPerformance(n); TestPrimitivePerformance(n); } } private static void TestStructPerformance(int n) { TestStruct s = new TestStruct(); s.X = 1d; s.Y = 2d; s.Z = 3d; double x = 0d; DateTime start = DateTime.Now; for (int i = 0; i < n; ++i) { x += GetX(s); } DateTime end = DateTime.Now; Console.WriteLine("Struct elapsed time: " + (end - start).TotalMilliseconds); Console.WriteLine("(" + x + ")"); } private static void TestPrimitivePerformance(int n) { double x = 1d; double y = 2d; double z = 3d; double t = 0d; DateTime start = DateTime.Now; for (int i = 0; i < n; ++i) { t += GetX(x, y, z); } DateTime end = DateTime.Now; Console.WriteLine("Primitive elapsed time: " + (end - start).TotalMilliseconds); Console.WriteLine("(" + t + ")"); } public struct TestStruct { public double X, Y, Z; } public static double GetX(TestStruct s) { return s.X; } public static double GetX(double x, double y, double z) { return x; }
Results on Intel CORE i5, x64, Win 7, .NET 4.0 (careful to run in release mode!): Struct elapsed time: 48,0061 (10000000) Primitive elapsed time: 32,5042 (10000000) Struct elapsed time: 52,5067 (10000000) Primitive elapsed time: 35,5045 (10000000) Struct elapsed time: 57,5073 (10000000) Primitive elapsed time: 32,004 (10000000) Struct elapsed time: 48,0061 (10000000) Primitive elapsed time: 32,0041 (10000000) Struct elapsed time: 44,5057 (10000000) Primitive elapsed time: 29,0037 (10000000) Our software often works with 2D, 3D and 4D vectors/points, and just passing the doubles as separate parameters would not be workable on the scale that we use it. In some performance critical bits we can do that, but the best thing if MS would fix these performance issues as it would be relatively minor effort for them to do so. EDIT: made minor screw up in the console output, just fixed that bit.
Wout
-
I started using jcreator. I didn't like it, and neither did anyone else in the class. We all had netbeans on a usb by the third week of class.
If it moves, compile it
I started with a plain old text editor and command line. With that experience, I now appreciate a mature IDE (almost ... the text editor never hung & crashed). I have used NetBeans in the past, and am now using Eclipse, but those choices are mainly based on the client environment. Either one is a pretty solid improvement over a plain text editor ...
-
It depends on the point of view. When Java was introduced, it brought to production a lot of great ideas (including garbage collection). But, after 6 years of almost no evolution and the horrible handling of the Sun acquisition by Oracle, it's been left behind. The fact that there are a lot of legacy libraries not ready to use later language developments and the object-oriented dogmatism of the java community just add insult to injury. At a language (not platform) level, there is almost nothing java can do that c# cannot do, while there are plenty of things C# can do with much less code than java (think of dynamic types, lambdas and other functional programming consrtucts, implicit strong typing and all things that make for example ASP.NET MVC so wonderfull concise). In the end, most Java programs I've seen are very verbose. Some of the best professionals know when to use other languages based on the JVM (like groovy) to make coding more concise, but it's not a widespread practice. Java's slowly becoming the new COBOL.
Yikes, that sounds bad... :~
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
} -
Here's a test I just did:
static void Main(string\[\] args) { int n = 10000000; for (int i = 0; i < 5; ++i) { TestStructPerformance(n); TestPrimitivePerformance(n); } } private static void TestStructPerformance(int n) { TestStruct s = new TestStruct(); s.X = 1d; s.Y = 2d; s.Z = 3d; double x = 0d; DateTime start = DateTime.Now; for (int i = 0; i < n; ++i) { x += GetX(s); } DateTime end = DateTime.Now; Console.WriteLine("Struct elapsed time: " + (end - start).TotalMilliseconds); Console.WriteLine("(" + x + ")"); } private static void TestPrimitivePerformance(int n) { double x = 1d; double y = 2d; double z = 3d; double t = 0d; DateTime start = DateTime.Now; for (int i = 0; i < n; ++i) { t += GetX(x, y, z); } DateTime end = DateTime.Now; Console.WriteLine("Primitive elapsed time: " + (end - start).TotalMilliseconds); Console.WriteLine("(" + t + ")"); } public struct TestStruct { public double X, Y, Z; } public static double GetX(TestStruct s) { return s.X; } public static double GetX(double x, double y, double z) { return x; }
Results on Intel CORE i5, x64, Win 7, .NET 4.0 (careful to run in release mode!): Struct elapsed time: 48,0061 (10000000) Primitive elapsed time: 32,5042 (10000000) Struct elapsed time: 52,5067 (10000000) Primitive elapsed time: 35,5045 (10000000) Struct elapsed time: 57,5073 (10000000) Primitive elapsed time: 32,004 (10000000) Struct elapsed time: 48,0061 (10000000) Primitive elapsed time: 32,0041 (10000000) Struct elapsed time: 44,5057 (10000000) Primitive elapsed time: 29,0037 (10000000) Our software often works with 2D, 3D and 4D vectors/points, and just passing the doubles as separate parameters would not be workable on the scale that we use it. In some performance critical bits we can do that, but the best thing if MS would fix these performance issues as it would be relatively minor effort for them to do so. EDIT: made minor screw up in the console output, just fixed that bit.
Wout
I ran your code with the System.Timers.Stopwatch and I got the following on x64: Struct elapsed time: 84 (10000000) Primitive elapsed time: 66 (10000000) Struct elapsed time: 70 (10000000) Primitive elapsed time: 58 (10000000) Struct elapsed time: 69 (10000000) Primitive elapsed time: 59 (10000000) Struct elapsed time: 69 (10000000) Primitive elapsed time: 61 (10000000) Struct elapsed time: 70 (10000000) Primitive elapsed time: 58 (10000000) Interestingly, the differences are actually similar when run under x86 which is not supposed to have this problem.
-
So I've made my first aquintance with Java since I need it for my study at OU. I've heard some colleagues and friends say that Java is absolutely terrible, so I wasn't to happy about having to use Java. I started using JCreator (which looks nice, but is quite limited in features). After that I was introduced to Eclipse which looks a lot better. Of course the editor has nothing to do with the language, but it makes programming in it a lot more pleasant. So what did I think of Java? It's not bad. Missing the Properties of C# and the Namespace Imports (using), but they're stuff I can get used to. I could run it on my desktop or in my browser without much trouble. Am I missing something or is Java just not the horrible language I was told it is?
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}As a language, Java is not much different than any other OO language. My main problem with it is the way the classes have been designed to make it much harder to do things that would be more efficient to do in some other languages. The Java classes appear overtly designed for scalability and extensibility of complex structures. Most often, the work need not be so complex, but the Java classes give me no choice. The next problem is all of the pieces that must be put together in the system to get it to work. And lastly, some programs I had working in earlier releases of Java don't work anymore, and I have to go back and re-code them.
-
So I've made my first aquintance with Java since I need it for my study at OU. I've heard some colleagues and friends say that Java is absolutely terrible, so I wasn't to happy about having to use Java. I started using JCreator (which looks nice, but is quite limited in features). After that I was introduced to Eclipse which looks a lot better. Of course the editor has nothing to do with the language, but it makes programming in it a lot more pleasant. So what did I think of Java? It's not bad. Missing the Properties of C# and the Namespace Imports (using), but they're stuff I can get used to. I could run it on my desktop or in my browser without much trouble. Am I missing something or is Java just not the horrible language I was told it is?
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}Naerling wrote:
I've heard some colleagues and friends say that Java is absolutely terrible, so I wasn't to happy about having to use Java.
Certainly if there was no context with those comments then I would dismiss them as at best ignorant and and worse it might indicate that the commenter isn't very smart.
Naerling wrote:
and the Namespace Imports (using),
Huh? Java has import. And in terms of syntax I haven't seen any difference between those two.
Naerling wrote:
Am I missing something or is Java just not the horrible language I was told it is?
Without a context it doesn't mean anything. Various preferences that I can note. - I like the power of C++ templates, memory management and pointers (emphasizing the power here.) - C# app domains are a poor substitute for Java's class loaders. I have yet to see any way in which they are better and quite a few ways in which they are worse. - I like C# properties. - I dislike the ease of C# Linq especially since it can lead to connection leaks (which I have seen.) - I dislike the C# exception handling versus Java. With C# one MUST capture exceptions in every thread or it will take down the application. And there is no equivalent global catch unlike Java. - I like C#/Java null reference exception, array boundary checks and various other exceptions that originate from programming bugs and which C++ merely fails. - In general I prefer the app to handle memory for me in C#/Java (even despite liking the control in C++.) - I like how fast I can put together a simple tool, especially parser/interpreters in Perl. The same thing would take longer and with more code in C#, Java and C++.
-
mark merrens wrote:
Get a 5 for balance: no idea why this would be down-voted.
Thanks. Must be my colleagues and friends who cannot approve of my point of view regarding Java ;p
mark merrens wrote:
It's just another tool, no more, no less. Use it if it fits the task.
Yeah sure, although the definition of a bad language may be that it does not fit any task ;) Of course that's hardly the case with Java as it fits almost any task...
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
} -
I like Java! I prefer programming in NetBeans for an IDE. Java is not horrible.
If it moves, compile it
-
I don't think the language is terrible, but I think the run time is a steaming pile.
CPallini wrote:
You cannot argue with agile people so just take the extreme approach and shoot him. :Smile:
Shelby Robertson wrote:
I don't think the language is terrible, but I think the run time is a steaming pile.
Meaning what exactly? That it is buggy? That you have a problem with performance? I haven't seen the former. And the latter is meaningless in standard business programming because in the vast majority of cases language choice will have not impact on that.
-
There's nothing particularly horrible about Java at all. I don't like the syntax, but I never liked C/C++ either; that's just a personal preference. Part of the horror of Java, I suppose, is that for a long time people were trying to make it do everything, while its designers intended it to run smart coffee pots. Over time, things got better, expectations got more realistic, and the language (along with its libraries) got a lot better. Enjoy it... :-D
Will Rogers never met me.
Roger Wright wrote:
There's nothing particularly horrible about Java at all. I don't like the syntax, but I never liked C/C++ either; that's just a personal preference.
Versus what language? C#? The overall structure of C# is similar to C++ and Java. Versus Perl? Cobol? Fortran? Those are different from C#, C++ and Java.