Skip to content

Tag: java

How to check for a sequence of keystrokes

I’m making a game and want to implement cheat codes like the Konami code. But how do I check for that sequence of keystrokes? I want it to work so that if a player just types the code it will trigger. Thanks in advance! Answer Below is a class that checks for the Konami code, including cases such as &#8…

Is it possible to generate a XSD from a JAXB-annotated class?

I’ve written a number of classes using JAXB for serialization and I was wondering if there was a way to generate a XSD file for each of these objects based on the annotations. Is there a tool for this? Something like generate-xsd com/my/package/model/Unit.java would be awesome. Does anything exist to do…

JPA: unidirectional many-to-one and cascading delete

Say I have a unidirectional @ManyToOne relationship like the following: If I have a parent P and children C1…Cn referencing back to P, is there a clean and pretty way in JPA to automatically remove the children C1…Cn when P is removed (i.e. entityManager.remove(P))? What I’m looking for is a…

BigDecimal – to use new or valueOf

I came across two ways of getting BigDecimal object out of a double d. new BigDecimal(d) BigDecimal.valueOf(d) Which would be a better approach? Would valueOf create a new object? In general (not just BigDecimal), what is recommended – new or valueOf? Answer Those are two separate questions: “What…

Why do arrays change in method calls? [duplicate]

This question already has answers here: Are arrays passed by value or passed by reference in Java? [duplicate] (7 answers) Is Java “pass-by-reference” or “pass-by-value”? (93 answers) Closed last month. When I write like this: It prints x22; When I write like this: It doesn’t pri…