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.

learn more… | top users | synonyms

0
votes
1answer
69 views

How do you write super() in the UML format?Is it correct to write super(parameter: type): return type in the UML methods section?

Suppose you write a subclass that extends to a certain class and in that subclass, you use the super() method for your constructor. Would you write "super(parameter: type): return type" in the UML?
-1
votes
1answer
59 views

Enable matching of character sequence made up of regex control character

Java Pattern provides flags that enables you match regex control characters. Passing Pattern.LITERAL or 16 as second argument will match any Unicode char, but not if you use a word bound with the ...
2
votes
2answers
171 views

What is a good approach to get a detailed system design from an existing system?

I will be working on a system which will be ported over from Java to .Net. It is a pretty big system. I don't have any specifics about how the system is designed, no documentation, nothing. You know ...
2
votes
2answers
179 views

Mutable objects - setters and getters

Is it a good practice to have a setter method of this kind? With primitive types, it's obviously fine, but when you have a setter for a field which holds a reference to mutable object, this might go ...
3
votes
2answers
164 views

How do people make libraries cross-platform?

How do people make libraries cross-platform (UNIX-systems and Android, sometimes even iOS)? What do they use? I'm asking this because I make libraries as a hobby and I'm curious.
6
votes
3answers
366 views

Best practices for using public, protected, private?

Is it fair to say that it is good practice to default everything to private up front when coding something? And then only upgrade it to protected if a subclass needs it, or public if another class ...
1
vote
1answer
59 views

Better way to organize query methods in Android?

In my Android app I have a SQLiteHelper class that extends SQLIteOpenHelper, and takes care of things like table-creation and upgrades. SQLiteDatasource class that performs CRUD operations on the ...
3
votes
1answer
84 views

Bounded Type Parameters

Ref: https://docs.oracle.com/javase/tutorial/java/generics/bounded.html, We have the method: public <U extends Number> void inspect(U u) Why can't this be: public void inspect(Number n) ? It ...
-3
votes
2answers
58 views

class name for linked lists

I have a question about how to name a class in java. Could a class name be arbitrary or have to obey some rules? For example, I want to define linked lists in a class, does the class name have to be ...
2
votes
3answers
84 views

Calling a constructor from a parent class in a derived class

I'm trying to create a parent class with a constructor that takes a single int as a parameter. I also need to derive a child class that creates two instances of the parent class using a constructor ...
3
votes
2answers
202 views

Using MVC style, where is the best place to put SQL functionality?

I am wondering about best practices here. MVC (Model - View - Controller) patterns involve separating components of your program that model the data, manipulate those models, and display those ...
0
votes
1answer
71 views

How to import driver details and Connection details without writing it manually or hard coding?

class ConnectionUtil{ public static void main(String args[]){ try{ Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con=DriverManager.getConnection( ...
5
votes
1answer
86 views

How can I plugin new JARs implementing an interface dynamically?

Quick background: I am working on developing an interface that will be implemented by myself and other developers. This interface will allow users to "plugin" new functional code into a system for ...
2
votes
3answers
153 views

designing classes for testability

I am writing a library for OVH api calls, and I am wondering how to make it friendly for unit tests. I have a class APIClient. The constructor of this class initializes the object with all parameters, ...
5
votes
4answers
280 views

Why instantiate an object to a Base class rather than a specific Sub class?

For example: URL blogFeedUrl = new URL("http://manishmaharzan.com.np/getJSON/json.json"); HttpURLConnection connection = (HttpURLConnection) blogFeedUrl.openConnection(); connection.connect(); ...
-1
votes
1answer
73 views

Best approach to scheduled events in Node.JS

I'm currently writing a browser based game where events occur in real time - as an example of this, take Farmville, where a crop only grows after a particular length of time. Running a method every ...
4
votes
0answers
96 views

Is the observer pattern suitable when the observers are not independent of each other?

I have a class Car which has 2 properties: int price and boolean inStock. It also holds a List of abstract class State (empty class). There are 2 states which can be applied on the car and each is ...
0
votes
2answers
74 views

What is the accepted practice for handling numeric conversions under OOP?

I am making a weather app that involves temperatures. You can change between Kelvin, Celsius, and Fahrenheit just for fun. However, temperature figures get used all over the place in different ways. ...
9
votes
4answers
288 views

Composable concurrency in Java or any other programming language

While I was reading a research paper on concurrency named Software and the Concurrency Revolution (html version). I came across following lines: Unfortunately, although locks work, they pose ...
1
vote
0answers
38 views

Polymorphically handle result of subtraction

I have an amount class which provides the minus method among others. The result of this operation is of course another amount. The question is how can I handle the three cases according to the signum ...
1
vote
0answers
61 views

Downloading information, but just when needed

I'm struggling with thinking of how to implement the following (in java): I try to create a program, that displays information about lots of tv series. For this i use the website "Burning Series" ...
5
votes
2answers
193 views

Is “use ”abc“.equals(myString) instead of myString.equals(”abc“) to avoid null pointer exception” already problematic in terms of business logic?

I heard numerous times that when comparing Strings in Java, to avoid null pointer exception, we should use "abc".equals(myString) instead of myString.equals("abc"), but my question is, is this idea ...
8
votes
1answer
190 views

Code Design: Delegation of arbitrary functions

On PPCG, we frequently have King of the Hill challenges, which pit different code bots against each other. We don't like limiting these challenges to a single language, so we do cross-platform ...
2
votes
4answers
121 views

Are names like OrderCreation and UserRegistration suitable names for business logic / domain classes

We have moved to a more SRP model and found coming up with class names challenging. Previously we had a Order class that looked something like this: public class Order { public void Create() ...
-3
votes
2answers
129 views

What is the difference between extending a class and instantiating an object of that class?

I frequently see people extending a class like this for example: public class Bananas extends Fruits { public void eatFruit(){ } } rather than public class Bananas { Fruits ...
2
votes
2answers
109 views

Should we add an extra class to this code sample

I have a shopping website which allows users to place orders. In my web application when the users click 'Create Order' i call an OrderService class which looks like the below: public class ...
1
vote
1answer
60 views

«Heavy» object initialization: within each thread or outside and then pass it to the threads as parameter?

Let say there is an array of strings, I have to process. I'm using a «heavy» third-part object which gets the string and performs its analysis. In order to optimize a performance, I create a number of ...
4
votes
1answer
67 views

Repeating a process can be a situation for method overloading?

I am developing a converter from objects of different domains, which accepts both, converting one object to other, or a list to another list. Please consider the following example: public MyObject2 ...
4
votes
2answers
320 views

Are there any reasons not to use a DI framework on a standalone project?

While researching technologies for a new "pet project" I analyzed a few well-established project's source code and I noticed that they hardly use any dependency injection frameworks at all. For ...
-7
votes
1answer
177 views

Java: Why's this For-Loop thousands of times slower?

So I have a simple method I'm calling millions of times a second, and I noticed that it was taking 16% of all processing time!! The offensive routine is as follows: public void placeHolder(){ ...
1
vote
3answers
111 views

What should be in my business logic class

We are currently having an internal debate on how our business logic classes should be structured. At the moment we structure our business classes like this: public class OrderBL { public void ...
1
vote
1answer
97 views

Nested classes in Java

Why is it legal in Java to declare an object of the enclosing class inside the nested class? It cannot be meaningful as enclosing class is not completely defined at the time of the declaration of its ...
1
vote
2answers
69 views

Benefit of not overloading `AbstractCollection.add()` and having `AbstractCollection.addAll()`?

example: public class Something { private Set<String> names = new HashSet(); public void add(String n) { names.add(n); } public void add(Set<String> set) { names.addAll(set); ...
4
votes
2answers
140 views

Store encrypted data in XML

Context I work in the energy domain with devices that send data in clear text over some medium, that finally ends on a computer. The data is there decoded and stored in XML files. A current XML file ...
2
votes
2answers
202 views

Can I alter the code while adding logging?

When I add logging (e.g. log4j2 in Java) to existing code, is it ok (good practice), to alter the code? Consider the following example: //if process returned 0 return true return (returnCode == ...
8
votes
2answers
612 views

Why for-each has colon instead of “in”?

From Java 5 language guide: When you see the colon (:) read it as "in". Why not use in in the first place then? This has been bugging me for years. Because it's inconsistent with the rest of ...
2
votes
2answers
131 views

Refactoring my code that depends on a renamed library method

Say third party library Beautify renames one of their methods from beauty to makeBeautiful because they want the method to be a verb and by some lack of initial planning didn't do this from the start. ...
0
votes
0answers
44 views

Incorporating external web services in Java/Spring web app

With traditional Java/Spring web apps, I've historically used an JEE architecture where there's a domain tier and a web tier. The web tier mostly contains web controllers. The domain tier includes ...
1
vote
0answers
55 views

How to report multiple errors as a result of validation?

I have a class that transforms a complex model, for example an abstract syntax tree or intermediate model. The model can be either valid, invalid or partially invalid, i.e. it contains errors but some ...
0
votes
3answers
271 views

Java constructors confusion? [closed]

public class example { private String one; private String two; public example(String one, String two) { this.one = one; this.two = two; } public static void ...
-5
votes
1answer
60 views

Proper use of break; [closed]

I am trying to establish my POINT value when the sum is equal to 4, 5, 6, 8, 9, 10, but terminal continues to execute my code even after the break;. Can someone please explain why this is happening? ...
13
votes
4answers
6k views

If my IDE is so smart, why do I need to cast “clone()”?

My IDE (NetBeans) type checks my Collections while I am typing code. But then, why do I have to cast the returned object of Object.clone()? Which is fine. No harm no foul. But still, I don't ...
0
votes
2answers
107 views

Spring-MVC : Testing code by automatically running it in UI

I am working on a Spring-MVC application(config XML based, no Main class) in which I would like to do testing. I have known that there is a way to test code which is backend+frontend code. For that, I ...
4
votes
2answers
51 views

Referencing extendable ordinal numbers

I have a class that is basically a container (or composite) of 4 other objects. I'm trying to figure out the "best" way of referring to these objects, while still allowing it to be robust enough, so ...
4
votes
3answers
157 views

Transitioning from C++ multithreading to Java multithreading

In C++, I've been accustomed to using threads in the following way: #include <iostream> #include <thread> #include <mutex> std::mutex m; int i = 0; void ...
7
votes
1answer
101 views

Is the complexity needed to prevent downcasting from constructor to overridden method worth it?

Invoking non-final instance methods in constructors risks downcasting from a constructor to an overridden method as such: public class Start { public static void main(String[] args) { try ...
6
votes
2answers
120 views

Returning Unmodifiable Collections only tees you up for runtime exceptions?

Seeing as how there are no distinct Unmodifiable Collections interfaces, aren't you just setting yourself up for runtime exceptions by returning Unmodifiable Collections from method invocations? ...
3
votes
1answer
163 views

In MVP pattern should the View instantiate a Model object based on UI contents, or just pass these contents as parameters to the Presenter?

I'm using MVP pattern in an android app that I'm developing. I have basically 4 elements: The AddUserView where a new user can be added: The AddUserPresenter The UserInfo (the pojo) The ...
3
votes
1answer
79 views

where to put methods that manipulate objects

I have a controller method as follow: public class RoomsController { @RequestMapping(method = RequestMethod.GET, path="/v1/rooms/{name}") public ResponseEntity<?> ...
7
votes
2answers
102 views

using Integer objects in Java API

I was reviewing a coworker's code, and noticed that he was using Integer objects instead of ints in some APIs (getters, setters, instance variables, and method parameters). When I asked him why, he ...