Showing posts with label Java vs C#. Show all posts
Showing posts with label Java vs C#. Show all posts

Thursday, May 1, 2014

Java vs. C# - Resource Auto Closing

       

            static String readFirstLineFromFile(String path) throws IOException {
              try (BufferedReader br =
                          new BufferedReader(new FileReader(path))) {
                      return br.readLine();
              }
            }
       
 
The above is similar and appears to have the same use case as the C# use statement, in that it allows you to omit the finally block so long as the resource in question implements java.lang.AutoCloseable (Java) vs IDisposeable .NET. The above was new in Java SE 7. ref: http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html

Monday, March 17, 2014

Static Classes in Java and C#

The semantics of them are entirely different. In C# it connotes a utility class; in Java it denotes independence from containing class (top level static classes are not allowed in Java).

See Skeet's answer for details: http://stackoverflow.com/questions/7486012/static-classes-in-java