I have a String named firstName. This string has a value of "Matt". I then have a second String named lastName with a value of "getLastName()". Both of these String are stored in a database and I'm attempting to build a line of code dynamically. The line of code needs to say:   firstName + getLastName();   Is there a way to get java to read the value of lastName (which is getLastName()) as a method instead of as a value of a string?
If I have two variables:  Object obj; String methodName = "getName";   Without knowing the class of obj, how can I call the method identified by methodName on it?  The method being called has no parameters, and a String return value. It's a getter for a Java bean.
What I am working with: I am running my self-made Arduino board (in the sense that I use the Arduino bootloader and code editor) at 3.3V, and powered from a Lithium ion battery, which is USB-charged by a corresponding Microchip charger IC.  What I am trying to achieve: I want to measure battery capacity once every minute or so. I have an LCD attached, so the idea is that the overall setup lets me know how the battery is doing at a given moment. The datasheet of the battery has a voltage versus discharge-level curve, and so by measuring the voltage of the battery, I can estimate the remaining capacity (very roughly but enough for me!).  What I did:   (EDIT: Resistor values updated and P-MOSFET switch added based on @stevenvh and @Jonny's suggestions).  I connected a voltage divider from the battery V_plus, with the larger "portion" going to an analog-read-pin (i.e., ADC) on the Arduino/Atmega chip. The divider is 33 KOhm-to-10 KOhm, thus allowing measurement up to 4.1 Volts maximum of the Li-ion battery from my 3.3V level microcontroller. Also, using one of the I/O pins connected to an n-channel MOSFET, I can switch the current through the divider only when I need the measurement. Here is a rough schematic (updated for a 2nd time based on suggestions of @stevenvh and @Nick):     My question:   How is my current setup? My only constraints are: (1) I would like to make a rough measurement of the battery capacity based on the voltage reading, as described above. (2) I would like to prevent the voltage divider from interfering with my charging IC's reading of battery presence (in my original setup, the divider sometimes caused the IC to misread presence even when the battery was absent). How to redirect and append both stdout and stderr to a file with Bash? How to load JAR files dynamically at Runtime? If Durmstrang and Beauxbatons were hidden from common knowledge, how did people from other schools go to them for the Triwizard tournament? So in GoF, they state that Beauxbatons and Durmstrang are hidden from view and don't have their locations public.     “Durmstrang’s another wizarding school?” said Harry      “Yes,” said Hermione sniffily, “and it’s got a horrible reputation.      According to An Appraisal of Magical Education in Europe, it puts a   lot of emphasis on the Dark Arts.”      “I think I’ve heard of it,” said Ron vaguely. “Where is it? What   country?”      “Well, nobody knows, do they?” said Hermione, raising her   eyebrows.      “Er — why not?” said Harry.      “There’s traditionally been a lot of rivalry between all the magic   schools. Durmstrang and Beauxbatons like to conceal their whereabouts   so nobody can steal their secrets,” said Hermione matter-offactly.   So how do students get to the other school for the Triwizard tournament? Good keyboard layouts for typing (La)TeX When typing (La)TeX some keys are used a lot more often then in plain text, especially \, {, }, [, ], $, ^ and _. On most keyboard layouts these keys are rather cumbersome to type. The English QWERTY keyboard is a lot better than the German QWERTZ, but is still far from optimal.  Given that I mostly type mathematical texts in English, what keyboard layout would you recommend?  Bonus points for the following:   Ability to type non-English Latin characters, especially German umlauts. Some similarity to QWERTZ or QWERTY as I'm most used to these layouts (I currently use the US-International layout from Linux) Ability to type math symbols directly (Greek letters, \times, etc.) 'sudo su -' vs 'sudo -i' vs 'sudo /bin/bash' - when does it matter which is used, or does it matter at all? When I'm doing something that requires root be typed in dozens of times in a row, I prefer to switch my session to a root session. In the various tutorials and instructions I have used on the Internet, I see sudo su, sudo su -, sudo -i and sudo /bin/bash being used to open a root session, but I'm not clear on the difference between these and when or if that difference matters.  Can someone clear this up for me? What is the difference between a synchronized method and synchronized block in Java? proof of functional completeness of logical operators If I know that the set of operators {∨, &amp; , ¬} is functionally complete, how do I go about proving/disproving the functional completeness of the following set of operators?  a) $\{\vee,\neg\}$  b) $\{\to,\neg\}$  c) $\{\to\}$  I have looked at the answer here for (b) : Bonus continent troops in Risk So I have taken over all of Australia and I get 2 extra troops.    My friend then attacks Indonesia from Southeast Asia. When it's my turn I retake control of Indonesia.  Now, do I get 2 more bonus troops since I retook control over the continent? Another phrase for "a chicken and egg situation" Is there any other phrase that conveys the same meaning as  the phrase "a chicken and egg situation" especially if one has to use this phrase in an official/corporate set up? I'm looking for the method by which the partial derangement formula $D_{n,k}$ was derived. I can determine the values for small values of N empirically, but how the general case formula arose still alludes me.  Any links/books or an explanation will be appreciated.  The formula is:  $D_{n,k} = {n \choose k}!(n-k)$  Links: Cloning a Non-Standard Svn Repository with Git-Svn I'm relatively new to Git, but I've found it so easy to work with at home that I'd like to use it at work where our projects are stored in Svn repositories. Unfortunately, the repositories are slightly non-standard and I'm having trouble getting them cloned. Sure, they all have trunk, branches/ and tags/, but branches/ and tags/ have subdirectories before hitting the real project directories:  trunk/ branches/maintenance/release1 branches/maintenance/release2 ... branches/development/feature1 branches/development/feature2 ... tags/build/build1 tags/build/build2 ... tags/release/release1 tags/release/release2   After cloning:  $ git svn clone -s --prefix=svn/ https://mydomain.com/svnproject $ git branch -r   development   development@1340   maintenance   maintenance@1340   tags/build   tags/build@1340   tags/release   tags/release@1340   trunk   trunk@1340    I get none of the actual project branches or tags. I actually need to be able to work on the trunk, one maintenance branch and one development branch. I've tried this approach in addition to several hacks at modifying the config, but nothing is working for me.  Is there any way I can get the key components of my non-standard Svn project into a local git repository so that I can easily move between them?  Many thanks.  UPDATE: I should add that I can't do a wholesale switch to Git (yet). There are other team members involved and an international presence. The logistics of the transition are more than I'm willing to undertake until I'm much more comfortable with Git; as I mentioned, I'm still pretty new. I've barely scratched the surface of its capabilities. customize of autoref We have $n$ charged and $n$ uncharged batteries and a radio which needs two charged batteries to work. PostgreSQL check bloating of a table Multiple File Extension Rename with single command I received some important files via mail. There are about 150 files like these. The extensions of the files are named as zip1,zip2,zip3, zip_ etc. I just want to change the extension of these files back to zip using a single command to avoid the manual task of renaming each file. The sum of an uncountable number of positive numbers Claim: If $(x_\alpha)_{\alpha\in A}$ is a collection of real numbers $x_\alpha\in [0,\infty]$ such that $\sum_{\alpha\in A}x_\alpha&lt;\infty$, then $x_\alpha=0$ for all but at most countably many $\alpha\in A$ ($A$ need not be countable).  Proof: Let $\sum_{\alpha\in A}x_\alpha=M&lt;\infty$. Consider $S_n=\{\alpha\in A \mid x_\alpha&gt;1/n\}$.  Then $M\geq\sum_{\alpha\in S_n}x_\alpha&gt;\sum_{\alpha\in S_n}1/n=\frac{N}{n}$, where $N\in\mathbb{N}\cup\{\infty\}$ is the number of elements in $S_n$.  Thus $S_n$ has at most $Mn$ elements.   Hence $\{\alpha\in A \mid x_\alpha&gt;0\}=\bigcup_{n\in\mathbb{N}}S_n$ is countable as the countable union of finite sets. $\square$  First, is my proof correct? Second, are there more concise/elegant proofs? Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on I have a scenario. (Windows Forms, C#, .NET)   There is a main form which hosts some user control. The user control does some heavy data operation, such that if I directly call the UserControl_Load method the UI become nonresponsive for the duration for load method execution. To overcome this I load data on different thread (trying to change existing code as little as I can)   I used a background worker thread which will be loading the data and when done will notify the application that it has done its work.   Now came a real problem. All the UI (main form and its child usercontrols) was created on the primary main thread. In the LOAD method of the usercontrol I'm fetching data based on the values of some control (like textbox) on userControl.    The pseudocode would look like this:  CODE 1  UserContrl1_LoadDataMethod() {     if (textbox1.text == "MyName") // This gives exception     {         //Load data corresponding to "MyName".         //Populate a globale variable List&lt;string&gt; which will be binded to grid at some later stage.     } }   The Exception it gave was     Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on.   To know more about this I did some googling and a suggestion came up like using the following code  CODE 2  UserContrl1_LoadDataMethod() {     if (InvokeRequired) // Line #1     {         this.Invoke(new MethodInvoker(UserContrl1_LoadDataMethod));         return;     }      if (textbox1.text == "MyName") // Now it wont give an exception     {     //Load data correspondin to "MyName"         //Populate a globale variable List&lt;string&gt; which will be binded to grid at some later stage     } }   BUT BUT BUT... it seems I'm back to square one. The Application again  become nonresponsive. It seems to be due to the execution of line #1 if condition. The loading task is again done by the parent thread and not the third that I spawned.  I don't know whether I perceived this right or wrong. I'm new to threading.  How do I resolve this and also what is the effect of execution of Line#1 if block?  The situation is this: I want to load data into a global variable based on the value of a control. I don't want to change the value of a control from the child thread. I'm not going to do it ever from a child thread.   So only accessing the value so that the corresponding data can be fetched from the database. Mathematical Prerequisites for QFT How to prove $|a^k|=n/\gcd(n,k)$ whenever $|a|=n$?