Asked  7 Months ago    Answers:  13   Viewed   31 times

When creating filepaths and URLs, I noticed that many times the path starts with ./ or ~/.

What is the difference between filepaths that start with ./ and ~/?

What do each of them mean?



./ means "starting from the current directory". . refers to the current working directory, so something like ./ would be looking for a file called in the current directory. (As a side note, .. means refers to the parent directory of the current directory. So ../ would be looking for that file one directory above.)

~/ means "starting from the home directory". This could have different meanings in different scenarios. For example, in a Unix environment ~/ would be looking for a file called in your home directory, something like /home/totzam/ In many web applications, ~/ would be looking for a file called in the web application root, something like /var/http/mywebapp/

Tuesday, June 1, 2021
answered 7 Months ago

& is bitwise AND. See Bitwise Operators. Assuming you do 14 & 7:

    14 = 1110
     7 = 0111
14 & 7 = 0110 = 6

&& is logical AND. See Logical Operators. Consider this truth table:

 $a     $b     $a && $b
false  false    false
false  true     false
true   false    false
true   true     true
Wednesday, March 31, 2021
answered 9 Months ago

-> is used when referring to a member of an object.

:: is the Scope Resolution Operator and is used to refer to a static member of a Class.

Consider the following class:

class FooBar {
    public static function fizz() {
        echo "Fizz";

    public function buzz() {
        echo "Buzz";

You would call the function buzz() using ->:

$myFooBar = new FooBar();

But would use :: to call the functon fizz(), as it is a static member (a member which doesn't require an instance of the class to be called):


Also, while we are talking about the difference between static members versus instantiated members, you cannot use $this to refer to the current instance within static members. You use self instead (no leading $) which refers to the current class, or parent if you want to refer to the parent class, or if you have the pleasure of working with PHP 5.3.0, static (which allows for late static binding).

The documentation uses :: to refer to a function inside a class as the class name in the header is not an instance of the class. Still using the same example, a documentation entry referring to the function buzz() would use the following header:


But unless the documentation specifies it's a static member, you will need to use -> on an instance to call it:

$myFooBar = new FooBar();
Wednesday, March 31, 2021
answered 9 Months ago

:: is for referencing static properties or methods of a class. -> is for referencing instance properties and methods. You aren't missing out on any programming correctness, and if you are a bad person then it isn't because of this. Which one you use depends on the purpose of your class and how its written. But also, PHP didn't have namespaces until very recently so many people encapsulated their code in static classes to emulate namespaces to avoid naming collisions. It is possible you are seeing code that does that.

Wednesday, March 31, 2021
answered 9 Months ago

The difference is that there is no operator ==!.

This expression:

$a ==! $b

Is basically the same as this:

$a == (!$b)
Saturday, May 29, 2021
answered 7 Months ago

!= checks value

if($a != 'true')

!== checks value and type both

if($a !== 'true') 
Saturday, May 29, 2021
answered 7 Months ago

=== and !== are strict comparison operators:

JavaScript has both strict and type-converting equality comparison. For strict equality the objects being compared must have the same type and:

  • Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.
  • Two numbers are strictly equal when they are numerically equal (have the same number value). NaN is not equal to anything, including NaN. Positive and negative zeros are equal to one another.
  • Two Boolean operands are strictly equal if both are true or both are false.
  • Two objects are strictly equal if they refer to the same Object.
  • Null and Undefined types are == (but not ===). [I.e. (Null==Undefined) is true but (Null===Undefined) is false]

Comparison Operators - MDC

Tuesday, June 1, 2021
answered 7 Months ago


The /* on a servlet overrides all other servlets, including all servlets provided by the servletcontainer such as the default servlet and the JSP servlet. Whatever request you fire, it will end up in that servlet. This is thus a bad URL pattern for servlets. Usually, you'd like to use /* on a Filter only. It is able to let the request continue to any of the servlets listening on a more specific URL pattern by calling FilterChain#doFilter().


The / doesn't override any other servlet. It only replaces the servletcontainer's builtin default servlet for all requests which doesn't match any other registered servlet. This is normally only invoked on static resources (CSS/JS/image/etc) and directory listings. The servletcontainer's builtin default servlet is also capable of dealing with HTTP cache requests, media (audio/video) streaming and file download resumes. Usually, you don't want to override the default servlet as you would otherwise have to take care of all its tasks, which is not exactly trivial (JSF utility library OmniFaces has an open source example). This is thus also a bad URL pattern for servlets. As to why JSP pages doesn't hit this servlet, it's because the servletcontainer's builtin JSP servlet will be invoked, which is already by default mapped on the more specific URL pattern *.jsp.


Then there's also the empty string URL pattern . This will be invoked when the context root is requested. This is different from the <welcome-file> approach that it isn't invoked when any subfolder is requested. This is most likely the URL pattern you're actually looking for in case you want a "home page servlet". I only have to admit that I'd intuitively expect the empty string URL pattern and the slash URL pattern / be defined exactly the other way round, so I can understand that a lot of starters got confused on this. But it is what it is.

Front Controller

In case you actually intend to have a front controller servlet, then you'd best map it on a more specific URL pattern like *.html, *.do, /pages/*, /app/*, etc. You can hide away the front controller URL pattern and cover static resources on a common URL pattern like /resources/*, /static/*, etc with help of a servlet filter. See also How to prevent static resources from being handled by front controller servlet which is mapped on /*. Noted should be that Spring MVC has a builtin static resource servlet, so that's why you could map its front controller on / if you configure a common URL pattern for static resources in Spring. See also How to handle static content in Spring MVC?

Tuesday, June 1, 2021
answered 7 Months ago

and is the same as && but with lower precedence. They both use short-circuit evaluation.

WARNING: and even has lower precedence than = so you'll usually want to avoid and. An example when and should be used can be found in the Rails Guide under "Avoiding Double Render Errors".

Tuesday, June 1, 2021
answered 7 Months ago


There are many changes done into support library since this question was answered. Good thing is, it is very well documented also. So you must read Support Library Documentation for more details and more available support library.

Starting with Support Library release 26.0.0 (July 2017), the minimum supported API level across most support libraries has increased to Android 4.0 (API level 14) for most library packages.

Below is difference from Support Library Packages:

v4 Support Library

This library is designed to be used with Android 1.6 (API level 4) Android 2.3 (API level 9) Android 4.0 (API level 14) and higher. It includes the largest set of APIs compared to the other libraries, including support for application components, user interface features, accessibility, data handling, network connectivity, and programming utilities.

v7 Libraries

There are several libraries designed to be used with Android 2.1 (API level 7) Android 2.3 (API level 9) Android 4.0 (API level 14) and higher. These libraries provide specific feature sets and can be included in your application independently from each other.

v7 appcompat library

This library adds support for the Action Bar user interface design pattern.

Note: This library depends on the v4 Support Library. If you are using Ant or Eclipse, make sure you include the v4 Support Library as part of this library's classpath.

So yes you need both jars if you want to use v7.

Update for android-support-v13.jar

v13 Support Library

This interface was deprecated in API level 27.1.0. Use Fragment instead of the framework Fragment.

v13 Support Library

This library is designed to be used for Android 3.2 (API level 13) and higher. It adds support for the Fragment user interface pattern with the (FragmentCompat) class and additional fragment support classes

When you see the package details it has a class FragmentCompat as given in definition. So it has not the all classes of appcompat library.

Wednesday, June 2, 2021
answered 7 Months ago

The difference between ?= and ?! is that the former requires the given expression to match and the latter requires it to not match. For example a(?=b) will match the "a" in "ab", but not the "a" in "ac". Whereas a(?!b) will match the "a" in "ac", but not the "a" in "ab".

The difference between ?: and ?= is that ?= excludes the expression from the entire match while ?: just doesn't create a capturing group. So for example a(?:b) will match the "ab" in "abc", while a(?=b) will only match the "a" in "abc". a(b) would match the "ab" in "abc" and create a capture containing the "b".

Friday, June 11, 2021
answered 6 Months ago

The infix operator ($) is just "function application". In other words

 f   x     -- and
 f $ x

are the same. Since in Haskell parentheses are only used to disambiguate precedence (and for tuple notation and a few other minor places, see comments) we can also write the above in a few other ways

 f     x
 f  $  x
(f)    x
 f    (x)
(f)   (x)    -- and even
(f) $ (x)

In every case, the above expressions denote the same thing: "apply the function f to the argument x".

So why have all this syntax? ($) is useful for two reasons

  1. It has really low precedence so it can stand in for a lot of parentheses sometimes
  2. It's nice to have an explicit name for the action of function application

In the first case, consider the following deeply right-nested function application

f (g (h (i (j x))))

It can be a little difficult to read this and a little difficult to know you have the right number of parentheses. However, it's "just" a bunch of applications so there ought to be a representation of this phrase using ($). Indeed there is

 f $ g $ h $ i $ j $ x

Some people find this easier to read. More modern style also incorporates (.) in order to emphasize that the whole left side of this phrase is just a composed pipeline of functions

 f . g . h . i . j $ x

And this phrase is, as we saw above, identical to

(f . g . h . i . j)  x

which is sometimes nicer to read.

There are also times when we want to be able to pass around the idea of function application. For instance, if we have a list of functions

lof :: [Int -> Int]
lof = [ (+1), (subtract 1), (*2) ]

we might want to map application by a value over them, for instance apply the number 4 to each function

> map (fun -> fun 4) lof
[ 5, 3, 8 ]

But since this is just function application, we can also use section syntax over ($) to be a bit more explicit

> map ($ 4) lof
[ 5, 3, 8 ]
Sunday, August 15, 2021
Alan Clark
answered 4 Months ago

||= will set the left-hand value to the right hand value only if the left-hand value is falsey.

In this case, both 6 and 4 are truthy, so a = 6 || 4 will set a to the first truthy value, which is 6.

a ||= 6 will set a to 6 only if a is falsey. That is, if it's nil or false.

a = nil
a ||= 6
a ||= 4
a # => 6
Tuesday, August 24, 2021
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :