In a Windows XP machine there's a folder copied from a Unix machine which contains many useless and hidden .cache folders. Following script can delete all these hidden folders recursively in DOS command line:
C:\temp>for /f "tokens=* delims=" %x in ('dir /s /b /a:d *cache') do rd /s /q "%x"
Alternatively we can create .bat batch file so we can just click it to run the script, but the token needs to be changed from %x to %%x:
for /f "tokens=* delims=" %%x in ('dir /s /b /a:d *cache') do rd /s /q "%%x"
Monday, November 15, 2004
Friday, November 12, 2004
C# vs Java
C# syntax is very similar to Java. Most noticeable ones to me are following ( based on C# 1.0 and Java 1.4):
1. C# uses namespace to organize the class by "using" keyword. Not like Java's package, C#'s namespace is purely logical without any implication of file/folder relation.
2. No "throws" in C# since C# doesn't have checked exceptions. C# only handles exception when it's actually thrown (not may be thrown). While in Java you must try-catch a potential exception or throws it explicitly, otherwise your code won't compile.
3. C# has "internal" and "protected internal" access modifiers. You can define a class with more granular scale.
3. No primitive type in C#. All C# types are rooted from System.Object. Following code is fine in C# but not in Java:
ArrayList list = new ArrayList
list.Add(123); // Java compile error
int number = (int)list[0]; // Java compile error
Type type = number.GetType(); // Java compile error
5. C# property is more intuitive than Java's accessor methods.
6. C# has "struct" while Java doesn't. .NET will put structs in stack instead of heap.
7. C# has "virtual" functions and you have to use "override" modifier explicitly to override a method in subclasses. A "new" function in C# creates a new method with same signature in subclasses, which is only visible in that specific class. Java doesn't have "virtual", "override" and "new" function modifiers. Function is picked based on class type checking.
8. C# doesn't have "final" constants but it has "const" and "readonly" for constant declaration. The difference between "const" and "readonly":
const
9. C# has delegate - a type-safe method pointer. This delegate is very useful from my opinion. You can do interesting things similar to C/C++ pointers. Java doesn't have equivalent function.
10. Passing by values is default in C#. In addition C# has option to pass by references using keyword of "ref" or "out" (you have to initialize the "out" parameters). You can not pass by references in Java (for objects, Java creates a copy of parameter pointing to the same object in the heap, which leads to confusion in some cases).
Looks like C# is more powerful than Java at a glance, or just some syntax sugar you would argue?
1. C# uses namespace to organize the class by "using" keyword. Not like Java's package, C#'s namespace is purely logical without any implication of file/folder relation.
2. No "throws" in C# since C# doesn't have checked exceptions. C# only handles exception when it's actually thrown (not may be thrown). While in Java you must try-catch a potential exception or throws it explicitly, otherwise your code won't compile.
3. C# has "internal" and "protected internal" access modifiers. You can define a class with more granular scale.
3. No primitive type in C#. All C# types are rooted from System.Object. Following code is fine in C# but not in Java:
ArrayList list = new ArrayList
list.Add(123); // Java compile error
int number = (int)list[0]; // Java compile error
Type type = number.GetType(); // Java compile error
5. C# property is more intuitive than Java's accessor methods.
6. C# has "struct" while Java doesn't. .NET will put structs in stack instead of heap.
7. C# has "virtual" functions and you have to use "override" modifier explicitly to override a method in subclasses. A "new" function in C# creates a new method with same signature in subclasses, which is only visible in that specific class. Java doesn't have "virtual", "override" and "new" function modifiers. Function is picked based on class type checking.
8. C# doesn't have "final" constants but it has "const" and "readonly" for constant declaration. The difference between "const" and "readonly":
const
- Can't be static.
- Value evaluated at compile time.
- Initialized at declaration only.
- Can be static or instance.
- Value evaluated at run time.
- Declaration or initialized in the constructor.
9. C# has delegate - a type-safe method pointer. This delegate is very useful from my opinion. You can do interesting things similar to C/C++ pointers. Java doesn't have equivalent function.
10. Passing by values is default in C#. In addition C# has option to pass by references using keyword of "ref" or "out" (you have to initialize the "out" parameters). You can not pass by references in Java (for objects, Java creates a copy of parameter pointing to the same object in the heap, which leads to confusion in some cases).
Looks like C# is more powerful than Java at a glance, or just some syntax sugar you would argue?
Subscribe to:
Posts (Atom)