so I want my Logger class to be an singleton. This is the only problem that I have in this program. I succefully added singeton in my other classes but I'm stuck in the logger class. I triend many different things but it gave me error or wrong output. Can anyone help me with the code?  The output that I'm getting -   Logging to: /Users/john/Desktop/File1/myLogFile.log Logging to: /Users/john/Desktop/File1/myLogFile.log Logging to: /Users/john/Desktop/File1/myLogFile.log Logging to: /Users/john/Desktop/File1/myLogFile.log Logging to: /Users/john/Desktop/File1/myLogFile.log Fido:   Speak: 'Woof!'   Fly: [I can't fly]  Logging to: /Users/john/Desktop/File1/myLogFile.log Toonces:   Speak: 'Meow!'   Fly: [I can't fly]  Logging to: /Users/john/Desktop/File1/myLogFile.log     Tweety:   Speak: 'Tweet!'   Fly: Flappy!  Logging to: /Users/john/Desktop/File1/myLogFile.log   The output that I want -   Logging to: /Users/john/Desktop/File1/myLogFile.log Fido:   Speak: 'Woof!'   Fly: [I can't fly]  Toonces:   Speak: 'Meow!'   Fly: [I can't fly]  Tweety:   Speak: 'Tweet!'   Fly: Flappy!  Process finished with exit code 0   This is my Logger class -   import org.omg.CORBA.Environment;  import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter;  public class Logger {     private String logFileName = "myLogFile.log";     private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");       Logger() {         File logFile = new File(logFileName);         if (!logFile.isFile()) {             try {                 logFile.createNewFile();             } catch (IOException e) {                 e.printStackTrace();             }         }         System.out.println("Logging to: " + logFile.getAbsolutePath());     }      public void log(String message) {         try {             String formattedDate = LocalDateTime.now().format(formatter);             String fullMessage = System.lineSeparator() + formattedDate + " - " + message;              // NOTE, this is not the best way.  But good enough for this assignment             Files.write(Paths.get(logFileName), fullMessage.getBytes(), StandardOpenOption.APPEND);          } catch (IOException e) {             e.printStackTrace();         }     }   }   Main class -  import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;  import java.util.Scanner;  public class Main {     private static Scanner keyboard = new Scanner (System.in);     public static void showOff(Animal animal) {         System.out.println(animal.getName() + ":");         System.out.println("  Speak: '" + animal.speak() + "'");         System.out.println("  Fly: " + animal.fly());         System.out.println();     }       public static void main(String[] args) {         Logger logger = new Logger();         logger.log("Program started");          Animal dog = SimpleAnimalFactory.buildAnimal("dog" );         Animal cat = SimpleAnimalFactory.buildAnimal("cat" );         Animal bird = SimpleAnimalFactory.buildAnimal("bird" );           dog.setName("Fido");         showOff(dog);          cat.setName("Toonces");         showOff(cat);          bird.setName("Tweety");         showOff(bird);          Logger logger2 = new Logger();         logger2.log("Program ended");     }  }
What is an efficient way to implement a singleton pattern in Java?
Recursive glob? I'd like to write something like this:  $ ls **.py   in order to get all .py filenames, recursively walking a directory hierarchy.  Even if there are .py files to find, the shell (bash) gives this output:  ls: cannot access **.py: No such file or directory   Any way to do what I want?  EDIT: I'd like to specify that I'm not interested in the specific case of ls, but the question is about the glob syntax. Where is the cron / crontab log? Geometry of Riemann Stieltjes integration What is the geometrical interpretation of Riemann Stieltjes Integration ?   We know that for Riemaan integration $\int_{a}^b f(x)dx$ represents the area bounded by the curve $y=f(x)$&amp; the straight lines $x=a$ &amp; $x=b$.  But when we integrate $f(x)$ with respect to another function $g(x)$ then which area represents that integration geometrically ? Can two different planes share the same flight number? Event button as a module or as user program? Find the expected value of $\frac{1}{X+1}$ where $X$ is binomial The problem:  X is a binomial random variable, find $E[\frac{1}{X+1}]$ n and p are not given  PDF for a binomial distribution is $\binom{n}{k}p^k(1-p)^{n-k}$  Expected value is $\sum{x_ip(x_i)}$  But this is where I get stuck, I'm really rusty on my statistics and I'm not sure exactly how to structure it in the next step? I think I want to get the form of the following out of the summation  $\sum _{k=0}^{n} \binom{n}{k}p^k(1-p)^{n-k} = (p + 1 - p)^n = 1$  But I'm not sure if it should look like  $\sum \frac{1}{xp(x)+1} $  and if it should where to go from here? Why can't I run this C program? I'm trying to run my first "process" program, but I get the following error :  ./fork.c: line 4: syntax error near unexpected token `(' ./fork.c: line 4: `int main()'   I'm pretty sure that the code is correct:   #include &lt;sys/types.h&gt;  #include &lt;stdio.h&gt;  int main() {      pid_t pid;      printf("Hello fork()\n");      switch(pid=fork())  {          case -1: printf("Error by fork().....\n"); exit(0);          case 0: printf("I'm the child process \n"); break;          default: printf("I'm the dad \n"); break;      }   exit(0); }   What is wrong? I am aware that there are plenty of threads on intensifiers(very, rather, pretty, quite, fairly, etc.), both on this site and on the web, because of their ambiguity in terms of meaning. What I have learned is that their meaning can change depending on which country you are from, which context they are used, or your intonation. So instead of comparing all intensifiers, I decided to make my question more specific. I chose to focus on the word pretty because of its "common" usage.  So as we can see, the word pretty has two meanings and unfortunately they are "pretty" opposite. My question is can you tell me, just by taking into account  the example sentences below, in which sentences "pretty" means "fairly,", and in which it means "very?"  Does "Tom looks pretty tired" always mean "Tom looks a little/fairly tired" ? prove $\lim_{n\to\infty}{\frac{a^n}{n!}}=0$ I have the proof but i don't understand one part. The proof (for $a&gt;1$) goes as follows:  there exists $k \in N$ such that$a&lt;k, \frac{a}{k}&lt;1$ and since $\frac{a}{k+i}&lt;\frac{a}{k}, i \in N$ $$\frac{a^n}{n!}=\frac{a}{1} \cdot \frac{a}{2} \cdot...\cdot\frac{a}{k}\cdot\frac{a}{k+1}\cdot...\cdot\frac{a}{n}&lt;\frac{a^k}{k!}(\frac{a}{k})^{n-k}=\frac{a^k}{k!}\cdot \frac{a^na^{-k}}{k^nk^{-k}}$$  $$0&lt;\frac{a^n}{n!}&lt;\frac{k^k}{k!}(\frac{a}{k})^n$$  then $$0 \leq \lim_{n\to\infty}{\frac{a^n}{n!}}\le\frac{k^k}{k!}\lim_{n\to\infty}{(\frac{a}{k})^n}$$  Now, the part I don't understand is in the expansion of $\frac{a^n}{n!}$. How does one come with $&lt;\frac{a^k}{k!}(\frac{a}{k})^{n-k}$ part, to be more precise, how does one come up with $(\frac{a}{k})^{n-k}$ part of the inequality? Number of possible marriage arrangements if Marriage Condition is satisfied Suppose I have a set of $n$ boys and each subset of $1\leqslant k \leqslant n$ boys knows at least $k$ girls then this means that the set of boys $B$ satisfies the marriage condition.  I am doing an exercise from a Graph Theory book and it says we can show by induction on $n$ that the number of possible marriage arrangements is $\geqslant t!$ if every individual boy knows at least $t \leqslant n$ girls or there are $\geqslant t!/(t-n)!$ possible marriages if each individual boy knows at least $t&gt;n$ girls.   I am struggling to see how the induction hypothesis can be implemented to prove the $n+1$ case. When you swap from the $n$ to $n+1$ case the conditions change and I can't see the link between them.  Would anyone be able to point me in the right direction? I have a list of tuples like this:  [ ('a', 1), ('a', 2), ('a', 3), ('b', 1), ('b', 2), ('c', 1), ]   I want to iterate through this keying by the first item, so, for example, I could print something like this:  a 1 2 3 b 1 2 c 1   How would I go about doing this without keeping an item to track whether the first item is the same as I loop around the tuples? This feels rather messy (plus I have to sort the list to start with)... A random variable with neither probability density function nor probability mass function... is this example wrong? This is from Shreve's Stochastic Calculus for Finance II, Appendix A.3. Consider infinitely many independent coin tosses with outcomes $\omega_n$, $n = 1, 2, \dots$ such that $\omega_n$ can be either $H$ = heads or $T$ = tails. Define \begin{equation} Y_n\left(\omega\right) = \begin{cases}1 &amp; \text{ if }\omega_n = H \\ 0&amp; \text{ if } \omega_n = T\text{.} \end{cases} \end{equation}  Define $\displaystyle Y = \sum\limits_{n=1}^{\infty}\dfrac{2Y_n}{3^{n}}$. Shreve shows that $Y$ can only take values in the Cantor set, and since that particular set has measure zero, its Lebesgue measure is zero as well, thus it does not have a probability density function (since integrating such a density function would give a value of $0$). This part I understand, as well as my professor.  Now Shreve claims that $Y$ does not have a probability mass function.      If it did, then for some number $x \in C$ [the Cantor set] we would have $\mathbb{P}\left(Y=x\right) &gt; 0$. But $x$ has a unique base-three expansion    \begin{equation} x = \sum\limits_{n=1}^{\infty}\dfrac{x_n}{3^{n}}\text{,} \end{equation}   where each $x_n$ is either 0, 1, or 2 unless $x$ is of the form $\dfrac{k}{3^{n}}$ for some positive integers $k$ and $n$. In the latter case, $x$ has two base-three expansions... In either case, there at most two choices of $w \in \Omega_{\infty}$ [that is, the infinite coin-toss space] for which $Y(\omega) = x$. In other words, the set $\{\omega \in \Omega; Y(\omega) = x\}$ has either one or two elements. The probability of a set with one element is zero, and the probability of a set with two elements is $0 + 0 = 0$. Hence $\mathbb{P}\left\{Y = x\right\} = 0$.   My professor and I were able to follow this until the statement "The probability of a set with one element is zero." Is this a true statement? How so?   I thought it would be perhaps the fact that the Lebesgue measure of $[a, a] = \{a\}$ is zero, but I don't see any reason why Shreve would only use the Lebesgue measure, since it is not a general probability measure. Regex to match only letters Firmware vs. Software The new top bar layout is fine, but the black color is very visually jarring/intrusive.  Is using a lighter color an available option? Option to hide rep/badges on the avatar block displayed of you SELECT permission on view querying table from another database I will be traveling from Australia to Austria, transferring in Abu Dhabi. Is it alright for me to bring a vibrator in the check-in luggage, or are there laws against that?  It is approximately 17cm long. Are there any precautions to take? Image uploads from the editor strip preceding line breaks Recently, using the image uploader in the post editor has starting stripping preceding line breaks; placing the image directly after any previous text instead of at the current cursor position. This means that the inserted image is placed inline as part of the previous line of text rather than in a new paragraph as it did previously...  Before inserting the image (note the cursor position):        After inserting the image:        This also happens after the Markdown for a horizontal rule, which destroys the rule and gives us a bunch of hyphens followed by an image instead:        Seems the behaviour is a bit inconsistent... Sometimes I get the behaviour shown above and sometimes it leaves a single newline, I'm not sure when or why but single line breaks are ignored in Markdown so the rendered result is the same regardless.  Obviously it's useful to be able to have inline images, but I'm pretty certain most images aren't intended to (and shouldn't) be. Are there tips and tricks to overcome a fear of flying? Are there tips and tricks for people with fear of flying that can makes them have a more pleasant experience when flying? I know drugs can do magic, and . I'm ideally after official advice and recommendations, but other tips and tricks would be nice as well.