Tagged Questions
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.
-4
votes
1answer
21 views
Launch vnc (tightvnc) viewer from a program [on hold]
So my company has a little over 200 computers we manage. They are all with in the same net work but on different IP sachems, how ever we are able to network with everyone.
What i would like to do i ...
-3
votes
0answers
19 views
What method exactly creates line in linechart javafx?
I still couldn't figure out what step actually creates line in linechart of javafx. Is it that xychart.series object itself a line object? Or is that lineChart.getData().add() step adds line? What i ...
5
votes
2answers
278 views
Is an interface with only getters a code smell?
(I've seen this question, but the first answer goes about auto properties more than about design, and the second one says hide the data storage code from the consumer, which I'm not sure is what I ...
1
vote
0answers
77 views
License issues of 3rd-party libraries that is not used directly [on hold]
I have a question about licenses of non-direct 3rd-party library usages. I'm using one of the Java's javax libraries. It turns out that this javax library uses an LGPL licensed 3rd-party library ...
0
votes
0answers
48 views
+100
Using an online data download and streaming API: Java/Scala client design
I've started working with scala.concurrent and Akka and would to start using them in my client programs. The client programs use a 3rd-party Java API which can download data and stream data. (The ...
1
vote
2answers
77 views
Unit tests for constructors
If I make a class, that in the constructor accepts an array or collection, but this array or collection is optional (the parameter can be null), and then I store that collection in the object in ...
2
votes
1answer
126 views
Is mixing Builders and Factory pattern a good idea?
I have an object Carconstructed using builder pattern.
Issue was a lot of code redundancy.
Car.Builder builder = new Car.Builder("Mercedes");
builder.numDoors(carConfig.getNumDoors()
...
39
votes
4answers
4k views
Is using Lambda expressions whenever possible in java good practice?
I have recently mastered the Lambda expression that was introduced in java 8. I find that whenever I am using a functional interface, I tend to always use a Lambda expression instead of creating a ...
-3
votes
1answer
62 views
The best way to structure a Java class [closed]
In order to make Java code easier to read we better have an agreed upon methodology on how to structure a class (where to put member fields, statics, methods, inner classes, etc.).
It seems there ...
2
votes
1answer
129 views
Is it bad practice to perform an “optional” interface inheritance?
Say... you're trying to write a networkCallback code in java:
public interface NetworkCallback {
void onNetworkResult1(Object object);
void onNetworkFailure(Object object);
}
you want to use ...
0
votes
1answer
62 views
Web application Architecture for real time app
Usecase: End user places an order on company website, the order needs to be pushed to company admin's screen with small latency.The company has multiple branches(identified by compId and branchId ...
0
votes
1answer
111 views
Migrate from an architecture to another [closed]
I have an existing Java architecture that uses a basic proprietary framework.
I want to start developing new functionalities in a framework, ex Play.
In that way I will not lose existing ...
-2
votes
0answers
35 views
Implementing Subscription and Recurring Payments using PayPal [on hold]
I am trying to use PayPal to get recurring payments in our IPTV website. The requirements are as follows:
Recurring Subscription
Cancel Subscription from our Dashboard
If possible, fixed fee ...
3
votes
4answers
119 views
Initializing objects in Constructor
I have below constructor, where it creates a workbook in constructor. I read that, ideally, we should not create objects in Constructor, instead, we should have just assignments which are passed.
...
9
votes
2answers
440 views
Avoid getters and setters, displaying user informations
Background
I m reading the "Clean Code book", and, in paralel, I m working on calisthenic objects Kata like the banker account, and I m stuck on that rule :
The 9th rule of calisthenic objects is ...
3
votes
1answer
129 views
Is it always optimal to preserve encapsulation in MVC?
I've just finished up a project in which I created a visual simulation of the life cycle of an ARM instruction in a single cycle processor. I used the MVC pattern in this project and ran into a design ...
1
vote
1answer
92 views
Why is a servlet more efficient than CGI?
I have been doing some research in to java servlets and I am having trouble understanding why it more efficient then a cgi based solution.
The reason for my lack of understanding is that java ...
3
votes
2answers
85 views
Static per-enum data: constructor, set in initialiser or override getter?
I have an enum with > 10 items each having 8 static properties. Contrived example:
enum JavaTypes {
INTEGER,
BOOLEAN,
STRING,
...;
boolean isPrimitive() {
}
boolean ...
0
votes
0answers
81 views
Migrating to Java 8: How can I scan the project and report that an expression can be replaced with a lambda equivalent?
There is a current project which has many lines of code and written for Java 6-7. I want to migrate it to Java 8 and use lambda expressions wherever I can.
How can i scan the project and report that ...
1
vote
0answers
20 views
How should I optimize my RecyclerAdapter (Android) to maximize efficiency of information retrieval in my app's data feed?
I was wondering if there were a set of standards or best practices for displaying information in lists for mobile applications (specifically Android applications that utilize RecyclerViews and custom ...
-3
votes
1answer
45 views
Backtracking algorithm with backtrack step [closed]
i have a problem where:
Having a char matrix[n][6] where in each position could be whatever [a-z] char i should say if exists a given string of n length with the restriction of couldn't use same row ...
4
votes
2answers
133 views
A multi-processing approach to listing the occurrences of words in a text file
A classical problem: read the words from a text file and list the occurence of each unique word in the file.
I solved the problem using a hash map, but how could the performance be improved? I ...
0
votes
2answers
74 views
Java Interfaces in Layers pattern
I'm developing a Java software according to the object-oriented Layers architectural pattern. Every layer should be clearly separated from the rest, and provide a well-defined interface to use it's ...
9
votes
4answers
267 views
Fetching a value without having to null check in Java
Many times I find myself null checking when fetching a value from some data hierarchy to avoid NullPointerExceptions, which I find to be prone to errors and a needs a lot of boilerplate.
I've written ...
5
votes
1answer
156 views
How to implement the MVC design pattern with JavaFX written in pure Java
I am currently in middle of designing a backup application in JavaFX written in pure Java (meaning without Fxml) .
I am having trouble implementing the MVC pattern for the following reason. The way I ...
0
votes
5answers
108 views
How to deal with IOException when file to be opened already checked for existence?
This is a specific question here, but I'm interested in the general "best practice" for similar situations as I'm new to Java.
Suppose I have Java code that needs to open a file (see below for code). ...
1
vote
1answer
115 views
Is it correct to think of a Java Interface as a “contract” that a class must implement?
I just want to check that my current understanding of Java interfaces is correct.
If an interface says it must include public void increase(int amount), then does that just mean the class that ...
-2
votes
0answers
62 views
Local Json file parsing in android [closed]
I have a set of json files kept in sd-card which are downloaded from the server(around 40 json files). I have to parse it and insert it to the sqlite db. My concern is about using the method for ...
6
votes
4answers
1k views
Why aren't OOP design patterns included in the standard libraries?
I have a question similar to this other question
Why aren't design patterns added to the languages constructs?
Why isn't there java.util.Singleton and then we inherit it? The boilerplate code ...
1
vote
1answer
111 views
Can the has-a relation in OOP become ambiguous or difficult to know?
Assume I have the following code.
class D { static Integer i1 = 42; }
Is it true that D has an Integer? Or is it only for instance variable that we can have a has-a relation?
I also wonder about ...
2
votes
0answers
71 views
Composite and Observer pattern implementation
I'm learning Composite and Observer design patterns and I have created a FileSystem class where I define Node, Folder and File as a composite relationship. Now I want to implement Observer pattern so ...
0
votes
2answers
159 views
Why is the dot illegal in a Java identifier?
We know some of this syntax won't compile, specifically the line where I'm explicitly referring to the class name for a variable.
class Main {
static String Main.s1 ="output"; //won't compile
...
0
votes
0answers
32 views
Aggregate functions in DAO
I have some simple Domain Model which describes persons table in db:
@Entity
@Table(name = "persons")
public class Person {
private int id;
private String firstName;
private String lastName;
private ...
0
votes
0answers
46 views
What problem is solved in Java with equals() and hashCode()? [duplicate]
I learnt about hashCode and equals in Java and their uses and contracts. I'm trying to understand why we do it this way and why they simply are not the same.
IIUC, the reason is a technical ...
0
votes
0answers
31 views
Java desktop-application with global administrative settings
I'm currently working on a java application, which will be running on several desktop-pcs, but with a common database. The purpose of the application is to make reservations for hardware, so people ...
1
vote
4answers
314 views
Why doesn't java allow multiple inheritance of classes when it allows multiple inheritance of interfaces? [duplicate]
I am currently perusing through Jdk 8 and I came across the feature where you have multiple interfaces that overlap with the same method signature for a default method, the compiler will throw an ...
-5
votes
2answers
200 views
Why are interfaces in Java called that way?
I have been a developer for past 3 years and I have been seeing interface in most of the places as a contract for the developers to write their own implementation or a marker (eg. Serializable). But ...
0
votes
0answers
10 views
Helper methods for JUnits logic [duplicate]
I've found a lot about creating JUnits for helper methods, where a "helper method" means usually a non-public method of a class.
I would like to ask the same question but in different context. A "...
3
votes
4answers
208 views
Can someone explain the technicalities of MapReduce in layman's terms?
When people talk about MapReduce you think about Google and Hadoop. But what is MapReduce itself? How does it work? I came across this blog post that tries to explain just MapReduce without Hadoop, ...
6
votes
2answers
138 views
What the fastest way to pass large data between JVMs?
I have 2 JVMs on the same machine that I want to pass about 1Mb of (serializable) data between ideally in under 5 ms.
Under load, using HTTP to localhost takes about 70ms average.
I tried hazelcast, ...
3
votes
4answers
470 views
How does Java improve over C++ in the area of portability?
I was reading through a Java book by author Herbert Schildt and he writes how the advantage of Java over C++ in portabilaty is that while C++ can be run anywhere, it still requires each program to be ...
0
votes
3answers
160 views
How to write a proper class to connect to database in Java
I'm currently writing an application and I'm struggling with the decision of how to correctly design a class to connect to a database. I came up with something like this:
public class ...
1
vote
0answers
42 views
Allowing users to add their own custom fields in a Spring MVC Hibernate application - What's an ideal approach?
We all may have seen applications like JIRA, or many CRM or other applications that allow its users to define their own custom fields to an entity, and do a variety of stuff with it, like making them ...
0
votes
1answer
108 views
Transaction handling in DAO or Service layer in pure JDBC without frameworks
I have an application which works with pure JDBC. I have a dilemma where should transaction handling go, in Service or DAO layer. I have found that in most cases it should be implemented in Service ...
1
vote
2answers
62 views
Modeling Composite Design Pattern
I'm using Java Eclipse EMF to model my Composite Pattern. What would be the right UML representation to model aa new class (Root) which implements a unique root directory. This is the original ...
2
votes
1answer
99 views
Swift-like extensions in Java using inheritance
After picking up some Swift skills with Java as my strongest language, one feature of Swift that I really like is the ability to add extensions to a class. In Java, a pattern I see very often is ...
0
votes
1answer
151 views
Does my file system implemented using the Composite pattern require a singleton?
I'm exploring composite pattern to write a file system, one of my requirements is to create a unique root element in this case a directory, similar to Linux System ('/'), I have seen many examples of ...
21
votes
5answers
3k views
Should non-trivial conditional statements be moved to the initialization section of loops?
I got this idea from this question on stackoverflow.com
The following pattern is common:
final x = 10;//whatever constant value
for(int i = 0; i < Math.floor(Math.sqrt(x)) + 1; i++) {
//...do ...
3
votes
2answers
97 views
Pattern for a method call outcome
Most often I need to call a service method from a controller, and based on the outcome, if there's an error show an appropriate error message depending on the error (or some other action, showing ...
0
votes
0answers
19 views
Implementing Data Type Independent User Set Values
I'm trying to set up a very simple user defined variables that can be set in an administration panel and used in the system. Our application is going in the direction of configuration over custom ...