Today's Question:  What weekend projects have you created?        GIVE A SHOUT



  String intern in Java

In Java, == is used to compare whether two objects have the same memory location, equals() is usually used to compare whether two objects have the same time and the same state.  When comparing two strings, normally we just want to know whether they have same content, so we can choose equals(). But since String comparison is so frequently needed, Java has worked on the String class to make == workable when comparing two String literals. The String class maintains a pool of emp...

1,459 0          JAVA STRING

  Three images to understand immutability of String in Java

String is immutable in Java. This means once a String object is created and instantiated, that object cannot be changed. Any operation on the String object will create a new Object instead of operating on the original content. Below are three images to help you understand String immutability in Java. Declare a String String s = "abcd"; s stores the reference to the string content created in the heap. Assign the String reference to another String variable String s2 = s; s2 stores the same ...

2,494 0          JAVA STRING

  String.length() vs String.getBytes().length in Java

In Java, String.length() is to return the number of characters in the string, while String.getBytes().length is to return the number of bytes to represent the string with the specified encoding. By default, the encoding will be the value of system property file.encoding, the encoding name can be set manually as well by calling System.setProperty("file.encoding", "XXX"). For example, UTF-8, Cp1252. In many cases, String.length() will return the same value as String.getBytes().length, but in some ...


  Convert number to string in C++

Prior to C++11, there is no built-in function in C++ standard library which can be used to convert numbers such as interger and double number to string.  There are many ways which can convert number to string. Since C++ is C compatible, we can use itoa() function to convert an integer to C style string. But this one can only convert integer to string, not double. For different types of numbers, we need to use different functions. string s = string(itoa(a)); Actually, we can also use strings...

10,786 0          C++ CONVERSION NUMBER STRING

  Never create Ruby strings longer than 23 characters

Looking at things through a microscopesometimes leads to surprising discoveries Obviously this is an utterly preposterous statement: it’s hard to think of a more ridiculous and esoteric coding requirement. I can just imagine all sorts of amusing conversations with designers and business sponsors: “No… the size of this <input> field should be 23… 24 is just too long!” Or: “We need to explain to users that their subject lines should be less than 23 letters…” O...


  A String is not an Error

I decided to write a little article to discourage an unfortunately common pattern in Node.JS modules (and browser JavaScript, to a lesser extent) that can boil down to these two examples: // A:function myFunction () {  if (somethingWrong) {    throw 'This is my error'  }  return allGood;} and // B: async Node.JS-style callback with signature `fn(err, …)`function myFunction (callback) {  doSomethingAsync(function () {    // …    if (somethin...