java
AccessController usage
You would use AccessController.doPrivileged() to give certain code privileges that code earlier in the calling stack DOES NOT have but which the privileged codes DOES have by virtue of that privilege being granted in a policy. For example, assume ClassA invokes methods on ClassB, and ClassB needs to read the java.home system property (to borrow … Read more
How to get name of scenario in cucumber java?
From version 1.6, in addition to, getStatus() and getSourceTagNames(), there is another method, getName() that returns the scenario’s description. For example, for a scenario as follows: Scenario: verify number of topics shown in the UI scenario.getName() returns “verify number of topics shown in the UI” I initialize scenario in @Before as follows: @Before public void … Read more
Deploy Spring Boot to Tomcat
The chapter Packaging executable jar and war files in the Spring Boot reference documentation states: To build a war file that is both executable and deployable into an external container you need to mark the embedded container dependencies as “provided”, e.g: <?xml version=”1.0″ encoding=”UTF-8″?> <project xmlns=”http://maven.apache.org/POM/4.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”> <!– … –> <packaging>war</packaging> <!– … … Read more
Should I buffer the InputStream or the InputStreamReader?
r1 is more efficient. The InputStreamReader itself doesn’t have a large buffer. The BufferedReader can be set to have a larger buffer than InputStreamReader. The InputStreamReader in r2 would act as a bottleneck. In a nut: you should read the data through a funnel, not through a bottle. Update: here’s a little benchmark program, just … Read more
Can’t refactor rename in Eclipse
If you use Lombok (1.18.22 in my case) and the error message in Eclipse Error Logs says Unhandled event loop exception, then it might be a Lombok issue – which in the mean time has been resolved. Upgrade Lombok to 1.18.24 or above.
–add-modules only on compilation [duplicate]
I made this answer a while ago where I answered this as an additional info to exposing non java.se packages in Java-9 using Maven. The added part specifically focusses on using the standalone version of the java.xml.* APIs. To adapt to which you can probably start consuming the dependency on jaxb-api:2.3.0 which can be loaded … Read more
Difference between PriorityQueue and TreeSet in Java? [duplicate]
When you want a queue, use a PriorityQueue. When you want a Set, use a TreeSet. A TreeSet has unique elements, and doesn’t offer the API of a Queue. A Queue doesn’t offer the API of a Set, and allows multiple equal elements.
Error 404: The requested resource is not available using HelloWorld servlet [duplicate]
Try this (if the Java EE V6) package crunch; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; @WebServlet(name=”hello”,urlPatterns={“/hello”}) // added this line public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println(“Hello World”); } } now reach the servlet by http://127.0.0.1:8080/yourapp/hello where 8080 is default Tomcat … Read more
Parent pom and microservices
The ‘problem’ with a multi-module parent pom is that, without complicated profiles, it locks the modules in the same release cycle (assuming you’re using the Release Plugin, which you should be). The way I work with Maven is to have a parent pom that declares: common dependencies (logging APIs, JUnit, etc). common plugins. all dependencies … Read more