Search Results
| Search type | Search syntax |
|---|---|
| Tags | [tag] |
| Exact | "words here" |
| Author | user:1234 user:me (yours) |
| Score | score:3 (3+) score:0 (none) |
| Answers | answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
| Views | views:250 |
| Code | code:"if (foo != bar)" |
| Sections | title:apples body:"apples oranges" |
| URL | url:"*.example.com" |
| Saves | in:saves |
| Status | closed:yes duplicate:no migrated:no wiki:no |
| Types | is:question is:answer |
| Exclude | -[tag] -apples |
| For more details on advanced search visit our help page | |
Results tagged with java
Search options not deleted user 61852
Java is a high-level, platform-independent, object-oriented programming language originally developed by Sun Microsystems. Java is currently owned by Oracle, which purchased Sun in 2010.
2 votes
Should I initialize a List when declaring it or should I use a static block?
It makes no difference and it's a matter of personal preference. That said I like the second option best because the initialization, not being a one-liner, breaks the visual tidyness when there are s …
1 vote
Parameter objects placeholder?
In layman's terms: I'd suggest you put it in the same package as the class whose method, having initially such a long signature, originated the need for such a paramter object. Parameter classes are …
4 votes
Anonymous class as singleton
Acording to that rationale, every anonymous class is a singleton, since they have no name, you cannot instantiate it more than once. One issue is that they have to live inside another class. IMHO th …
4 votes
Accepted
Using Constructors in Java
Constructors are not used for readability. In fact, I cannot think an example in which a constructor could be user for readability. The constructor in the example just gives an initial value to class …
1 vote
Accepted
Is it possible to have a keyed dictionary stored on disk?
Yes indeed. There's something called disk-based hash tables. You generate keys that correspond with a physical location in disk. The accepted answer in this SO question tells you a possible implement …
1 vote
What is the proper way for these methods to function?
In layman's words You have to separate business logic from presentation logic. The game class (business logic) should not read input from console not from an HTML form. The game class (business logi …
11 votes
Accepted
Java: difference between String a = null and String a = new String()
First let's clarify something: You mention that after assigning null to the variable you could forget to initialize it, but by assigning null to it you are in effect initializing it. public static vo …
4 votes
Accepted
How can I explain the A a = new B();?
Yes, you are correct. ia is of class B ia is also of class A since B inherits A. B overrrides A's doA() method.
1 vote
Why can static methods only use static data?
Think of it as static methods living in a non-object-oriented dimension. In the "object oriented dimension" a class can spawn multiples egos (instances), each ego has conscience of itself via its sta …
9 votes
Accepted
Is it possible to make some methods invisible/non-usable to some classes in Java?
That cannot be done. Your problems arise from violating ISP. That said, the only idea I can think of is to force client classes to register with your classes in order to be able to call their methods …
1 vote
Why null pointer instead of class cast?
Java successfully casts null to an Integer reference that references no object. That's OK because being unistantiated is a valid state for a reference. …
0 votes
Should I add parameters to instance methods that use those instance fields as parameters?
Short anwer: If the instance method has access to the instances variables then there is no need to pass those same values as parameters. If you want to create a class (static) methods, then such a me …
0 votes
A way to return multiple return values from a method: put method inside class representing r...
Short answer: You can return an array or a List with the two values. I personally would write two distinct methods, like int x = obj.getX(); int y = obj.getY();
14 votes
Accepted
Using nested public classes to organize constants
For example in the Java API every class/interface has its constants. They are not in a Constants class/interface with hundreds of constants, either grouped into inner classes or not. …
0 votes
Can a recursive function have iterations/loops?
The "create an smaller version of the problem" part can have loops. As long as the method calls itself passing as a parameter the smaller version of the problem, the method is recursive. Of course an …