q: You can do it in .NET by using the keyword "ref". Is there any way to do so in Java?

[A]
Java uses pass by value for method arguments
.
Primitives
(int, boolean, etc.) are special cases in Java.. not objects per se. In this case, a copy of the primitive (argument) is passed into the function. This gels well with the pass by value theory.
For Objects, what happens is that the ref to the object is passed by value (a copy of the reference is made rather than the object)... but both references point to the same object. So if you modify an object parameter in a method, the actual object will be modified.
This article should help you out..
http://www.javaworld.com/javaworld/javaqa/2000-05/03-qa-0526-pass.html
As for the OP's question, just pass in the reference to the byte[] array to the method. The net result would be similar to pass by reference. If you modify the byte array, the caller will be able to see the changes post method execution.
Update to quell the resistance :)
=> indicates output
.NET Land
```
```
class Counter
{
  private int m_count = 0;
  public override string  ToString()
  {
     return String.Format("Counter ID{0} : Value {1}", this.GetHashCode(), m_count);
  }
  public void Increment()
  {  m_count++;  }
}
class MakeAPass
{
   public void PassByValueAndModify(int i)
   {   i = 20;    }

   public void PassByRefAndModify(ref int i)
   {   i = 20;   }

   public void PassByValueAndModify(Counter c)
   {   c.Increment();   }

   public void PassByRefAndModify(ref Counter c)
   {   c.Increment();   }

   public void PassByRefAndReassign(ref Counter c)
   {
      c = new Counter();
      for (int i=0; i<5; ++i)
         c.Increment();
   }
}

static void Main(string[] args)
{
   MakeAPass obj = new MakeAPass();
   int intVal = 10;
   obj.PassByValueAndModify(intVal);
   Console.WriteLine(intVal);              // => 10
   obj.PassByRefAndModify(ref intVal);
   Console.WriteLine(intVal);              // => 20

   Counter obCounter = new Counter();
   obj.PassByValueAndModify(obCounter);
   Console.WriteLine(obCounter.ToString());  // => Counter ID58225482 : Value 1
   obj.PassByRefAndModify(ref obCounter);
   Console.WriteLine(obCounter.ToString());  // => Counter ID58225482 : Value 2
   obj.PassByRefAndReassign(ref obCounter);
   Console.WriteLine(obCounter.ToString());  // => Counter ID54267293 : Value 5
}
```
```
Java Land
Minor mods reqd: Use hashCode() and + to concat strings in Counter.java...
```
```
class MakeAPass
{
   public void PassByValueAndModify(int i)
   {   i = 20;   }

   // can't be done.. Use Integer class which wraps primitive
   //public void PassByRefAndModify(ref int i)

   public void PassByValueAndModify(Counter c)
   {   c.Increment();   }

   // same as above. no ref keyword though
   //public void PassByRefAndModify(ref Counter c)

   // this can't be done as in .net
   //public void PassByRefAndReassign(ref Counter c)
   public void PassAndReassign(Counter c)
   {
      c = new Counter();
      for (int i=0; i<5; ++i)
         c.Increment();
   }
}
public static void main(String args[])
{
   MakeAPass obj = new MakeAPass();
   int intVal = 10;
   obj.PassByValueAndModify(intVal);
   System.out.println(intVal);                 // => 10
   //obj.PassByRefAndModify(ref intVal);
   //System.out.println(intVal);               // can't get it to say 20

   Counter obCounter = new Counter();
   obj.PassByValueAndModify(obCounter);
   System.out.println(obCounter.ToString());    // => Counter ID3541984 : Value 1
   //obj.PassByRefAndModify(ref obCounter);
   //Console.WriteLine(obCounter.ToString());   // no ref. but can make it 2 by repeating prev call
   obj.PassAndReassign(obCounter);
   System.out.println(obCounter.ToString());    // => Counter ID3541984 : Value 1
                                                // can't get it to say 5
}
```
```


q:
I have a solution of mixed VB.NET and C++ projects. When using Visual Studio 2005 you can set the "Tools->Option->Projects and Solutions->VC++ Directories" to help the compiler find your include files. When building the same solution with MSBuild I don't see how to pass these settings. The C++ won't compile without this path specified. When building this solution form Visual Studio it build perfectly.

What is the way to pass this path for MSBUild?

Edit: Looks like MSBuild doesn't pass the path (or the /u switch) to vcbuild. Starting from VCBuild instead fails on dependency.

[A]
To set the include directories, you can add them into your INCLUDE environment variable. You use the same format as in PATH env. variable - you separate paths with semicolons.
To set the library directories - you can do it in similar way, by putting them into your LIB environment variable.
To set environment variables, you simply right-click "My Computer", choose "Properties". Then you go to "Advanced" tab, and there's a button called "Environment Variables".
Or, you can run MSBuild from a BATCH script, in which case, before calling MSBuild, you can set the INCLUDE and LIB variables, like so:
```
```
set INCLUDE=C:\Libraries\LibA\Include
set LIB=C:\Libraries\LibA\Lib\x86
```
```

s: huggingface

c: devops

d: intermediate


q:
I get this error:

System.Reflection.TargetException: Object does not match target type.

when trying to bind a List<IEvent> where an IEvent can be an appointment, a birthday, or a few other calendar related event types.

[A]
ChanChan,
GridView does
not
support binding to a collection of interfaces,
Try redisigning your application to ensure binding only to a collection of concreate classes.
The only workaround for this is to use base class (in your case Event) and bind to a collection of events.
```
```
public  class Event
        {
            public  DateTime StartDate { get; set; }
        }
        public class Birthday : Event
        {

            public DateTime? EndDate { get; set; }
        }
        public class Appointment : Event
        {

            public string Place { get; set; }
        }
        public class EventCollection : Collection<Event>
        {
            public static EventCollection GetEvents()
            {
                var events = new EventCollection();
                events.Add(new Birthday
                {
                     EndDate = DateTime.Now.AddDays(1),
                     StartDate = DateTime.Now
                });
                events.Add(new Appointment
                {
                    Place = "Gallery",
                    StartDate = DateTime.Now
                });
                return events;
             }
         }
```
```
Please note that inheritance from base classes creates 'is a' relation, but inheriting
from interfaces creates 'can do' relation. In other words, IMO, implementing IEvent
would be a bad design, since Birthday 'is a' Event. I would inherit from base class here.
Hope this helps,
Valve.


q:
I would like to be able to show a non-modal form in an already existing application.  At the moment I can do something like:

myform.ShowDialog(handleToApp);

but that will create a modal form parented to the application and what I'm really looking for something that isn't modal so when the form loses focus it won't break the flow of control and pester the user about not being closed.

Does anyone know how or if I can do what I'm looking for?

[A]
How about a simple
```
myForm.Show()
```
?


q:
I'm trying to figure out if Haskell uses dynamic or static scoping.
I realize that, for example, if you define:

let x = 10

then define the function

let square x = x*x

You have 2 different "x's", and does that mean it is dynamically scoped?  If not, what scoping does it use, and why?

Also, can Haskell variables have aliases (a different name for the same memory location/value)?

Thanks.

[A]
Haskell use (broadly speaking) exactly the same lexical scoping as most other languages.
eg.
```
```
x = 10
```
```
Results in a value referenced through
```
x
```
in the global scope, whereas
```
```
square x = x * x
```
```
will result in
```
x
```
being lexically scoped to the function square.  It may help if you think of the above form being a syntactic nicety for:
```
```
square = \ x -> x * x
```
```
As to your other question i'm not sure what you mean by aliasing


q:
I have a daily batch process that involves selecting out a large number of records and formatting up a file to send to an external system.  I also need to mark these records as sent so they are not transmitted again tomorrow.

In my naive JDBC way, I would prepare and execute a statement and then begin to loop through the recordset.  As I only go forwards through the recordset there is no need for my application server to hold the whole result set in memory at one time.  Groups of records can be feed across from the database server.

Now, lets say I'm using hibernate.  Won't I endup with a bunch of objects representing the whole result set in memory at once?

[A]
Hibernate does also iterate over the result set so only one row is kept in memory. This is the default. If it to load greedily, you must tell it so.
Reasons to use Hibernate:
"Someone" was "creative" with the column names (PRXFC0315.XXFZZCC12)
The DB design is still in flux and/or you want one place where column names are mapped to Java.
You're using Hibernate anyway
You have complex queries and you're not fluent in SQL
Reasons
not
to use Hibernate:
The rest of your app is pure JDBC
You don't need any of the power of Hibernate
You have complex queries and you're fluent in SQL
You need a specific feature of your DB to make the SQL perform


q:
I'm new to this JSF world, please bear with me if I'm asking some silly thing

i'm using UI tags for my application and I have a scenario that I need to generate a calendar control to make the user to select the date I followed the ui tags documentation and wrote the code like this:

  <table width="100%">
    <tr>
    <td>
           <ui:calendar binding="#{booking.calDate}"
           id="calDate"
          dateFormatPattern="dd/MM/yyyy"
          label="Date ::"/>
          </td>
          </tr>
     </table>

and my backing bean contains

  private Calendar calDate = new Calendar();

with appropriate getters and setters

when I tried to load the page I'm getting the calendar component disorted.
I'm getting cross marks and nonsense things with some javascript errors.

please help me in resolving this issue

Thanks in anticipation

[A]
The component  is coming from which JSF library?
In others words, what do you have at the beginning of your XHTML file?
The only  library I know is coming from
Facelets
, and it does not provide any  component!
In addition, if calDate is a **java.util.**Calendar class, then you cannot bind this class to a JSF component!
Maybe you can have a look to
Tomahawk
, or
Richfaces
, that provide good calendar component...


q:
Is there a widely accepted class for dealing with URLs in PHP?

Things like: getting/changing parts of an existing URL (e.g. path, scheme, etc), resolving relative paths from a base URL.  Kind of like a two-way parse_url(), encapsulated with a bunch of handy functions.

Does something like this exist?

[A]
This
URL.php class
may be a good start (not sure it is 'widely' accepted though).
URL class intended for http and https schemes
This class allows you store absolute or relative URLs and access it's various parts (scheme, host, port, part, query, fragment).
It will also accept and attempt to resolve a relative URL against an absolute URL already stored.
Note: this URL class is based on the HTTP scheme.
Example:
```
```
$url =& new URL('http://www.domain.com/path/file.php?query=blah');
echo $url->get_scheme(),"\n";    // http
echo $url->get_host(),"\n";      // www.domain.com
echo $url->get_path(),"\n";      // /path/file.php
echo $url->get_query(),"\n";     // query=blah
// Setting a relative URL against our existing URL
$url->set_relative('../great.php');
echo $url->as_string(); // http://www.domain.com/great.php
```
```


q:
What is the XPath expression that I would use to get the string following 'HarryPotter:' for each book.

ie. Given this XML:

<bookstore>
<book>
  HarryPotter:Chamber of Secrets
</book>
<book>
  HarryPotter:Prisoners in Azkabahn
</book>
</bookstore>

I would get back:

Chamber of Secrets
Prisoners in Azkabahn

I have tried something like this:

/bookstore/book/text()[substring-after(. , 'HarryPotter:')]

I think my syntax is incorrect...

[A]
In your XML you've got no space between Harry Potter but in your XQuery you've got a space.  Just make it match and presto, you'll get data back...
```
```
Dim xml = <bookstore>
                  <book>HarryPotter:Chamber of Secrets</book>
                  <book>HarryPotter:Prisoners in Azkabahn</book>
                  <book>MyDummyBook:Dummy Title</book>
              </bookstore>

    Dim xdoc As New Xml.XmlDocument
    xdoc.LoadXml(xml.ToString)

    Dim Nodes = xdoc.SelectNodes("/bookstore/book/text()[substring-after(., 'HarryPotter:')]")

    Dim Iter = Nodes.GetEnumerator()
    While Iter.MoveNext
        With DirectCast(Iter.Current, Xml.XmlNode).Value
            Console.WriteLine(.Substring(.IndexOf(":") + 1))
        End With
    End While
```
```


q:
We have a PageRoles xml file which contains the page path and the user role that can access that page.

We are maintaining a Dictionary in a static class, which gets loaded int static constructor for the class.
The class has a method CheckIfRoleAllowed that takes in a page path and returns a bool.

Each page call the CheckIfRoleAllowed on Page Init.

static class PageAccessChecker
{
 static Dictionary<string, UserRoleType[]> _PageAccessPermissions;
 static FileSystemWatcher _XmlWatcher;

 static PageAccessChecker()
 {
   // Load page access permissions from xml
   // Set FileSystemWatcher watcher to watch for changes
 }

 public static CheckIfRoleAllowed(string pagePath)
 {
 }

}

Would we be better off doing this using the singleton pattern?
If yes, why?

Kind regards.

[A]
You do use a singleton. Simply, there are 2 usual implementations for singletons, the other being instantiating the class and having a static member referencing this instance.
Your implementation makes calls simpler IMO :
```
```
PageAccessChecker.CheckIfRoleAllowed(path);
```
```
instead of:
```
```
PageAccessChecker._default.CheckIfRoleAllowed(path);
```
```


q:
I read this answer and its comments and I'm curious: Are there any reasons for not using this / Self / Me ?

BTW: I'm sorry if this has been asked before, it seems that it is impossible to search for the word this on SO.

[A]
It was asked before indeed, in the "variable in java" context:
Do you prefix your instance variable with ‘this’ in java ?
The main recurrent reason seems to be:
"it increases the visual noise you need to sift through to find the meaning of the code."
Readability, in other word... which I do not buy, I find
```
this.
```
very useful.


q:
My Java application is saving stuff in 'user.home' but on windows this does not seem to be the correct path to save application information (as a friend told me). An other option is using the preferences api but it's not possible to set up the hsqldb location using the preferences api. Also, I want all files to be available in the same folder (local database, config, cache, ...).

I'm looking for some example code or a framework that takes care of os-specific stuff.

[A]
It's unusual for a window app to save data in user.home but not "wrong". Windows applications love to spread their data all over the place (a bit in the registry, a bit in the application's install directory, a bit in the Windows directory, a bit in System32, a bit here and a bit there). In the end, this makes it impossible to cleanly backup or remove something which results in the famous "Windows rot" (i.e. you have to reinstall every few months).
Anyway. If you really don't want to use user.home (and I see no reason not to), use code like
this from Apache commons-lang
to figure out if you're running on Windows. If this yields true, pop up a directory selection dialog where the user can specify where they want to save their data.
Save this information in Preferences and use this path the next time when your app is started. This way, users can specify where they want their data and you only have to leave one bit of information in the prefs.


q:
I'm using caml query to select all documents which were modified or added by user. Query runs recursively on all subsites of specified site collection.

Now problem is I can't get rid of folders which are also part of result set. For now I'm filtering them from result datatable. But I'm wondering: Is it possible to filter out folders from result set just by using caml?

[A]
So, i figured it out :)
You can use FieldRef='ContentType' in your caml query and specify typr of content type which you want to select or exclude from select.
So in my case I've added this condition to my caml expression:
```
<Neq><FieldRef Name='ContentType' /><Value Type='Text'>Folder</Value></Neq>
```
NOTE:
There are problems in multi language setup. Name of content type can be different, so it is good to get names of content types from resources
UPDATE:
It looks like I was too quick in my assumptions. I need to filter out all contett types based on folder content type, because in our projects such content types are used :(
I was not able to create workable query in caml, so I added view field element to my query which selects ContentTypeId of list item and I filter-out rows which are based on folder content type.
Code to do this is trivial, but it bothers me that such simple task cannot be done by pure caml.


q:
Let's say I have a search page called Search.aspx that takes a search string as a url parameter ala Google (e.g. Search.aspx?q=This+is+my+search+string).

Currently, I have an asp:TextBox and an asp:Button on my page.  I'm handling the button's OnClick event and redirecting in the codebehind file to Search.aspx?q=

What about with ASP.NET MVC when you don't have a codebehind to redirect with?  Would you create a GET form element instead that would post to Search.aspx?  Or would you handle the redirect in some other manner (e.g. jQuery event attached to the button)?

[A]
You need to understand that MVC doesn't directly reference .aspx pages like WebForms in its URLs. Its main purpose is to separate concerns, that is model (data), controller (logic), and view (presentation).
First, you'd have to create a route matching your URLs, which would now look like this for example : /home/search/This+is+my+search+string
This would call the Search action method of the Home controller, which would get "This is my search string" as an input parameter. This action is responsible for accessing the model and pulling the results probably from a database.
Typically, your search action would then return a ViewResult containing the view placed in the folder /Views/Home/Search.aspx. Here, you can use neither the Postback functionality nor the events of your Web controls like in WebForms, because MVC applications are stateless and not event-driven. It's more like a request/dispatch way of doing things.
Read more about MVC here
.