Rectangle 27 30

The basic idea of static import is that whenever you are using a static class,a static variable or an enum,you can import them and save yourself from some typing.

import java.lang.Math;

class WithoutStaticImports {

 public static void main(String [] args) {
  System.out.println("round " + Math.round(1032.897));
  System.out.println("min " + Math.min(60,102));
 }
}

Same code, with static imports:

import static java.lang.System.out;
import static java.lang.Math.*;

class WithStaticImports {
  public static void main(String [] args) {
    out.println("round " + round(1032.897));
    out.println("min " + min(60,102));
  }
}
import static java.lang.Math

@AmadeusDrZaius nope, import static is only for static members of a class.

Good answer! Since many 'newbies' read this post one should however give one little warning: Do not overuse the asterisk to prevent namespace pollution.

java - What does the "static" modifier after "import" mean? - Stack Ov...

java modifier static-import
Rectangle 27 2

You have to use the u modifier, otherwise "" is considered as having 2 chars (2 bytes):

$string = 'Tst';
echo preg_match_all('/[A-Z]/u', $string, $treffer); // 2

Perfect, and also thank you for letting me know about IDEOne.com

php - Preg_match for counting uppercase and circumflex characters - St...

php regex preg-match
Rectangle 27 4

If you use the 'u' modifier, the pattern is supposed to be treated as utf-8, so why not simply write '' instead of '\u00B0' or '\xB0'?

$result = preg_replace('//u'," degrees ", $result ); does work.... why doesn't it work giving the string in hex?

regex - unicode preg_replace problem in php - Stack Overflow

php regex unicode utf-8 preg-replace
Rectangle 27 4

If you use the 'u' modifier, the pattern is supposed to be treated as utf-8, so why not simply write '' instead of '\u00B0' or '\xB0'?

$result = preg_replace('//u'," degrees ", $result ); does work.... why doesn't it work giving the string in hex?

regex - unicode preg_replace problem in php - Stack Overflow

php regex unicode utf-8 preg-replace
Rectangle 27 4

If you use the 'u' modifier, the pattern is supposed to be treated as utf-8, so why not simply write '' instead of '\u00B0' or '\xB0'?

$result = preg_replace('//u'," degrees ", $result ); does work.... why doesn't it work giving the string in hex?

regex - unicode preg_replace problem in php - Stack Overflow

php regex unicode utf-8 preg-replace
Rectangle 27 4

If you use the 'u' modifier, the pattern is supposed to be treated as utf-8, so why not simply write '' instead of '\u00B0' or '\xB0'?

$result = preg_replace('//u'," degrees ", $result ); does work.... why doesn't it work giving the string in hex?

regex - unicode preg_replace problem in php - Stack Overflow

php regex unicode utf-8 preg-replace
Rectangle 27 360

Use the ll (el-el) long-long modifier with the u (unsigned) conversion. (Works in windows, GNU).

printf("%llu", 285212672);

Or to be precise it's for GNU libc, and doesn't work with Microsoft's C runtime.

This isn't a Linux/UNIX thing, the "ll" length modifier was added to Standard C in C99, if it doesn't work in "Microsoft C" then it is because they are not standards compliant.

Works for me in VS2008. Moreover, as far as I remember the MS C Compiler (when set up to compile straight C) is supposed to be C90 compliant by design; C99 introduced some things that not everyone liked.

c - How do you printf an unsigned long long int(the format specifier f...

c syntax printf format-specifiers long-long
Rectangle 27 106

There is no modifier g for preg_match. Instead, you have to use the preg_match_all function.

preg_match("/^(\w|\.|-)+?@(\w|-)+?\.\w{2,4}($|\.\w{2,4})$/gim", ....)
preg_match_all("/^(\w|\.|-)+?@(\w|-)+?\.\w{2,4}($|\.\w{2,4})$/im", ....)

regex - "Unknown modifier 'g' in..." when using preg_match in PHP? - S...

php regex preg-match preg-match-all
Rectangle 27 98

There is no modifier g for preg_match. Instead, you have to use the preg_match_all function.

preg_match("/^(\w|\.|-)+?@(\w|-)+?\.\w{2,4}($|\.\w{2,4})$/gim", ....)
preg_match_all("/^(\w|\.|-)+?@(\w|-)+?\.\w{2,4}($|\.\w{2,4})$/im", ....)

regex - "Unknown modifier 'g' in..." when using preg_match in PHP? - S...

php regex preg-match preg-match-all
Rectangle 27 5

Your regex will break if the string $id_base has a / in it as you are using / as the regex delimiter.

preg_quote
$id_base
if (preg_match('/'. preg_quote($id_base,'/').'-([0-9]+)$/', .....) {

so use 'preg_quote' instead of '$id_base'? how would you rewrite the line?

php - Warning: preg_match() [function.preg-match]: Unknown modifier 'v...

php regex warnings preg-match modifier
Rectangle 27 1

Personally, when HTML is involved I'd steer away from the defacto delimiter / and use # instead so you don't have to remember to escape any closing HTML tags.

$preg = '#<div class="title">([^<]+)</div>#';

php - Warning: preg_match() [function.preg-match]: Unknown modifier '(...

php preg-match modifier
Rectangle 27 1

Personally, when HTML is involved I'd steer away from the defacto delimiter / and use # instead so you don't have to remember to escape any closing HTML tags.

$preg = '#<div class="title">([^<]+)</div>#';

php - Warning: preg_match() [function.preg-match]: Unknown modifier '(...

php preg-match modifier
Rectangle 27 1

What characters are considered "word-characters" depends on the locale. You should set a locale which has those characters in its natural alphabet, and use the /u modifier for the regexp, like this:

$str = 'perch';
setlocale(LC_ALL, 'it_IT@euro');
echo preg_match('#^\w+$#u', $str);

regex - How do I match accented characters with PHP preg? - Stack Over...

php regex pcre
Rectangle 27 27

transient variables are never serialized in java.

It marks a member variable not to be serialized when it is persisted to streams of bytes. When an object is transferred through the network, the object needs to be 'serialized'. Serialization converts the object state to serial bytes. Those bytes are sent over the network and the object is recreated from those bytes. Member variables marked by the java transient keyword are not transferred, they are lost intentionally.

please have a look at what serialization is.? and also refer this

public class Foo implements Serializable
{
  private String saveMe;
  private transient String dontSaveMe;
  private transient String password;
  //...
}

In above example dontSaveMe & password are never get serialize as they are declare as a transient variables.

'Never' is too strong. They are not serialized by default, but if you write your own readObject()/writeObject() methods you can serialize them yourself.

serialization - Why use the `transient` keyword in java? - Stack Overf...

java serialization keyword transient modifier
Rectangle 27 9

You want to use the readonly modifier

Just noticed that the ReadOnlyCollection type doesnt allow an empty constructor or supplying of the list in the brackets. You must supply the list in the constructor.

So really you can just write it as a normal list which is readonly.

private readonly static List<string> _ExtensionsOfInterestList = new List<string>()
{
    ".doc", ".docx", ".pdf", ".png", ".jpg"
};

or if you really want to use the ReadOnlyCollection you need to supply the above normal list in the constructor.

private readonly static ReadOnlyCollection<string> _ExtensionsOfInterest = new ReadOnlyCollection<string>(_ExtensionsOfInterestList);

How can I get the equivalent of C++'s "const" in C#? - Stack Overflow

c#
Rectangle 27 9

You want to use the readonly modifier

Just noticed that the ReadOnlyCollection type doesnt allow an empty constructor or supplying of the list in the brackets. You must supply the list in the constructor.

So really you can just write it as a normal list which is readonly.

private readonly static List<string> _ExtensionsOfInterestList = new List<string>()
{
    ".doc", ".docx", ".pdf", ".png", ".jpg"
};

or if you really want to use the ReadOnlyCollection you need to supply the above normal list in the constructor.

private readonly static ReadOnlyCollection<string> _ExtensionsOfInterest = new ReadOnlyCollection<string>(_ExtensionsOfInterestList);

How can I get the equivalent of C++'s "const" in C#? - Stack Overflow

c#
Rectangle 27 9

You want to use the readonly modifier

Just noticed that the ReadOnlyCollection type doesnt allow an empty constructor or supplying of the list in the brackets. You must supply the list in the constructor.

So really you can just write it as a normal list which is readonly.

private readonly static List<string> _ExtensionsOfInterestList = new List<string>()
{
    ".doc", ".docx", ".pdf", ".png", ".jpg"
};

or if you really want to use the ReadOnlyCollection you need to supply the above normal list in the constructor.

private readonly static ReadOnlyCollection<string> _ExtensionsOfInterest = new ReadOnlyCollection<string>(_ExtensionsOfInterestList);

How can I get the equivalent of C++'s "const" in C#? - Stack Overflow

c#
Rectangle 27 26

transient variables are never serialized in java.

It marks a member variable not to be serialized when it is persisted to streams of bytes. When an object is transferred through the network, the object needs to be 'serialized'. Serialization converts the object state to serial bytes. Those bytes are sent over the network and the object is recreated from those bytes. Member variables marked by the java transient keyword are not transferred, they are lost intentionally.

please have a look at what serialization is.? and also refer this

public class Foo implements Serializable
{
  private String saveMe;
  private transient String dontSaveMe;
  private transient String password;
  //...
}

In above example dontSaveMe & password are never get serialize as they are declare as a transient variables.

'Never' is too strong. They are not serialized by default, but if you write your own readObject()/writeObject() methods you can serialize them yourself.

serialization - Why use the `transient` keyword in java? - Stack Overf...

java serialization keyword transient modifier
Rectangle 27 26

transient variables are never serialized in java.

It marks a member variable not to be serialized when it is persisted to streams of bytes. When an object is transferred through the network, the object needs to be 'serialized'. Serialization converts the object state to serial bytes. Those bytes are sent over the network and the object is recreated from those bytes. Member variables marked by the java transient keyword are not transferred, they are lost intentionally.

please have a look at what serialization is.? and also refer this

public class Foo implements Serializable
{
  private String saveMe;
  private transient String dontSaveMe;
  private transient String password;
  //...
}

In above example dontSaveMe & password are never get serialize as they are declare as a transient variables.

'Never' is too strong. They are not serialized by default, but if you write your own readObject()/writeObject() methods you can serialize them yourself.

serialization - Why use the `transient` keyword in java? - Stack Overf...

java serialization keyword transient modifier
Rectangle 27 26

transient variables are never serialized in java.

It marks a member variable not to be serialized when it is persisted to streams of bytes. When an object is transferred through the network, the object needs to be 'serialized'. Serialization converts the object state to serial bytes. Those bytes are sent over the network and the object is recreated from those bytes. Member variables marked by the java transient keyword are not transferred, they are lost intentionally.

please have a look at what serialization is.? and also refer this

public class Foo implements Serializable
{
  private String saveMe;
  private transient String dontSaveMe;
  private transient String password;
  //...
}

In above example dontSaveMe & password are never get serialize as they are declare as a transient variables.

'Never' is too strong. They are not serialized by default, but if you write your own readObject()/writeObject() methods you can serialize them yourself.

serialization - Why use the `transient` keyword in java? - Stack Overf...

java serialization keyword transient modifier