All Questions
9,545 questions
4
votes
2
answers
102
views
How can I prevent an object from being modified after it’s created in Java?
I’m trying to make sure an object can’t be modified after it’s created in Java. For example, in the class below, I can change the values of model and year using setters. But I want to prevent that and ...
-3
votes
0
answers
95
views
How to read the object instead of the memory address
I've been working on this project and when I try to read the data stored in the memory retrieves only the memory address instead of reading the object I tried to see if it was a problem with my code ...
-2
votes
2
answers
85
views
How do I call the method from a class that creates other objects? [closed]
I have five classes. My Main class, a form class, two subclasses that extend the form class and a createForm class I am forced to use to create new instances of the subclass.
public class FormenFabrik ...
0
votes
0
answers
31
views
Constructor and datatype not matching in java [duplicate]
I'm relatively new to Java and object oriented programming, and I don't understand why sometimes the constructor used in declaring and object will be a subclass of the objects type instead of the ...
1
vote
1
answer
31
views
LibGDX orthographic camera movement using object?
In Java in LibGDX I'm trying to make my camera follow an object created by shaperenderer. I don't want to use a sprite, but can only find tutorials for sprites. Using spritebatch and such.
I just want ...
1
vote
4
answers
126
views
Why do I need to make a static class to make instances of that class?
When I'm trying to make instances of my class I get errors unless I add the static keyword. I'm wondering why this is, doesn't this go against the whole concept of being static.
Here is my code that ...
3
votes
2
answers
92
views
Is there an algorithm for shuffling objects in an array randomly WITHOUT utilizing Lists and Collections
I want to shuffle an array of Objects in a card game simulation.
I scrolled through many posts on here and almost all of them mention transforming the array into a list, then shuffling it using an ...
0
votes
0
answers
52
views
Why my object equals null, when i want to share it between two activities
My task is to click on the button "add" in 1_activity, which sends me to 2_activity where i need to key my data into fields and click on the button "save", which saves the data and ...
0
votes
0
answers
41
views
google gson JsonObject incorrect data type
I am trying to create a json for export. I am using com.google.gson.JsonObject to do so.
I have an issue where when i add a integer value into the jsonObject, it became a number.
JsonObject jsonObject ...
-1
votes
1
answer
59
views
Is there a way to get all non-null nested attributes of an object?
If I've got 2 classes as follows:
class Car{
String carName;
String serial;
Wheel wheel;
}
class Wheel{
String wheelName;
Integer someInt1;
Integer someInt2;
Set<...
-2
votes
3
answers
119
views
Add an array of objects as a parameter to a constructor
I am working on a Java quiz application. In this I want the four answer options to be as an array instead of coding it is as Option 1,2,..4. How do I add an array of objects to the constructor?
I am ...
-1
votes
1
answer
63
views
readObject() does not throw exception when the socket is abruptly closed by the remote server. What is the optimal way to find out? [duplicate]
When a client waits for a java object from the server using readObject, we could think that when the server shuts down, it would cause an IOException on the client. But this does not happen, and ...
0
votes
1
answer
90
views
Java: Remove a collection of objects (for ex the info about a vehicle with ID xxx) from a list and return removed objects to new list
I want to remove a collection of objects from a List, the removed objects should be added to new list and returned. The expected return of removed object (car) when outprinted look like for ex:
[...
0
votes
1
answer
85
views
how to test a method that uses clobs?
I have a method that compares the value of objects (as string, date, number...) and returns true or false depending of the result.
I've created a unit test for this method, but I'm having a problem ...
0
votes
0
answers
28
views
How to properly restore system state after shutdown in Java using Restore class?
Problem:
I am working on a Java project where I need to restore the system state after a shutdown caused by an event (such as a PowerOut or WindowMalfunction). When the system is restored, it should ...