New Apps

Articles

Tips

Events

Improve Soft Skills

Tips


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:

  1. //C#:
  2. var person = new Person();
  3. //variable person is of type Person, obviosly
  4.  
  5. //Java
  6. Person person = new Person(); //variable type must be expressed explicitelly


6. Linq:
given that I have following collection of people:

  1. var people = new[]
  2. {
  3. new Person { FirstName = "Daniel", LastName = "Turan" },
  4. new Person { FirstName = "John", LastName = "Smith" },
  5. new Person { FirstName = "John", LastName = "Brown" }
  6. }


in C# i can query against the collection like:

  1. var me = people .Where(p => p.FirstName == "Daniel").First();
  2.  
  3. var numberOfJohns = people.Count(p => p.FirstName == "John");
  4.  
  5. var mostFrequestNames = people
  6. .GroupBy(p => p.FirstName)
  7. .OrderByDescenting(group => group.Count())
  8. .Select(group => new
  9. {
  10. Name = group.Key,
  11. Occurences = group.Count()
  12. });


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 :



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 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 using (and the dispose pattern, via IDisposable) since the very beginning. Java only has try-with-resources (the Java equivalent to using) since Java 7.
  • Ditto for string switches. Also note that C# switches are more versatile than Java's ones; you can use goto case and goto default to jump to other cases.
  • 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 override when overriding, and forbids using override when not overriding. This makes it easier to detect when a refactor is breaking other code.
  • C# has operator overloading.
  • C# has compile-time constants using const. In Java, you can only have compile-time constants for numbers, booleans, characters, and strings.
  • 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 ref and out parameters. In Java, everything is pass-by-value; it's not possible to have pass-by-reference.
  • C# has enumerator generators via yield since 2.0.

Having said that, there are things that actually appeared in Java first, that C# either doesn't have or has caught up to later:

  • 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.
Yes. C# lacks some stuff java has but events with deleagetes, async/await or LINQ have advantage over type variance (covariance and contravariance) in java.




  • 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.

Simply using the "best" language related to the domain still doesn't mean it's going to give you the "best" results in the "quickest" / "easiest" manner. Just that it's more possible than with others. It's still very much up to what the programmer knows and implements. None of them (any language ever invented - not just those you've listed) are anything close to a "magic-bullet".

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.


Frankly speaking, every programming language is Best, if you can master it. For example, A person with sound knowledge over only C is a valuable key resource compared with a person having 'basic knowledge' on many languages.

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.


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 :



These tips are based upon common knowledge and experimentation.
An optimized web page not only provides for a more responsive site for your visitors, but also reduces the load on your web servers and Internet connection. This can be crucial for high volume sites or sites which have a spike in traffic due to unusual circumstances such as breaking news stories.
Optimizing page load performance is not just for content which will be viewed by narrow band dial-up or mobile device visitors. It is just as important for broadband content and can lead to dramatic improvements even for your visitors with the fastest connections.

EDIT

Reduce page weight

Page weight is by far the most important factor in page-load performance.
Reducing page weight through the elimination of unnecessary whitespace and comments, commonly known as minimization, and by moving inline script and CSS into external files, can improve download performance with minimal need for other changes in the page structure.
Tools such as HTML Tidy can automatically strip leading whitespace and extra blank lines from valid HTML source. Other tools can "compress" JavaScript by reformatting the source or by obfuscating the source and replacing long identifiers with shorter versions.

Minimize the number of files

Reducing the number of files referenced in a web page lowers the number of HTTP connections required to download a page.
Depending on a browser's cache settings, it may send an 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.
By reducing the number of files that are referenced within a web page, you reduce the time required for these requests to be sent, and for their responses to be received.
If you use background images a lot in your CSS, you can reduce the amount of HTTP lookups needed by combining the images into one, known as an image sprite. Then you just apply the same image each time you need it for a background, and adjust the x/y coordinates appropriately. This technique works best with elements that will have limited dimensions, and will not work for every use of a background image. However, the fewer HTTP requests and single image caching can help reduce pageload time.
Too much time spent querying the last modified time of referenced files can delay the initial display of a web page, since the browser must check the modification time for each CSS or JavaScript file, before rendering the page.

Reduce domain lookups

Since each separate domain costs time in a DNS lookup, the page load time will grow along with the number of separate domains appearing in CSS link(s) and JavaScript and image src(es).
This may not always be practical; however, you should always take care to use only the minimum necessary number of different domains in your pages.

Cache reused content

Make sure that any content that can be cached, is cached, and with appropriate expiration times.
In particular, pay attention to the 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.
So, in particular for pages which are generated dynamically, a little research on this subject is beneficial. It can be somewhat involved, but it will save a lot in page requests on pages which would normally not be cacheable.
More information:
  1. HTTP Conditional Get for RSS Hackers
  2. HTTP 304: Not Modified
  3. HTTP ETag on Wikipedia
  4. Caching in HTTP
  5. Learn HTML

Optimally order the components of the page

Download page content first, along with any CSS or JavaScript that may be required for its initial display, so that the user gets the quickest apparent response during the page loading. This content is typically text, and can therefore benefit from text compression in transit, thus providing an even quicker response to the user.
Any dynamic features that require the page to complete loading before being used, should be initially disabled, and then only enabled after the page has loaded. This will cause the JavaScript to be loaded after the page contents, which will improve the overall appearance of the page load.

Reduce the number of inline scripts

Inline scripts can be expensive for page loading, since the parser must assume that an inline script could modify the page structure while parsing is in progress. Reducing the use of inline scripts in general, and reducing the use of 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

Use of modern CSS reduces the amount of markup, can reduce the need for (spacer) images, in terms of layout, and can very often replace images of stylized text -- that "cost" much more than the equivalent text-and-CSS.
Using valid markup has other advantages. First, browsers will have no need to perform error-correction when parsing the HTML (this is aside from the philosophical issue of whether to allow format variation in user input, and then programmatically "correct" or normalize it; or whether, instead, to enforce a strict, no-tolerance input format).
Moreover, valid markup allows for the free use of other tools which can pre-process your web pages. For example, HTML Tidy can remove whitespace and optional ending tags; however, it will refuse to run on a page with serious markup errors.

Chunk your content

Tables for layouts are a legacy method that should not be used any more. Layouts utilizing <div> blocks, and in the near future, CSS3 Multi-column Layout or CSS3 Flexible Box Layout, should be used instead.
Tables are still considered valid markup, but should be used for displaying tabular data. To help the browser render your page quicker, you should avoid nesting your tables.
Rather than deeply nesting tables as in:
<TABLE>
  <TABLE>
    <TABLE>
          ...
    </TABLE>
  </TABLE>
</TABLE>
use non-nested tables or divs as in
<TABLE>...</TABLE>
<TABLE>...</TABLE>
<TABLE>...</TABLE>

Minify and compress SVG assets

SVG produced by most drawing applications often contains unnecessary metadata which can be removed. Configure your servers apply gzip compression for SVG assets.

Specify sizes for images and tables

If the browser can immediately determine the height and/or width of your images and tables, it will be able to display a web page without having to reflow the content. This not only speeds the display of the page but prevents annoying changes in a page's layout when the page completes loading. For this reason, height and width should be specified for images, whenever possible.
Tables should use the CSS selector:property combination:
table-layout: fixed;
and should specify widths of columns using the COL and COLGROUP HTML tags.

Choose your user-agent requirements wisely

To achieve the greatest improvements in page design, make sure that reasonable user-agent requirements are specified for projects. Do not require your content to appear pixel-perfect in all browsers, especially not in down-version browsers.
Ideally, your basic minimum requirements should be based on the consideration of modern browsers that support the relevant standards. This can include recent versions of Firefox, Internet Explorer, Google Chrome, Opera, and Safari.
Note, however, that many of the tips listed in this article are common-sense techniques which apply to any user agent, and can be applied to any web page, regardless of browser-support requirements.

References :



If you’re new to Java, or just looking to brush up on the details, then this is the article is for you!
As far as prerequisites go, we’re going to assume you understand how to program (perhaps in PHP, or Visual Basic or C++), but that you are unfamiliar with the specifics of programming in the Java language. We aren’t going to teach you to program; we’re going to provide you with clear examples of commonly used Java language constructs and principles, while pointing out some Android-specific tips and tricks.
Technically, you don’t need any tools to complete this article you will certainly need them to develop Android applications.
To develop Android applications (or any Java applications, for that matter), you need a development environment to write and build applications. Eclipse is a very popular development environment (IDE) for Java and the preferred IDE for Android development. It’s freely available for Windows, Mac, and Linux operating systems.
For complete instructions on how to install Eclipse (including which versions are supported) and the Android SDK, see the Android developer website.
Android applications are developed using the Java language. As of now, that’s really your only option for native applications. Java is a very popular programming language developed by Sun Microsystems (now owned by Oracle). Developed long after C and C++, Java incorporates many of the powerful features of those powerful languages while addressing some of their drawbacks. Still, programming languages are only as powerful as their libraries. These libraries exist to help developers build applications.
Some of the Java’s important core features are:
  • It’s easy to learn and understand
  • It’s designed to be platform-independent and secure, using
    virtual machines
  • It’s object-oriented
Android relies heavily on these Java fundamentals. The Android SDK includes many standard Java libraries (data structure libraries, math libraries, graphics libraries, networking libraries and everything else you could want) as well as special Android libraries that will help you develop awesome Android applications.
Java is easy to learn for a variety of reasons. There’s certainly no shortage of Java resources out there to help you learn the language, including websites, tutorials, books, and classes. Java is one of the most widely discussed, taught, and used programming languages on the planet. It’s used for many different types of programming projects, no matter their scale, from web applications to desktop applications to mobile applications.
If you’re coming from a traditional programming background like C or C++, you’ll find Java syntax quite similar. If you’re not, then take comfort in knowing that you’ve chosen one of the easiest languages to learn. You’ll be up and running in no time at all.
Finally, Java is one of the most human-readable languages out there, by which we mean that a person who knows nothing about programming can often look at some Java code and have at least an inkling what it’s doing. Consider the following example:
If you simply read the code aloud, you can pretty much tell that this snippet of code is doing. There’s a single letter variable called character. If the character variable equals the letter a, then we do something (call the doSomething() method), otherwise we do something else (by calling the doSomethingElse() method).
With many programming languages, you need to use a compiler to reduce your code down into machine language that the device can understand. While this is well and good, different devices use different machine languages. This means that you might need to compile your applications for each different device or machine language—in other words, your code isn’t very portable. This is not the case with Java. The Java compilers convert your code from human readable Java source files to something called “bytecode” in the Java world. These are interpreted by a Java Virtual Machine, which operates much like a physical CPU might operate on machine code, to actually execute the compiled code. Although it might seem like this is inefficient, much effort has been put into making this process very fast and efficient. These efforts have paid off in that Java performance in generally second only to C/C++ in common language performance comparisons.
Android applications run in a special virtual machine called the Dalvik VM. While the details of this VM are unimportant to the average developer, it can be helpful to think of the Dalvik VM as a bubble in which your Android application runs, allowing you to not have to worry about whether the device is a Motorola Droid, an HTC Evo, or the latest toaster running Android. You don’t care so long as the device is Dalvik VM friendly—and that’s the device manufacturer’s job to implement, not yours.
Let’s take this bubble idea a bit further. Because Java applications run within the bubble that is a virtual machine, they are isolated from the underlying device hardware. Therefore, a virtual machine can encapsulate, contain, and manage code execution in a safe manner compared to languages that operate in machine code directly. The Android platform takes things a step further. Each Android application runs on the (Linux-based) operating system using a different user account and in its own instance of the Dalvik VM. Android applications are closely monitored by the operating system and shut down if they don’t play nice (e.g. use too much processing power, become unresponsive, waste resources, etc.). Therefore, it’s important to develop applications that are stable and responsive. Applications can communicate with one another using well-defined protocols.
Like many languages, Java is still a compiled language even though it doesn’t compile all the way down to machine code. This means you, the developer, need to compile your Android projects and package them up to deploy onto devices. The Eclipse development environment (used with the Android Development plug-in) makes this pretty painless. In Eclipse, automatic compilation is often turned on by default. This means that every time you save a project file, Eclipse recompiles the changes for your application package. You immediately see compile errors. Eclipse also interprets Java as you type, providing handy code coloring and formatting as well as showing many types of errors as you go. Often, you can click on the error and have Eclipse automatically fix a typo, or add an import statement, or provide a method stub for you, saving lots of typing.
You can still manually compile your code if you so desire. Within Eclipse, you’ll find the Build settings under the project menu. If you have “Build Automatically” turned on, you can still choose the “Clean…” option that will allow you to do full rebuild of all files. If “Build Automatically” is turned off, “Build All” and “Build Project” menu options are enabled. "Build All" means to build all of the projects in the workspace. You can have many projects in an Eclipse workspace.
The build process, for regular Java projects, results in a file with the extension of JAR – Java ARchive. Android applications take JAR files and package them for deployment on devices as Android PacKage files with an extension .apk. These formats not only include your compiled Java code, but also any other resources, such as strings, images, or sound files, that your application requires to run as well as the Application Manifest file, AndroidManifest.xml. The Android Manifest file is a file required by all Android applications, which you use to define configuration details about your app.
Okay. Time for a very brief and 20,000 foot view of object oriented programming (OOP). OOP is a programming style or technique that relies upon the definition of data structures called objects. For those new to OOP, an object can be thought of much like a custom data type. For example, you might have a Dog object, which represents the blueprint for a generic dog, with a name, breed, and gender. You could then create different instances of the Dog object to represent specific dogs. Each Dog object must be created by calling its constructor (a method that has the same name as the object itself, and may or may not have parameters for setting initial values). For example, the following Dog objects use a constructor with three parameters (name, breed, gender):
So where is this Dog object defined? Well, here we need to begin defining some of the fundamental building blocks of the Java programming language. A class provides a definition for an object. Therefore, there is a Dog class somewhere—either defined by you or in some library somewhere. Generally speaking, a class will be defined in its own file, with the filename matching the class name (e.g. Dog.java). There are exceptions to this rule, such as classes defined within other classes (when a class is declared within a class, it is generally defined for use within the parent class only as a helper class, and referred to as aninner class).
When you want to reference an object from within another class, you need to include an import statementin the top of your class file, much like you would use a #include statement in a compiled language like C.
A class typically describes the data and behavior of an object. The behavior is defined using classmethods. Method is the common term for a subroutine in an OOP language. Many common object classes are defined in shared class libraries like software development kits (SDKs), whereas others are defined by you, the developer, for your own purposes. Software is then built up by using and manipulating object instances in different ways.
Please realize this is a very generalized definition of OOP. There are entire books written on this subject. If you’d like to know more about OOP, here are a few resources you might want to check out:
Note: We use a lot of different terminology in this tutorial. There are multiple ways to refer to a given concept (e.g. superclass vs. parent class), which is confusing to those new to object oriented programming. Different developers use different terms, and so we have tried to mention synonyms where appropriate. Deciding which terms you will use is a personal choice.
Here is another important Java concept you’ll run into a lot: inheritance. Simply put, inheritance means that Java classes (and therefore objects) can be organized into hierarchies with lower, more specific, classes in the hierarchy inheriting behavior and traits from higher, more generic, classes.
This concept is best illustrated by example. Let’s pretend we are developing a Java application to simulate an aquarium. This aquarium has some fish in it. Therefore, we might define a class to represent a fish. This class, called Fish, could include some data fields (also called attributes, or class member variables) to describe a fish object: species, color and size; as well as some of its behavior in the form of methods (also called subroutines, or functions in procedural languages), like eat(), sleep(), and makeBabyFish().
A special type of method, called a constructor, is used to create and initialize an object; constructors are named the same as their class and may include parameters. The following Fish class has two constructors: one for creating a generic Fish object and another for constructing a specific Fish object with some initial data. You’ll also see that the Fish class has two eat() methods: one for eating something random, and another for eating another fish, which would be represented by another instance of the Fish class:
Classes can be organized into hierarchies, where a derived class (or subclass) includes all the features of its parent class (or superclass), but refines and adds to them to define a more specific object using the extends keyword. This is called inheritance.
For example, the Fish class might have two subclasses: FreshwaterFish and SaltwaterFish. These subclasses would have all the features of the Fish class, but could further customize the objects through new attributes and behaviors or modified behaviors from the parent class Fish. For example, the FreshwaterFish class might include information about the type of freshwater environment lived in (e.g. river, lake, pond, or puddle). Similarly, the SaltwaterFish class might customize the makeBabyFish() method such that the fish eats its mate after breeding (as defined in the super class) by using the override mechanism, like this:
In Java, you can organize object behaviors in what are called interfaces. While a class defines an object, an interface defines some behavior that can be applied to an object. For example, we could define a Swimmer interface that provides a set of methods that are common across all objects that can swim, whether they are fish, otters, or submergible androids. The Swimmer interface might specify four methods: startSwimming(), stopSwimming(), dive(), and surface().
A class like Fish could then implement the Swimmer interface (using the implements keyword) and provide implementations of the swimming behavior:
Class hierarchies, such as our fish classes, can then be organized into packages. A package is simply a set of classes and interfaces, bundled together. Developers use namespaces to uniquely name packages. For example, we could use com.mamlambo.aquarium or com.ourclient.project.subproject as our package name to keep track of our fish-related classes.
Wow! You’ve just embarked on a crash-course in Java for Android development. We’ve covered a pretty intense amount of material here

References :

Showing posts with label Tips. Show all posts
Showing posts with label Tips. Show all posts

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:

  1. //C#:
  2. var person = new Person();
  3. //variable person is of type Person, obviosly
  4.  
  5. //Java
  6. Person person = new Person(); //variable type must be expressed explicitelly


6. Linq:
given that I have following collection of people:

  1. var people = new[]
  2. {
  3. new Person { FirstName = "Daniel", LastName = "Turan" },
  4. new Person { FirstName = "John", LastName = "Smith" },
  5. new Person { FirstName = "John", LastName = "Brown" }
  6. }


in C# i can query against the collection like:

  1. var me = people .Where(p => p.FirstName == "Daniel").First();
  2.  
  3. var numberOfJohns = people.Count(p => p.FirstName == "John");
  4.  
  5. var mostFrequestNames = people
  6. .GroupBy(p => p.FirstName)
  7. .OrderByDescenting(group => group.Count())
  8. .Select(group => new
  9. {
  10. Name = group.Key,
  11. Occurences = group.Count()
  12. });


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 var (local variable type inference) since 3.0.
  • 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 using (and the dispose pattern, via IDisposable) since the very beginning. Java only has try-with-resources (the Java equivalent to using) since Java 7.
  • Ditto for string switches. Also note that C# switches are more versatile than Java's ones; you can use goto case and goto default to jump to other cases.
  • 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 override when overriding, and forbids using override when not overriding. This makes it easier to detect when a refactor is breaking other code.
  • C# has operator overloading.
  • C# has compile-time constants using const. In Java, you can only have compile-time constants for numbers, booleans, characters, and strings.
  • 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 ref and out parameters. In Java, everything is pass-by-value; it's not possible to have pass-by-reference.
  • C# has enumerator generators via yield since 2.0.

Having said that, there are things that actually appeared in Java first, that C# either doesn't have or has caught up to later:

  • 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.
Yes. C# lacks some stuff java has but events with deleagetes, async/await or LINQ have advantage over type variance (covariance and contravariance) in java.


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.

Simply using the "best" language related to the domain still doesn't mean it's going to give you the "best" results in the "quickest" / "easiest" manner. Just that it's more possible than with others. It's still very much up to what the programmer knows and implements. None of them (any language ever invented - not just those you've listed) are anything close to a "magic-bullet".

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.


Frankly speaking, every programming language is Best, if you can master it. For example, A person with sound knowledge over only C is a valuable key resource compared with a person having 'basic knowledge' on many languages.

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.

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



These tips are based upon common knowledge and experimentation.
An optimized web page not only provides for a more responsive site for your visitors, but also reduces the load on your web servers and Internet connection. This can be crucial for high volume sites or sites which have a spike in traffic due to unusual circumstances such as breaking news stories.
Optimizing page load performance is not just for content which will be viewed by narrow band dial-up or mobile device visitors. It is just as important for broadband content and can lead to dramatic improvements even for your visitors with the fastest connections.

EDIT

Reduce page weight

Page weight is by far the most important factor in page-load performance.
Reducing page weight through the elimination of unnecessary whitespace and comments, commonly known as minimization, and by moving inline script and CSS into external files, can improve download performance with minimal need for other changes in the page structure.
Tools such as HTML Tidy can automatically strip leading whitespace and extra blank lines from valid HTML source. Other tools can "compress" JavaScript by reformatting the source or by obfuscating the source and replacing long identifiers with shorter versions.

Minimize the number of files

Reducing the number of files referenced in a web page lowers the number of HTTP connections required to download a page.
Depending on a browser's cache settings, it may send an 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.
By reducing the number of files that are referenced within a web page, you reduce the time required for these requests to be sent, and for their responses to be received.
If you use background images a lot in your CSS, you can reduce the amount of HTTP lookups needed by combining the images into one, known as an image sprite. Then you just apply the same image each time you need it for a background, and adjust the x/y coordinates appropriately. This technique works best with elements that will have limited dimensions, and will not work for every use of a background image. However, the fewer HTTP requests and single image caching can help reduce pageload time.
Too much time spent querying the last modified time of referenced files can delay the initial display of a web page, since the browser must check the modification time for each CSS or JavaScript file, before rendering the page.

Reduce domain lookups

Since each separate domain costs time in a DNS lookup, the page load time will grow along with the number of separate domains appearing in CSS link(s) and JavaScript and image src(es).
This may not always be practical; however, you should always take care to use only the minimum necessary number of different domains in your pages.

Cache reused content

Make sure that any content that can be cached, is cached, and with appropriate expiration times.
In particular, pay attention to the 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.
So, in particular for pages which are generated dynamically, a little research on this subject is beneficial. It can be somewhat involved, but it will save a lot in page requests on pages which would normally not be cacheable.
More information:
  1. HTTP Conditional Get for RSS Hackers
  2. HTTP 304: Not Modified
  3. HTTP ETag on Wikipedia
  4. Caching in HTTP
  5. Learn HTML

Optimally order the components of the page

Download page content first, along with any CSS or JavaScript that may be required for its initial display, so that the user gets the quickest apparent response during the page loading. This content is typically text, and can therefore benefit from text compression in transit, thus providing an even quicker response to the user.
Any dynamic features that require the page to complete loading before being used, should be initially disabled, and then only enabled after the page has loaded. This will cause the JavaScript to be loaded after the page contents, which will improve the overall appearance of the page load.

Reduce the number of inline scripts

Inline scripts can be expensive for page loading, since the parser must assume that an inline script could modify the page structure while parsing is in progress. Reducing the use of inline scripts in general, and reducing the use of 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

Use of modern CSS reduces the amount of markup, can reduce the need for (spacer) images, in terms of layout, and can very often replace images of stylized text -- that "cost" much more than the equivalent text-and-CSS.
Using valid markup has other advantages. First, browsers will have no need to perform error-correction when parsing the HTML (this is aside from the philosophical issue of whether to allow format variation in user input, and then programmatically "correct" or normalize it; or whether, instead, to enforce a strict, no-tolerance input format).
Moreover, valid markup allows for the free use of other tools which can pre-process your web pages. For example, HTML Tidy can remove whitespace and optional ending tags; however, it will refuse to run on a page with serious markup errors.

Chunk your content

Tables for layouts are a legacy method that should not be used any more. Layouts utilizing <div> blocks, and in the near future, CSS3 Multi-column Layout or CSS3 Flexible Box Layout, should be used instead.
Tables are still considered valid markup, but should be used for displaying tabular data. To help the browser render your page quicker, you should avoid nesting your tables.
Rather than deeply nesting tables as in:
<TABLE>
  <TABLE>
    <TABLE>
          ...
    </TABLE>
  </TABLE>
</TABLE>
use non-nested tables or divs as in
<TABLE>...</TABLE>
<TABLE>...</TABLE>
<TABLE>...</TABLE>

Minify and compress SVG assets

SVG produced by most drawing applications often contains unnecessary metadata which can be removed. Configure your servers apply gzip compression for SVG assets.

Specify sizes for images and tables

If the browser can immediately determine the height and/or width of your images and tables, it will be able to display a web page without having to reflow the content. This not only speeds the display of the page but prevents annoying changes in a page's layout when the page completes loading. For this reason, height and width should be specified for images, whenever possible.
Tables should use the CSS selector:property combination:
table-layout: fixed;
and should specify widths of columns using the COL and COLGROUP HTML tags.

Choose your user-agent requirements wisely

To achieve the greatest improvements in page design, make sure that reasonable user-agent requirements are specified for projects. Do not require your content to appear pixel-perfect in all browsers, especially not in down-version browsers.
Ideally, your basic minimum requirements should be based on the consideration of modern browsers that support the relevant standards. This can include recent versions of Firefox, Internet Explorer, Google Chrome, Opera, and Safari.
Note, however, that many of the tips listed in this article are common-sense techniques which apply to any user agent, and can be applied to any web page, regardless of browser-support requirements.

References :

Friday, May 20, 2016

Learn Java for Android Development: Introduction to Java



If you’re new to Java, or just looking to brush up on the details, then this is the article is for you!
As far as prerequisites go, we’re going to assume you understand how to program (perhaps in PHP, or Visual Basic or C++), but that you are unfamiliar with the specifics of programming in the Java language. We aren’t going to teach you to program; we’re going to provide you with clear examples of commonly used Java language constructs and principles, while pointing out some Android-specific tips and tricks.
Technically, you don’t need any tools to complete this article you will certainly need them to develop Android applications.
To develop Android applications (or any Java applications, for that matter), you need a development environment to write and build applications. Eclipse is a very popular development environment (IDE) for Java and the preferred IDE for Android development. It’s freely available for Windows, Mac, and Linux operating systems.
For complete instructions on how to install Eclipse (including which versions are supported) and the Android SDK, see the Android developer website.
Android applications are developed using the Java language. As of now, that’s really your only option for native applications. Java is a very popular programming language developed by Sun Microsystems (now owned by Oracle). Developed long after C and C++, Java incorporates many of the powerful features of those powerful languages while addressing some of their drawbacks. Still, programming languages are only as powerful as their libraries. These libraries exist to help developers build applications.
Some of the Java’s important core features are:
  • It’s easy to learn and understand
  • It’s designed to be platform-independent and secure, using
    virtual machines
  • It’s object-oriented
Android relies heavily on these Java fundamentals. The Android SDK includes many standard Java libraries (data structure libraries, math libraries, graphics libraries, networking libraries and everything else you could want) as well as special Android libraries that will help you develop awesome Android applications.
Java is easy to learn for a variety of reasons. There’s certainly no shortage of Java resources out there to help you learn the language, including websites, tutorials, books, and classes. Java is one of the most widely discussed, taught, and used programming languages on the planet. It’s used for many different types of programming projects, no matter their scale, from web applications to desktop applications to mobile applications.
If you’re coming from a traditional programming background like C or C++, you’ll find Java syntax quite similar. If you’re not, then take comfort in knowing that you’ve chosen one of the easiest languages to learn. You’ll be up and running in no time at all.
Finally, Java is one of the most human-readable languages out there, by which we mean that a person who knows nothing about programming can often look at some Java code and have at least an inkling what it’s doing. Consider the following example:
If you simply read the code aloud, you can pretty much tell that this snippet of code is doing. There’s a single letter variable called character. If the character variable equals the letter a, then we do something (call the doSomething() method), otherwise we do something else (by calling the doSomethingElse() method).
With many programming languages, you need to use a compiler to reduce your code down into machine language that the device can understand. While this is well and good, different devices use different machine languages. This means that you might need to compile your applications for each different device or machine language—in other words, your code isn’t very portable. This is not the case with Java. The Java compilers convert your code from human readable Java source files to something called “bytecode” in the Java world. These are interpreted by a Java Virtual Machine, which operates much like a physical CPU might operate on machine code, to actually execute the compiled code. Although it might seem like this is inefficient, much effort has been put into making this process very fast and efficient. These efforts have paid off in that Java performance in generally second only to C/C++ in common language performance comparisons.
Android applications run in a special virtual machine called the Dalvik VM. While the details of this VM are unimportant to the average developer, it can be helpful to think of the Dalvik VM as a bubble in which your Android application runs, allowing you to not have to worry about whether the device is a Motorola Droid, an HTC Evo, or the latest toaster running Android. You don’t care so long as the device is Dalvik VM friendly—and that’s the device manufacturer’s job to implement, not yours.
Let’s take this bubble idea a bit further. Because Java applications run within the bubble that is a virtual machine, they are isolated from the underlying device hardware. Therefore, a virtual machine can encapsulate, contain, and manage code execution in a safe manner compared to languages that operate in machine code directly. The Android platform takes things a step further. Each Android application runs on the (Linux-based) operating system using a different user account and in its own instance of the Dalvik VM. Android applications are closely monitored by the operating system and shut down if they don’t play nice (e.g. use too much processing power, become unresponsive, waste resources, etc.). Therefore, it’s important to develop applications that are stable and responsive. Applications can communicate with one another using well-defined protocols.
Like many languages, Java is still a compiled language even though it doesn’t compile all the way down to machine code. This means you, the developer, need to compile your Android projects and package them up to deploy onto devices. The Eclipse development environment (used with the Android Development plug-in) makes this pretty painless. In Eclipse, automatic compilation is often turned on by default. This means that every time you save a project file, Eclipse recompiles the changes for your application package. You immediately see compile errors. Eclipse also interprets Java as you type, providing handy code coloring and formatting as well as showing many types of errors as you go. Often, you can click on the error and have Eclipse automatically fix a typo, or add an import statement, or provide a method stub for you, saving lots of typing.
You can still manually compile your code if you so desire. Within Eclipse, you’ll find the Build settings under the project menu. If you have “Build Automatically” turned on, you can still choose the “Clean…” option that will allow you to do full rebuild of all files. If “Build Automatically” is turned off, “Build All” and “Build Project” menu options are enabled. "Build All" means to build all of the projects in the workspace. You can have many projects in an Eclipse workspace.
The build process, for regular Java projects, results in a file with the extension of JAR – Java ARchive. Android applications take JAR files and package them for deployment on devices as Android PacKage files with an extension .apk. These formats not only include your compiled Java code, but also any other resources, such as strings, images, or sound files, that your application requires to run as well as the Application Manifest file, AndroidManifest.xml. The Android Manifest file is a file required by all Android applications, which you use to define configuration details about your app.
Okay. Time for a very brief and 20,000 foot view of object oriented programming (OOP). OOP is a programming style or technique that relies upon the definition of data structures called objects. For those new to OOP, an object can be thought of much like a custom data type. For example, you might have a Dog object, which represents the blueprint for a generic dog, with a name, breed, and gender. You could then create different instances of the Dog object to represent specific dogs. Each Dog object must be created by calling its constructor (a method that has the same name as the object itself, and may or may not have parameters for setting initial values). For example, the following Dog objects use a constructor with three parameters (name, breed, gender):
So where is this Dog object defined? Well, here we need to begin defining some of the fundamental building blocks of the Java programming language. A class provides a definition for an object. Therefore, there is a Dog class somewhere—either defined by you or in some library somewhere. Generally speaking, a class will be defined in its own file, with the filename matching the class name (e.g. Dog.java). There are exceptions to this rule, such as classes defined within other classes (when a class is declared within a class, it is generally defined for use within the parent class only as a helper class, and referred to as aninner class).
When you want to reference an object from within another class, you need to include an import statementin the top of your class file, much like you would use a #include statement in a compiled language like C.
A class typically describes the data and behavior of an object. The behavior is defined using classmethods. Method is the common term for a subroutine in an OOP language. Many common object classes are defined in shared class libraries like software development kits (SDKs), whereas others are defined by you, the developer, for your own purposes. Software is then built up by using and manipulating object instances in different ways.
Please realize this is a very generalized definition of OOP. There are entire books written on this subject. If you’d like to know more about OOP, here are a few resources you might want to check out:
Note: We use a lot of different terminology in this tutorial. There are multiple ways to refer to a given concept (e.g. superclass vs. parent class), which is confusing to those new to object oriented programming. Different developers use different terms, and so we have tried to mention synonyms where appropriate. Deciding which terms you will use is a personal choice.
Here is another important Java concept you’ll run into a lot: inheritance. Simply put, inheritance means that Java classes (and therefore objects) can be organized into hierarchies with lower, more specific, classes in the hierarchy inheriting behavior and traits from higher, more generic, classes.
This concept is best illustrated by example. Let’s pretend we are developing a Java application to simulate an aquarium. This aquarium has some fish in it. Therefore, we might define a class to represent a fish. This class, called Fish, could include some data fields (also called attributes, or class member variables) to describe a fish object: species, color and size; as well as some of its behavior in the form of methods (also called subroutines, or functions in procedural languages), like eat(), sleep(), and makeBabyFish().
A special type of method, called a constructor, is used to create and initialize an object; constructors are named the same as their class and may include parameters. The following Fish class has two constructors: one for creating a generic Fish object and another for constructing a specific Fish object with some initial data. You’ll also see that the Fish class has two eat() methods: one for eating something random, and another for eating another fish, which would be represented by another instance of the Fish class:
Classes can be organized into hierarchies, where a derived class (or subclass) includes all the features of its parent class (or superclass), but refines and adds to them to define a more specific object using the extends keyword. This is called inheritance.
For example, the Fish class might have two subclasses: FreshwaterFish and SaltwaterFish. These subclasses would have all the features of the Fish class, but could further customize the objects through new attributes and behaviors or modified behaviors from the parent class Fish. For example, the FreshwaterFish class might include information about the type of freshwater environment lived in (e.g. river, lake, pond, or puddle). Similarly, the SaltwaterFish class might customize the makeBabyFish() method such that the fish eats its mate after breeding (as defined in the super class) by using the override mechanism, like this:
In Java, you can organize object behaviors in what are called interfaces. While a class defines an object, an interface defines some behavior that can be applied to an object. For example, we could define a Swimmer interface that provides a set of methods that are common across all objects that can swim, whether they are fish, otters, or submergible androids. The Swimmer interface might specify four methods: startSwimming(), stopSwimming(), dive(), and surface().
A class like Fish could then implement the Swimmer interface (using the implements keyword) and provide implementations of the swimming behavior:
Class hierarchies, such as our fish classes, can then be organized into packages. A package is simply a set of classes and interfaces, bundled together. Developers use namespaces to uniquely name packages. For example, we could use com.mamlambo.aquarium or com.ourclient.project.subproject as our package name to keep track of our fish-related classes.
Wow! You’ve just embarked on a crash-course in Java for Android development. We’ve covered a pretty intense amount of material here

References :

Social Impact