C# on the left, Java on the right: 1. Properties: You will immediately notice, that in java you have to write get/set methods instead of properties.2....
The Evolution of the C# Language An interesting part of our conversation revolved...
A question that’s often asked is how many programming languages should I learn...
If you’ve worked in the world of the internet at any point in the past few years, the...
Pointers in C are easy and fun to learn. Some C programming tasks are performed more...
Articles
Tips
Events
Latest Post
What does it exactly mean when people say that C# is better than Java?
Unknown 3:54 AM 0
C# learnt from many mistakes that Java had. C# has decimal fixed point. C# has var (local variable type inference) since 3.0. C# has real...
Currently, which one is best: C#, Java or C++?
Unknown 3:45 AM 0
If you are developing applications for Windows desktops, or for Windows servers (e.g. ASPdotNET), or for Windows phone, then C#. If you are...
The Past, Present, and Future of C#
Unknown 3:30 AM 0
The Evolution of the C# Language An interesting part of our conversation revolved around the concept that developers are often divided into two...
Do people/companies still use C# programming
Unknown 3:22 AM 0
C# is pretty much the language for developing business applications targeting a Windows environment, and it's a leading Web language, as well as gaining ground...
Tips for fast loading of HTML pages
Unknown 11:38 PM 0
These tips are based upon common knowledge and experimentation. An optimized web page not only provides for a more responsive site for your...
Thursday, September 8, 2016
What are some examples of how C# and Java differ in syntax and capabilities?
C# on the left, Java on the right:
1. Properties: You will immediately notice, that in java you have to write get/set methods instead of properties.
2. Virtual/Final: Very important difference is, that all methods and properties in java are implicitly virtual. In C# you have to explicitly tell that the property or method is virtual. On the other side, in java, you have to implicitly tell that a method is final (resp, sealed).
3. In C# you can also write properties and method using Lambda syntax (see Test property);
4. In C# you can write optional method parameters. In Java you can achieve the same by method overloading:
Related : To Learn C# fromSratch
5. implicit typing:
- //C#:
- var person = new Person();
- //variable person is of type Person, obviosly
- //Java
- Person person = new Person(); //variable type must be expressed explicitelly
6. Linq:
given that I have following collection of people:
- var people = new[]
- {
- new Person { FirstName = "Daniel", LastName = "Turan" },
- new Person { FirstName = "John", LastName = "Smith" },
- new Person { FirstName = "John", LastName = "Brown" }
- }
in C# i can query against the collection like:
- var me = people .Where(p => p.FirstName == "Daniel").First();
- var numberOfJohns = people.Count(p => p.FirstName == "John");
- var mostFrequestNames = people
- .GroupBy(p => p.FirstName)
- .OrderByDescenting(group => group.Count())
- .Select(group => new
- {
- Name = group.Key,
- Occurences = group.Count()
- });
Linq has fundamentally changes the way we write C# code. In java there is still no alternative that is good enough.
There is much more syntactic sweetness in C#, like async/await, which greatly improves readability and maintainability of asynchronous code, string interpolation, extension method and a lot more.
References :
What does it exactly mean when people say that C# is better than Java?
C# learnt from many mistakes that Java had.
- C# has decimal fixed point.
- C# has
(local variable type inference) since 3.0.var
- C# has real generics ("reified generics") since 2.0. Java has fake generics ("erasure generics") since Java 5.
- C# has real properties.
- C# has value types.
- C# has attributes since the very beginning. Java only has annotations (the Java equivalent to attributes) since Java 5.
- Ditto for for-each loops.
- Ditto for auto-boxing and auto-unboxing.
- Ditto for varargs.
- C# has
(and the dispose pattern, viausing
IDisposable
) since the very beginning. Java only has try-with-resources (the Java equivalent to
) since Java 7.using
- Ditto for string switches. Also note that C# switches are more versatile than Java's ones; you can use
andgoto case
to jump to other cases.goto default
- C# has lambdas since 3.0, long before Java did (Java 8).
- Ditto for extension methods. (The closest thing Java has to extension methods are interface default methods, and those are introduced in Java 8.)
- C# has static classes (non-instantiable classes where all methods have to be static) since 2.0. In Java, you can hack around it by making a class with only private constructors, but you can still define non-static methods in such a class.
- C# methods are non-virtual by default. In Java you can only make a method non-virtual by making it private or final.
- C# requires using
when overriding, and forbids usingoverride
when not overriding. This makes it easier to detect when a refactor is breaking other code.override
- C# has operator overloading.
- C# has compile-time constants using
. In Java, you can only have compile-time constants for numbers, booleans, characters, and strings.const
- C# does not have checked exceptions. Many programmers consider checked exceptions a broken concept.
- C# has named and optional arguments since 4.0.
- C# has
andref
parameters. In Java, everything is pass-by-value; it's not possible to have pass-by-reference.out
- C# has enumerator generators via
since 2.0.yield
- Covariant and contravariant generic type parameters have been around since Java 5, but were introduced in C# 4.0.
- Java enumerations (which are full-fledged classes) are much more advanced than C# enumerations (which are basically just integers). For example, you can use it to implement a simple state machine.
- Java has
BigDecimal
which provides decimal floating point, as opposed to C#'s builtin decimal fixed point.
Currently, which one is best: C#, Java or C++?
- If you are developing applications for Windows desktops, or for Windows servers (e.g. ASPdotNET), or for Windows phone, then C#.
- If you are developing a PC game or writing an OS, then C or C++.
- If you are writing server applications (e.g. web or mobile), or targeting Android phones, then Java.
- If you are targeting iPhones/iPads, then ObjectiveC or Swift.
- If you are building the browser side of an application, or if using node.js, then Javascript.
- Since the comments I keep getting are pointing out how non-universal my original answer to this silly question was, I should point out that there are many other computer languages that are great for various uses. Python, PHP, Perl, Ruby, assembly, whatever.
Therefore "best" is not just an irrelevant term (especially if no specialization in domain is stated), it's also subjective and individual- / group dependent. I.e. before stating the "best", first state "what" you want to do as well as what you know and how well you can use it (unless you're willing / able to spend a lot of time trying to become an expert in something you don't know). Only then could you even attempt at rating a language's suitability.
The interesting thing is that, once you master a single language, conquering others will not be that tough!
So, suggestion for the beginners: Be the master of a modern language(whatever suits you) & after that try to gather basic knowledge of others, eventually if you have time, master those as well.
The Past, Present, and Future of C#
The Evolution of the C# Language
Writing Quality Code with C#: Common Gotchas
The Future of C#
References :
Do people/companies still use C# programming
C# is pretty much the language for developing business applications targeting a Windows environment, and it's a leading Web language, as well as gaining ground in game programming with the XNA Framework plugin and easy porting of titles between PC and XBox. According to statistics at TIOBE Software based on recruited positions by employers and advertised programming language skills among developers, C# is currently the number 5 language, behind C, Java, Obj-C and C++.
Objective-C's popularity is driven by the resurgence of Apple technologies, starting around 2006 with the iPhone and iPod Touch, and bleeding back into desktops with OSX in several key development fields such as graphics design, audio production etc. C and C++ have always been must-have languages across the spectrum, especially for "close-to-the-metal" development work like device drivers and performance-critical graphics and calculation-intensive applications, as well as for Linux distros and applications therefore (though Mono, a .NET workalike, is not unheard of in that space). Java's current popularity is tied to that of Android, which has recently overtaken iOS to become the most popular mobile OS on the planet. It's also a popular web language, and not unheard of for desktop development work either (Apache OpenOffice and several other office productivity competitors to Microsoft Office are written in it).
However, most small to medium businesses need one thing from their in-house developers; applications that run on Windows (the dominant OS for business workstations; 80%+ of corporate market share), which allow the user to retrieve and manipulate information from a data storage server (traditionally an in-house DB server, increasingly cloud data services). For many such applications, inter-op with applications installed on the workstation is a must, and that usually precludes an HTML-based intranet application of any language. C# and the .NET Framework excels in this space; the language was designed to produce powerful, inter-operable desktop applications quickly and efficiently.
On top of that, it would be nice to use the same language and libraries of common business logic to create that customer-facing web portal, too; C# and ASP .NET are very common choices here for that reason. The .NET Framework powers about 17% of websites with a known server-side architecture, which puts it at #2 behind a dominant PHP (largely due to the widespread adoption of low-cost PHP "website-in-a-box" products like Joomla, WordPress, Drupal, phpBB, SMF, vBulletin etc which power the overwhelming majority of online discussion forums and blog sites). Anything else on the radar (Servlets/JSP, Python, RoR, Perl, Node.JS) is in the low single digits of not at fractions of a percent of known server architectures.
So yeah, people and companies still use C#. Knowing your stuff in .NET is a hot commodity, so much so that long-term unemployment (jobless > 6 months) among people with significant (3+ years) .NET experience is something like 0.4%, beating the industry average of 2.8%.
References :
Sunday, July 3, 2016
Tips for fast loading of HTML pages
EDIT
Reduce page weight
Minimize the number of files
If-Modified-Since
request to the web server for each CSS, JavaScript or image file, asking whether the file has been modified since the last time it was downloaded.Reduce domain lookups
Cache reused content
Last-Modified
header. It allows for efficient page caching; by means of this header, information is conveyed to the user agent about the file it wants to load, such as when it was last modified. Most web servers automatically append the Last-Modified
header to static pages (e.g. .html
, .css
), based on the last-modified date stored in the file system. With dynamic pages (e.g. .php
, .aspx
), this, of course, can't be done, and the header is not sent.- HTTP Conditional Get for RSS Hackers
- HTTP 304: Not Modified
- HTTP ETag on Wikipedia
- Caching in HTTP
- Learn HTML
Optimally order the components of the page
Reduce the number of inline scripts
document.write()
to output content in particular, can improve overall page loading. Use modern AJAX methods to manipulate page content for modern browsers, rather than the older approaches based ondocument.write()
.Use modern CSS and valid markup
Chunk your content
<div>
blocks, and in the near future, CSS3 Multi-column Layout or CSS3 Flexible Box Layout, should be used instead.<TABLE>
<TABLE>
<TABLE>
...
</TABLE>
</TABLE>
</TABLE>
<TABLE>...</TABLE>
<TABLE>...</TABLE>
<TABLE>...</TABLE>
Minify and compress SVG assets
Specify sizes for images and tables
height
and width
should be specified for images, whenever possible.table-layout: fixed;
COL
and COLGROUP
HTML tags.