spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » JAVA » Page 5
Should members of static class in Builder pattern be final?
The design here is that the first and last names always have to be set, but the age is optional. (I would have used Integer here, rather than defaulting to 0... but then I'd prefer to use a birthDate anyway... but I digress.) That "required vs optional" part is communicated through forcing the first name and last name to be present on construction... so why would you also want setters? When would

Categories : Java

IllegalArgumentException: Comparison method violates its general contract! on Integer[]
java.lang.Integer's compareTo(Integer) method does not violate any contract about sorting, of course. As you noted, though, Arrays.sort (and probably any other sorting algorithm implemented in the JDK) implicitly assumes that it's the only one manipulating the array. If this array is accessible from multiple threads, you'll have to protect the access to it, e.g., but using a synchronized block.

Categories : Java

Find palindromes from multiple lines in file
I can tell you how to reverse the String to determine if it is a palindrome. I don't know how to effectively build a palindromic phrase based on your requirements. To reverse the String, pass the original String to the StringBuilder constructor and use its reverse method to reverse the string: String str = "word"; StringBuilder buff = new StringBuilder(str); boolean isPalindrome = str.equa

Categories : Java

Using a maven project to test another project
Your above produces a circular dependency. I have done this in the past not for unit tests but for integration tests. What I suggest is that B depends on A (A has no dependency on B). In src/test/java of B write all the tests you need. When you run mvn test on B it will pass or fail depending on if the tests pass or fail. There is not a way to make the compilation of A fail based on the tests in

Categories : Java

Spring JMX Bean Not Visible in JConsole
The solution is to add a line to the server bean <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"> <property name="locateExistingServerIfPossible" value="true" /> </bean>

Categories : Java

Properties file in JAR on Websphere
I posted a solution long time back on this one, please see below link and explanation: http://gauravwrites.blogspot.com/2009/06/loading-resource-file-runtime-residing.html Basically you need to use class loader to locate property packaged as part of JAR file, due to the way loading works in WebSphere. Let me know if you need any information around it.

Categories : Java

Forcing Jaxb preference of union member type when compiling
I believe, what you've referenced should actually work for arbitrary simple types. Assuming tns is a declared prefix for the targen namespace in your schema, try the following mapping: <globalBindings> <javaType name="javax.xml.datatype.XMLGregorianCalendar" xmlType="tns:CPT-DateTime" .../> </globalBindings> However, I am not 100% sure. Also check xjc:javaType.

Categories : Java

Android change order of cursor
If the ordering is defined as a calculation in SQL, then I think you'll have to requery. (The cursor will not dynamically recalculate the "ORDER BY" clause, this happens at query time in SQL). Alternatively, you could change your adapter to one backed by a list instead of a cursor, and implement a Comparator to sort the data. Then notify the adapter that the data has changed. Assuming each row in

Categories : Java

How to enable Swagger UI? Tomcat, SpringMVC, REST
I solved my problem by adding swagger-ui resources to srcmainwebappdocs I also added <mvc:default-servlet-handler/> To pom.xml Now I can access swagger UI under: http://localhost:8080/myapp/docs/

Categories : Java

Decryption pad block corrupted
You should not rely on available() to detect the end of the stream. It may work now (for files), but it may not in the future. Instead, use the output of read(). More importantly however you are calling cipher.doFinal(). One of the features of doFinal() is that it checks the padding for ciphers that require it (CBC and ECB mostly). Now padding is only applied at the end of the plaintext message,

Categories : Java

Is java toBinaryString Incorrect?
You aren't parsing your input string as a HEX representation. You're taking each character, getting its char value and converting that to binary representation. What you want is to parse the input text as a base 16 integer String hexCode = "A1E1F1"; int val = Integer.parseInt(hexCode, 16); System.out.println(Integer.toBinaryString(val));

Categories : Java

Why does JDBC not support Oracle Boolean type
From: PL/SQL TABLE, BOOLEAN, and RECORD Types It is not feasible for Oracle JDBC drivers to support calling arguments or return values of the PL/SQL RECORD, BOOLEAN, or table with non-scalar element types. However, Oracle JDBC drivers support PL/SQL index-by table of scalar element types. ... As a workaround to PL/SQL RECORD, BOOLEAN, or non-scalar table types, create container proce

Categories : Java

Java RMI: Rejecting requests when saturation is reached
RMI offers you a way to control the server socket creation, if you control the creation of client-server socket, you can decide whether to serve the incoming request or not, and of cause you can monitor rejections of service. here you need to extend ServerSocket. And if you want to reject "method invoke request", you can use a proxy object. public class T { public static void main(String[] a

Categories : Java

My random numbers are always zero?
Instance field initialization expressions are executed before the constructor body. So private int num1 = rand.nextInt((max - min) + 1) + min; is executed before this.max = max; this.min = min; in the constructor. At that point, the value of max and min is therefore the default 0. Move the initialization statement of num1 to the constructor body, after the assignments of max and min.

Categories : Java

Use DelimiterBasedFrameDecoder, StringEncoder, etc outside of pipeline in Netty
It's possible to put all encoders/decoders logic into the handler, but it's bad idea from architecture point. Would be better to write new codec (encoder/decoder), maybe even based on them, you can look inside of StringEncoder or StringDecoder or even to DelimiterBasedFrameDecoder to understand how to do it, in fact they are pretty simple, or check on the netty site how they implementing TimeEnc

Categories : Java

Play 2.x: Binding model which contains a list to the template
As mentioned in comment probably JavaScript and AJAX would be most comfortable solution, you can i.e. create an User as unactive and activate him only when at least one address is added later. Other solution can be using custom class with fields from both (User and Address) so after validating all required fields you can create an User and associated Address. Sample User model: public class Us

Categories : Java

My activity is going to potentially hold a lot of fragments (5+) how should I create them?
In one of my activities, I add all the fragments onWindowFocusChanged (so I have proper screen measurements): private void addFragments() { if(mPassedMachine.getMachineType() == MachineType.ZR7) addZeroFragment(ANIMATION_TYPE_NONE, false); else addLevelFragment(ANIMATION_TYPE_NONE, false); addHeartRateFragment(ANIMATION_TYPE_NONE, false); addMaxMinAvgFragment(ANI

Categories : Java

How do I convert 16-bit char array to 8-bit char array and send to c code using JNA?
If your native signature requires const char*, then JNA will automagically work when you pass a Java String. No conversion necessary. Internally, JNA will create a temporary buffer (for the duration of the call) and encode the Java String as a native NUL-terminated byte array (defaults to utf8 encoding, but can be modified by setting the system property jna.encoding).

Categories : Java

apache commons-validator alternative for new gTLDS
If you are not concerned about internationalized addresses, you could change last part of address, and continue to use Apache commons. This approach is based on the fact that whatever the TLD is, the validity of the whole domain name is equivalent to the validity of the same domain name with the TLD replaced with com. For example: abc.def.com is valid. Similarly abc.def.name, abc.def.xx--kput3i

Categories : Java

Wicket Panel inside of a Fragment
Yes, it is. Here's a simple example: Page: package com.mycompany; import org.apache.wicket.request.mapper.parameter.PageParameters; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.panel.Fragment; import org.apache.wicket.markup.html.WebPage; public class HomePage extends WebPage { public HomePage(final PageParameters parameters) { super(param

Categories : Java

when to use constructor injection in spring?
The correct approach is to use constructor injection whenever it's possible. Thanks to that it's clear what are the object dependencies and you are not able to create one if you do not provide all that are required. Use constructor injection as below. public class ProjectService { private final ProjectRepository projectRepository; private final TaskRepository taskRepository; @Aut

Categories : Java

Afterburner.fx fail load resource from object injected
Finally, I found the problem that no have relation with Afterburner.fx: When I create Project with maven, I not include resources from folder img in my POM, so I get always the above error. Perhaps, I can load other default resources like css styles. After configure correctly my POM, all things work.

Categories : Java

Unable to run under Jetty from Eclipse: Unknown scope: debug
I am not a regular jetty user. Just now installed Jetty 8.1.14 from eclipse marketplace on my Eclipse Luna 4.4.0 (Mac) and it is working like a charm. Please try to upgrade eclipse/jetty if you are using older versions.

Categories : Java

Drawing multiple lines (minimum 9x9) in JFrame
I had to modify your code just to get it to compile. I made several changes to give you a starting point for your continued development. Here's what my version of the Go Frame looks like. So, here are the changes I made. First, you must always start a Swing application with a call to SwingUtilities.invokeLater. public static void main(String[] args) { SwingUtilities.invokeLater(new GoB

Categories : Java

Can't solve "Java heap space" error in eclipse
Where is the "vmargs" option? If you set the min/max heap, you probably need to do it on the main process, not the launcher. See the Eclipse FAQ item on setting VM options. That launcher PermSize opt is a bit ridiculous. Unless you know it is launcher PermSize causing the OOM, keep it at the default of 256m. [EDIT] As pointed out else-thread, if this is happening when you run your Java progra

Categories : Java

generic signature to accept Map or Map
If you were only reading the values out of the Map you could have done something like this: public static Report createReport(Map<String,?> parameters) {...} However, since you also want to add enteries, you need to know the type, or at least be able to know that the type in the Map is the same as the type you are adding. If it is variable, then I would suggest having another parameter t

Categories : Java

Value isn't being brought over
I tried to fix some of your logic. You were in an infinite loop since there was no way to ever break out of it. I fixed this by making a valid number boolean. Also why the outer while loop? That increases the time complexity for no reason. So got rid of it and replaced with an if if (invalidInput) finalNum = JOptionPane.showInputDialog(null, "Please enter a number

Categories : Java

Integrating Selenium Test Suite (Eclipse) with TFS
You can call UI scripts as you describe and I would additionaly recommend that you use Release Management to do this rather than build. It makes much more sense to use a deployment engine rather than a compilation engine to maintain this. One does not usually have an instance of ones application running on the build server. http://nakedalm.com/execute-tests-release-management-visual-studio-2013/

Categories : Java

Java - How to create a new class that extends JFrame and has all GUI components in it while another class has all functionality?
Provide a Controller as Singleton for the gui: http://en.wikipedia.org/wiki/Singleton_pattern e.g. class Controller{ private Controller _instance; private Controller(){ } public static Controller getInstance(){ if(_instance == null){ _instance = new Controller(); } return _instance; } public void addCard(Card card){ } publ

Categories : Java

How to correctly use Apache Common BeanUtil's BeanComparator to benefit of introspection?
You've gotta look at the various constructors on there: BeanComparator(String property) Constructs a property-based comparator for beans. BeanComparator(String property, Comparator comparator) Constructs a property-based comparator for beans. Here's the former's javadoc (2nd para is your answer): Constructs a property-based comparator for beans. This compares two beans by the proper

Categories : Java

Java memory issue with animated gif frames
Ok, I found the solution Thanks to http://stackoverflow.com/a/16234122/2655623 and http://stackoverflow.com/a/8935070/2655623 You may also get a deprecation warning because of com.sun.imageio.plugins.gif.* files. But that is fine. I copied these files into my project so the issue is solved. Now I can get images (Search them by index) without putting all images into the memory. ;) Edit: Please u

Categories : Java

converting ArraList to JSON (in Java) and accessing it with Javascript
You may need to create a REST service end point and expose Array content as JSON. then you should be able to retrieve JSON from browser and consume it. Simple way of creating such end point is given in spring documentation https://spring.io/guides/gs/rest-service

Categories : Java

How to properly close threads and file handles in async object
Finalize is where I'm thinking I should handle such things Finalizers are called by garbage collection, and the garbage collector runs when there's a need to reclaim unused memory. The garbage collector does not run because of a shortage of file descriptors or database connections or any other resource. It does not run because there's a transaction that's been left hanging open... Don't us

Categories : Java

TreeMap Element does not removed
returning 0 would merge keys Returning 0 means the elements are equal. If you don't return 0, elements are never equal. Your TreeMap uses the given Comparator to put and remove. Your Comparator never identifies two keys as equal and therefore cannot remove anything.

Categories : Java

Index out of bounds exception when trying to swap the colums of a matrix
This is because you rows and columns are not same. Consider an example : A 3x4 matrix [1,2,3] [4,5,6] [7,8,9] [10,11,12] now interchanging rows and columns [1,4,7,10] [2,5,8,11] [3,6,9,12] This becomes a 4x3 matrix EDIT : public static void main(String[] args) { int [][] arr={{1,2,3},{4,5,6},{7,8,9}}; printArray(arr); System.out.println(); swapAllcolumn

Categories : Java

How to fix ad to the screen while in scrollview?
Easy. Don't put the ad in the ScrollView. instead of <ScrollView> <!-- your ad here --> <!-- your content --> </ScrollView> try something like <LinearLayout> <!-- your ad here --> <ScrollView> <!-- your content --> </ScrollView> </LinearLayout>

Categories : Java

Making CRUD in Liferay MVC
You seem to be missing some fundamental understanding about how to pass around the proper ids. My recommendation is to build this portlet, including the entity, with xmlportletfactory. That one will use servicebuilder, but generate all of the code that you currently are implementing on your own, including the frontend portlet. You can take a look at this code, debug and inspect it. Then transfer y

Categories : Java

type-casting can be an example of adapter design pattern?
No. Since an adapter pattern requires Object instances, and type-casting primitives uses no Object(s) at all, it isn't an Adapter pattern. Even if you cast between Object instances (which you could only do if they were in the same type-hierarchy), it would not be an adapter pattern. From the Wikipedia article (emphasis added), the adapter pattern is a software design pattern that allows the interf

Categories : Java

insert data into database(mongodb)
"i have a front end which has 4 text boxes saying "name","manufacturer","colour" and "price"....so whatever i enter in the text box should be put into the database....however in the above code insertion can be done only by explicitly specifying the values....so i need to change this for a generlized method" Just change it to something like: String name = nameField.getText(); String manufactu

Categories : Java


Recently Add
Essbase Java API export database MAXL
String length is getting wrong from two strings in java?
How the connection pool works
How to show data on same page after controller call?
Is there a way to use string names as indexes in java arrays?
adding items to an Hashmap and getting error null.pointer.exception
Java : arraylist shows empty when it used to show null values
how to copy the console output into a file in java?
I can't figure out why a class i made isn't working
How do I sign a java applet if I bought an SSl through Hostgator
Logic error towards the end
Cant store a message on a method in java with exceptions
JSF - c:forEach Not Working On Recursive Method
How do I store the type of a class for use later in Java?
Timer management in Java
Scanner nextLine() occasionally skips input
How to add dates into ArrayList before and after a specified date
JSF with Spring Controllors
How to create two column and with auto number in jasper report to excel?
“Your security settings have blocked a local application from running” Java 8
Too many solutions to coin change maker
Give low level functionality to a JMenuItem "Copy" in a GUI that I am creating
Get HTML and Display it in WebView perfectly
How would I reduce the repetitiveness of this method?
Java fileWriter is not writing all of my output to a file
finding a hash function for long integer array
Programming about finding the triangle
How to reduce the file size of a xml file that is created using java?
JMS Connection Pooling in Message Listener
How can I round down a decimal?
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.