I was going through the interview questions and found out the below question which I am not able to answer it. Can anyone provide some sort of algorithm for this problem how can I solve it?
There are a cluster of stateless servers all serving the same pages.
The servers are hosting 5 web pages- p1.html, p2.html, p3.html, p4.html and p5.html
p1.html just redirects users to the other 4 pages
Requests to p1.html should result in 10% of users being redirected to p2.html, 5% of users redirected to p3.html, 20% of users redirected
to p4.html, and 65% of users redirected to p5.html.
Users do not need to stick to the page they are first redirected to. They could end up on a different page with every request to
p1.html
Write a function/pseudocode that would be invoked with every request to p1.html and redirect the correct percentage of users to the
correct page.
Any suggestions will be of great help.
Hi guys, I was wondering if is it possible to deploy a jar file in Jetty?
If not, are there applications servers who can do so?
I am beginner. I am asking this question because all the docs that i have found, it seems that we can only deploy war archive in application servers. Is that true?
Hi,
I would like to know how to start and code a thread manager for my Android App.
My app is going to fill a list with a network I/O and I have to manage threads for that.
I never done this before and I don't know where to start. I heard about Thread Pool and other stuff, but I'm quite confused. Could someone please help me make my way through ?
Thanks
I have downloaded ip-to-country.csv that has ip ranges that are mapped to countries. How should I store this data to database and how can I query in what range Ip address is to know where Ip address is coming from?
My understanding is serialVersionUID is applicable only to classes, because we can create an object only to classes and the concept of serialVersionUID is for object serialization and deserialization.
I am writing a tomcat app, and have a need to do authentication within the URL like this:
https://user:[email protected]
Except for the life of me i'm not sure how to set it up or able to find the docs to read up on it, clearly my google skills need work.
Can anyone tell me where i should be looking for this kind of info or where to start?
Cheers
Andy
i'm using spring+tapestry for authenticate webuser. I wonder is there any technique i can force all users that currently login in to logout let say i'm on scenario where the site is 'under maintenance mode'
I created a dialog box like this:
String response =
JOptionPane.showInputDialog(null,"message","title",JOptionPane.PLAIN_MESSAGE);
I'd like to keep it always on top of all windows.
Do you have any idea?
Thanks!
I developed one swing application but each time you run application new window is opened.
I want that if one window is already opened other not allow to open.
I have an activity which pulls some JSON from my server, and then uses it to draw a list. That list launches further activities.
My problem is that I can't figure out a way to tell if the activity is still alive when you go back to it, so I end up re-querying my JSON from the server and redrawing the list every time the user goes back to the activity.
How can I tell if my activity is still alive so I can skip the redraw?
Hello,
Consider I scheduled a Runnable for periodic execution with ScheduledExecutorService and there occurs some system Error like OutOfMemory. It will be silently swallowed.
scheduler.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
throw new OutOfMemoryError(); // Swallowed
}
}, 0, delay, TimeUnit.SECONDS);
Is it normal?
Why doesn't it propagate to the container?
What is the correct way to handle such errors?
Thanks!
I have a SVG document that I exported from Visio 2003 that would like to edit. This file has an action where you click a button it will navigate to a new screen. What I would like to do is have the navigation be based off of a data point rather than having to click the button.
As an example I have a dynamic point data being brought into the SVG file and when that value changes from 0 to 1, I want this screen to automatically navigate to another screen. Below is the code I for clicking the button.
<title content="structured text">Sheet.1107</title>
<desc content="structured text">Button 1</desc>
<v:custProps>
<v:cp v:ask="false" v:langID="1033" v:invis="false" v:cal="0" v:val="VT4(Test Graphic 2)" v:type="0" v:prompt="" v:nameU="ObjRef" v:sortKey="" v:lbl="" v:format=""/>
<v:cp v:ask="false" v:langID="1033" v:invis="false" v:cal="0" v:val="VT4(SF-S)" v:type="0" v:prompt="" v:nameU="DataPt" v:sortKey="" v:lbl="" v:format=""/>
</v:custProps>
<v:userDefs>
<v:ud v:prompt="" v:nameU="NAVIGATE" v:val="VT4(NAVIGATE Test Graphic 2,'',)"/>
</v:userDefs>
<v:textBlock v:margins="rect(4,4,4,4)"/>
<v:textRect width="125.01" height="35" cx="62.5" cy="517.5"/>
<rect x="0" width="125" y="500" height="35" class="st3"/>
<text x="40.15" y="521.1" v:langID="1033" class="st4"><v:paragraph v:horizAlign="1"/><v:tabList/>Button 1</text> <jci:action type="click" count="1">if(evt.button == 0) nav('Test Graphic 2','','');</jci:action></g></a>
In the above code I am bringing in the data value from SF-S. Once that value is equal to 1 I want this screen to automatically navigate to Test Graphic 2.
I don't have any experience with coding so I am hoping someone here will be able to help me.
Thanks,
DMyers
I have an XML file located at a location such as
http://example.com/test.xml
I'm trying to parse the XML file to use it in my program with xPath like this but it is not working.
Document doc = builder.parse(new File(url));
How can I get the XML file?
I have many lines i just use for debugging and helpers. Is there a way i can mark these so they do not compile when publishing a project but still can use when running/debugging my program within Eclipse? Even better would be to mark a certain field as debug only and discard everything that has to do with that field completely when publishing.
I understand this might get one in trouble when using fields like that and using that in critical parts of the code. But i often find myself initializing a lot of debug fields then comment them out which results in errors down the line if i do not comment those out as well.
So is there some way to handle this in a better and more efficient way?
The code at the bottom is what I have. I removed the creation of all tags.
At the top in the xml file I get.<?xml version="1.0" encoding="UTF-8" standalone="no"?> Note that standalone is no, even thou I have it set to yes.
The first question: How do I get standalone = yes?
I would like to add <?xml-stylesheet type="text/xsl" href="my.stylesheet.xsl"?> at line two in the xml file.
Second question: How do I do that?
Some useful links? Anything?
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Document doc = docBuilder.newDocument();
<cut>
TransformerFactory transfac = TransformerFactory.newInstance();
transfac.setAttribute("indent-number", new Integer(2));
Transformer trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
trans.setOutputProperty(OutputKeys.STANDALONE, "yes");
trans.setOutputProperty(OutputKeys.INDENT, "yes");
trans.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, "name");
FileOutputStream fout = new FileOutputStream(filepath);
BufferedOutputStream bout= new BufferedOutputStream(fout);
trans.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(bout, "utf-8")));
May be a dumb question, but GWT FlowPanel (raw div element) does not provides something to handle a mouseclick/mousemovement on it. Overriding onBrowserEvent do not works either.
If setting onclick event using native JavaScript (need to specify positive height before, 'div' have a height of 0 if not specified), then catching these events is working properly. Is there a way to do it without using JSNI?
i'm currently working on a android project where i need to encrypt a string using 128 bit AES, padding PKCS7 and CBC. I don't want to use any salt for this.
I've tried loads of different variations including PBEKey but i can't come up with working code. This is what i currently have:
String plainText = "24124124123";
String pwd = "BobsPublicPassword";
byte[] key = pwd.getBytes();
key = cutArray(key, 16);
byte[] input = plainText.getBytes();
byte[] output = null;
SecretKeySpec keySpec = null;
keySpec = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
cipher.init(Cipher.ENCRYPT_MODE, keySpec);
output = cipher.doFinal(input);
private static byte[] cutArray(byte[] arr, int length){
byte[] resultArr = new byte[length];
for(int i = 0; i < length; i++ ){
resultArr[i] = arr[i];
}
return resultArr;
}
Any help appreciated
//Vlahovic
BeanUtils copyProperties, out of the box, doesn't seem to handle copying from Boolean object properties to boolean primitive properties.
I figured I could create and register a converter to handle this, but that just didn't seem to work.
So, how can I use BeanUtils to copy the properties from class Source to class Destination where:
public class Destination {
private boolean property;
public boolean isProperty() {
return property;
}
public void setProperty(boolean property) {
this.property = property;
}
}
public class Source{
private Boolean property;
public Boolean getProperty() {
return property;
}
public void setProperty(Boolean property) {
this.property = property;
}
}
Hi,
I have my webservice deployed on Apache tomcat 5.5. When I run my webservice using eclipse IDE, it prints logs to the location I have specified . I have put log4j property file for my webservice in the apache-tomcat-5.5.28/common/classes folder. Problem is , when i run this using webservice .aar file which is put in to apache-tomcat-5.5.28/webapps/axis2/WEB-INF/classes folder in the webservice ,it does not print logs.
Could anyone tell me what is going wrong here. why does it print logs when running from eclipse ide and, why is it not printing logs when it is started using the aar file deployed to tomcat
I'm looking for a collection that offers list semantics, but also allows array semantics. Say I have a list with the following items:
apple orange carrot pear
then my container array would:
container[0] == apple
container[1] == orangle
container[2] == carrot
Then say I delete the orange element:
container[0] == apple
container[1] == carrot
I don't particularly care if sort order is maintained, I'd just like the array values to function as accelerators to the list items, and I want to collapse gaps in the array without having to do an explicit resizing.
I'm trying to draw strings character by character to add lighting effects to shapes composed of text.
while (i != line.length()) {
c = line.substring(i, i + 1);
cWidth = g.getFontMetrics().stringWidth(c);
g.drawString(c, xx += cWidth, yy);
i++;
}
The problem is, the width of a character isn't the actual distance it's drawn from another character when those two characters are printed as a string. Is there any way to get the correct distance in graphics2d?
Hi,
how do i prevent schemagen from adding the super-class to the schema?
I have tried using XMLTransient on the super-class, and on its fields but they still show up in the schema .
for example :
@XmlTransient
public class Asset {
@XmlTransient
public Long ID;
}
public class Movie extends Asset {
}
creates this schema :
<xs:complexType name="asset">
<xs:sequence>
<xs:element name="ID" type="xs:long" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="movie">
<xs:complexContent>
<xs:extension base="asset">
<xs:sequence/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
the schema that i would like to see is :
<xs:complexType name="movie">
<xs:complexContent>
<xs:sequence/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
I have the following code in a listener method:
FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("time", new Date());
When a button is clicked the following code is executed
System.out.println(FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("time"));
One could except that "time" is null when the listener was not executed while processing the current request, but: it seems like the "time" object survives the request processing. So when "time" has been set sometimes in the past it stays there... can anybody explain this? Thanks.
Hi all,
I am using the PropertySheetView component to visualize and edit the properties of a node. This view should always reflect the most recent properties of the object; if there is a change to the object in another process, I want to somehow refresh the view and see the updated properties.
The best way I was able to do this is something like the following (making use of EventBus library to publish and subscribe to changes in objects):
public DomainObjectWrapperNode(DomainObject obj) {
super (Children.LEAF, Lookups.singleton(obj));
EventBus.subscribe(DomainObject.class, this);
}
public void onEvent(DomainObject event) {
// Do a check to determine if the updated object is the one wrapped by this node;
// if so fire a property sets change
firePropertySetsChange(null, this.getPropertySets());
}
This works, but my place in the scrollpane is lost when the sheet refreshes; it resets the view to the top of the list and I have to scroll back down to where I was before the refresh action.
So my question is, is there a better way to refresh the property sheet view of a node, specifically so my place in the property list is not lost upon refresh?