blog RSS

The Programmer Blog is here to help you, the programmer. We do our best to provide useful resources that offer explanations to popular programming problems, across a variety of programming languages. If you would like to suggest a blog topic or have a question, please leave us a message.


compare, String

Comparing strings in Java

Typically programmers become accustom to using the == operator when comparing strings. While this is certainly valid syntax in Java, there is a catch that you should know about. The Catch == compares object references .equals() compares string values Explained == performs a reference equality check, to determine whether the two objects (strings in this case) refer to the same object in the memory. The equals() method...

Read more

Java, java.lang.OutOfMemoryError, systemoutofmemory

Java - java.lang.OutOfMemoryError

Learn how memory leaks manifest themselves in Java and how to avoid a System Out of Memory Exception. Contrary to what many people think, an application written in Java may rather present memory leak problems, resulting in exceptions of type System Out of Memory (java.lang.OutOfMemoryError). Unfortunately, a large number of Java programmers think that Memory leak is a C /...

Read more

Javascript, JSON, KnockoutJS

KnockoutJS - ko.toJSON copying unwanted properties

When using KnockoutJS and the Knockout Mapping Plugin, you may notice extra properties are being serialized with your viewmodels, ex. "__ko_mapping__" or "copiedProperties" objects. JSON Example: { "MyObject": { "Id": "00000000-0000-0000-0000-000000000000", "Type": 1, "Name": "Default MyObject" }, "__ko_mapping__": { "ignore": [], "include": ["_destroy"], "copy": [], "observe": [], "mappedProperties": { "MyObject.Id": true, "MyObject.Type": true, "MyObject.Name": true }, "copiedProperties": {}, "": {}...

Read more

API, Javascript

JavaScript - Getting query string values

One of the key ingredients to an AJAX driven website is the ability to reliably get query string parameters. We will run through an example using the new URLSearchParams API and also a Javascript only implementation for legacy browsers. Using the URLSearchParams Web API Consider the url http://www.systemoutofmemory.com?id=1&firstName=Bob&hobby=Baseball&hobby=Basketball Get the query string params var queryParams = new URLSearchParams(window.location.search); Iterate &...

Read more

c#, list, random

C# - Randomizing a List<T>

Randomizing a list<T> can be done using the Random and a simple LINQ query. Check out our card shuffling example below: Randomizing a list of objects Given a Card class public class Card { public string Name { get; set; } public int Value { get; set; } } Initialize a new list of cards var cards = new List<Card>()...

Read more