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

1
vote
0answers
63 views

Java MVC: multiple use of the same event for different actions

I am working on a large Java project which employs the model-view-controller pattern. Should I use a different event for each action (to let the views communicate with their respective controllers)? ...
0
votes
1answer
48 views

Is there an established pattern for associating a database entry with a Java class that executes on that data?

I have a behavior tree with different leaf nodes that execute tasks. When building out the tree relationship in the database I need an association between the leaf node entry and the Java class that ...
0
votes
1answer
62 views

Architecture question about data migration

I'm facing a new enterprise project in Java about data migration. I did one of them in the past, now I want to do a better work and I think I need your considerations. So, let's me explain the ...
-3
votes
1answer
64 views

How should I change in get method without calling getList() of Deque? [closed]

import java.util.List; import java.util.ArrayList; public class Test { /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { ...
1
vote
2answers
140 views

Is it better to perform a calculation in the field's setter or have a different method?

I'm implementing a simple Quota object which determines a usage percentage based on the maximum and the used. private int maximum; private int used; public Quota(int used, int maximum) { ...
0
votes
1answer
115 views

Enum as singleton or fully functional class [duplicate]

Joshua Bloch claims that "a single-element enumeration type is the best way to implement a singleton" Why? I totally disagree with this statement because enumeration is data type with some ...
0
votes
1answer
119 views

Should I use one class that calls Several static methods or several classes each calling one static method

I need to use instances which represent mathematical functions along with their parameters end enable their evaluation. I can take 2 approaches: 1: have a single class representing all the math ...
1
vote
0answers
38 views

Individual methods or parameters for Google Analytics abstraction on Android

A coworker and I are having a discussion around the best way to build our abstraction on top of Google Analytics for an Android application. A couple of data points. We have auto-tracking enabled ...
-4
votes
1answer
148 views

it is possible to implement keyloggers in java [closed]

I am researching on keyloggers and as a part of my research I would like to know if its possible to implement keyloggers in java edit * How can i create a keylogger in java or to be precise what ...
1
vote
2answers
205 views

How to add rigor to my testing?

I work on a small/medium sized Java application. Over time, I've tried to ensure that the tests which I write are "good" tests, and that there's plenty of them. Hence I've been looking into various, ...
0
votes
2answers
120 views

Printing to out vs Logging, given the nature of this app?

I'm writing a command line application in Java. That app will scan a list of remote resources, do several attempts to access those resources, report failed attempts, and if succesfully accesed, ...
0
votes
1answer
149 views

Implementing a NoSQL and RDBMS compatible DAO

What would be the correct way to design a DAO which implementation is first going to be targeting a MS SQL database with a STAR model, but yet, business requirements specify the application must be ...
0
votes
2answers
110 views

Classic ASP to Java UI Conversion

My question is based on a business model of a financial services organization that currently is supporting applications that are a hybrid mix of Classic ASP and Java, with some JSP’s already in some ...
0
votes
2answers
217 views

Saving to file before storing into a database in a REST service

A mobile back-end I am building should receive a larger amount of data (some sensor recordings) from an Android phone. The phone does not have much use of it so it was most efficient to store the data ...
1
vote
1answer
126 views

Automatic Type Promotion in JAVA

I have started studying JAVA . In there, byte ch=50; ch*=2; works fine. But byte ch=50; ch=ch*2; does not. error:possible loss of precision required:byte found:int Why this do not happen ...
13
votes
7answers
2k views

Is there a pattern for a more “natural” way of adding items to collections? [closed]

I think the most common way of adding something to a collection is to use some kind of Add method that a collection provides: class Item {} var items = new List<Item>(); items.Add(new ...
1
vote
4answers
174 views

Options for constructing an object that is not logically initialized until all fields are set

I am working on a Pokemon game at the moment, and am running into some design concerns. The easiest example is as follows: Each Species of Pokemon has several traits that are required before it is ...
3
votes
3answers
485 views

Should I try it straight or should I first check if it can be done?

I have a set of items, and each item in the set must be unique. Item are composed from multiple properties and each property of each item can be changed. But after each change every item in the set ...
1
vote
2answers
94 views

Java applets with Safari on Windows as compared to Safari on OS X [closed]

I have a developed an Applet which works fine on Chrome/IE/FF on Windows. I am not expecting any users for Safari on Windows but there might be the odd user who may be on a Mac. As of now, I don't ...
3
votes
4answers
429 views

Are `switch` statements generally used wrong? [closed]

I see most developers using switch statements with breaks in each and every case. Is this usage of switch statements inappropriate since a simple set of if-else statements would suffice? Is it OK for ...
0
votes
1answer
109 views

How to make my program do something when an errors pops up instead of crashing?

Basically i'm writing a game in Java where i want the program to tell the user that he can't move right or left if that move will cause the player to move out of the array, which means this: ...
0
votes
3answers
152 views

Should I be extracting strings from source in core java the way android does?

I just started doing android development stuff after getting pretty comfortable with Java. Android apps tend to do this weird thing where they have all strings for their program held in an XML file ...
0
votes
1answer
131 views

ActiveRecord equivalent in Java [closed]

My question is fairly simple.. What is the closest ORM to ActiveRecord that I'd be able to find for Java? In other words, in terms of thinking patterns and knowledge, with limted development time, ...
2
votes
3answers
167 views

Good or bad idea to create a “fromJSON” static factory constructor for an object that is often created by parsing a JSON coming from API?

I have a "Product" POJO class in my app. A Product object can either be created in-app by the user or by parsing a json that comes from the API. Product has 20+ fields, but Im using only 2 here for ...
1
vote
1answer
169 views

Adding a graphical view to a system

I currently have an program in Java that simulates railway movements. Essentially, trains arrive on platforms, pick up and drop off passengers, and then proceed, respecting signalling where possible. ...
4
votes
5answers
506 views

Should I create a single object for a common method call or use a throw away approach?

I'm creating a little rpg fight program just for fun and to practice my java (I'm pretty new hehe). I have a class called Dice with a method called d20 that rolls a random number between 1 and 20. ...
1
vote
0answers
141 views

How to separate out below tightly coupled classes

I have two classes which are somewhat tightly coupled to one another. Lets call them A and B. A derives from C and B derives from D. B is the class whose instance is created by the system and then B ...
0
votes
4answers
256 views

Identifying user of a webapp

For a small webapp I want to be able to identify a user. The issue is, if the user cheats in some manner, I want to be able to forbid him the usage of my application. I already have done extensive ...
1
vote
3answers
158 views

Limiting complexity in JPA programs Java/Hibernate

I've been working on a new application for some months now. It's my first big JPA program, and is still in the early stages. However, the complexity of my JPA object tree is becoming a growing ...
2
votes
1answer
121 views

How to randomly get or find a sub-tree (include root node) from a given tree that contains n leaf-nodes

I have a non-binary tree. I want to randomly find a "sub-trees" that are connected from root to leaf which must have at least n leaf-nodes (leaf-nodes of sub-tree must be leaf-nodes of given tree). ...
0
votes
1answer
113 views

Controlling concurrency by Thread Pool in scenario of CPU-intensive and I/O intensive requests?

My goal is to understand how to handle jobs coming from the client side at very high frequency each job is either CPU-intensive or I/O intensive, but both types of jobs are continuously arriving at my ...
3
votes
2answers
224 views

How should blank/empty value objects be instantiated/structured?

I was wondering... what is considered the best practice to instantiate blank value objects? (in Java) E.g. Assume we have some value object class Foo, that could be blank. Would creating methods ...
12
votes
2answers
568 views

Taming the 'utility functions' classes

In our Java codebase I keep seeing the following pattern: /** This is a stateless utility class that groups useful foo-related operations, often with side effects. */ public class FooUtil { ...
1
vote
1answer
226 views

Is this database design good? What JPA Entities should I create for this design?

I am trying my hands on JPA. For this I am thinking of using the example of a student admission process as shown in the diagram below. Is this design good ? Any suggestions for improvement are ...
0
votes
1answer
96 views

Bootstrap licence free template

I´m creating a new website. For that I´m using a free bootstrap template. On top of my index page I have: A Design by W3layouts Author: W3layout Author URL: http://w3layouts.com License: ...
0
votes
1answer
118 views

Where would be better to handle an exception?

Imagine I have the following DAO method: public Employee getEmployeeById(Integer id){ NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(getJdbcTemplate()); String sql = ...
0
votes
1answer
169 views

What kind of reputation does Java 8 have among “enterprise” companies? [closed]

Are the new, functionally-inspired features of Java 8 well-regarded within the enterprise development community? Have they been adopted by large companies? Have coding standards been updated to ...
2
votes
2answers
249 views

Is using generics to indicate some class/method is aware of a type good idea?

I'm going to use Java for code/idea demonstration. Imagine it's needed to define two interfaces: Observer and Observable (observer pattern). It's a good idea to have two generic interfaces, so there ...
21
votes
8answers
3k views

Is there a conventional way to combine file path strings?

In an example: var assets = "images/" var sounds = assets+"sounds/" Is it more conventional to put the slash on the back of a file path? var assets = "/images" var sounds = assets+"/sounds" Is ...
1
vote
4answers
209 views

Adding values to HashMap

I want to add values to a HashMap, which would be used by methods in the same class. I have two solutions: Adding all the values with static When the first method is called, add the values ...
2
votes
4answers
234 views

Range of values based on key values

I'm trying to implement a method of searching trough a large amount of 2D points for those that match a certain range. I'm thinking of creating HashMaps for <X, Point> and <Y, Point> but ...
2
votes
1answer
133 views

How to access secure web services from a desktop application?

I'm writing a Java desktop application that will be available to the public. It will contact backend APIs via HTTPS using Jersey client. I don't know anything about using certificates in desktop apps ...
24
votes
9answers
3k views

What is different between the internal design of Java and C++ that lets C++ have multiple inheritance? [duplicate]

It's drilled into the newbie Java programmers that Java (pre-Java 8) has no multiple class inheritance, and only multiple interface inheritance, because otherwise you run into diamond inheritance ...
2
votes
3answers
205 views

Declaring lambdas in Java8

What would be the best practice to declare lambdas in Java8 code? How it was designed to be used? For example, let's say that we have a method that accept a Function. I want to provide function ...
0
votes
1answer
434 views

String[] args vs (String . . . args)

When programming for android, whenever I use an AsyncTask the doInBackground method looks like this. protected String doInBackground(String... args) But when using the arguments anywhere in that ...
10
votes
1answer
430 views

Efficient way to represent hexagonal board logic for abalone-like games

I have to implement the AI for Abalone game and I'm wondering what is the best way to represent the board logic using Java without wasting too much resources in all checks and updates routines ...
6
votes
3answers
335 views

Design solution for communicating between multiple layers

We are developing a framework that has several layers and would be deployed in a multi-threaded environment. Each layer may have its own input/output data type. The top layer takes the input, performs ...
1
vote
1answer
74 views

excute Vs excuteOnExecutor [closed]

There are two ways to execute AsynTask, i.e., execute and executeOnExecutor. I already know that execute works serially and executeOnExecutor works in parallel. So my question is: Which one to use? ...
2
votes
3answers
161 views

Design a Queuing Solution with Clustering and Multiple Consumers

It is a Design Problem which I am listing out here. I have different set of business operations that are carried out for different business entities. Operations: Operation A Operation B Operation ...
1
vote
2answers
111 views

JUnit3 and JUnit4 in the same project (but different module)? [closed]

I have an Android project with a Gradle build. We've decided to commit to writing a vanilla Java implementation of our business logic (since we took care to keep that divorced form the Android ...