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

7
votes
5answers
710 views

Coding style issue: Should we have functions which take a parameter, modify it, and then RETURN that parameter?

I'm having a bit of a debate with my friend over whether these two practices are merely two sides of the same coin, or whether one is genuinely better. We have a function which takes a parameter, ...
1
vote
3answers
225 views

Including extra headers that I do not really need

I always wondered what are the effects of including not needed headers to the final executable once compiled. In my code some times I may included many different headers that I do not need (or I used ...
0
votes
0answers
8 views

Can't find main class in Java? [migrated]

For some reason that I haven't been able to figure out, the program I've been working on for a while now isn't running. This is the error message I've been getting: All I did between the time it was ...
-2
votes
0answers
17 views

How to change the return message of Exception.getMessage()? [migrated]

I need to change the return message of the method getMessage() , for instance, i have an ArithmeticException, and when i write: try{c=a/0;} catch(ArithmeticException excep){System.out.println( ...
0
votes
0answers
4 views

how to use postgresql in Java [migrated]

I Installed postgresql and its driver which is "postgresql-9.3-1102.jdbc41.jar". And my directory seems like : > SQL > myJDBC.java > postgresql-9.3-1102.jdbc41.jar I have tried : ...
-1
votes
1answer
64 views

Creating a new type of project file [closed]

I'm starting to work on a project where it would be quite useful to have something like a project file that holds all the data being used in a form that can't be opened/modified/used in anything but ...
-1
votes
0answers
11 views

i am trying to sent sms through serial port event listener but i am grtting this error NoSuchPortException [migrated]

Week before this code working perfectly but after formating the system it is giving NoSuchPortException while trying to send sms connect my nokia c3 cell phone via usb error log is as enter code ...
0
votes
0answers
70 views

How to micro-ify the middle tier in a Microservice Oriented Architecture?

Just read Fowler on Microservices and definitely recommend it. A big thing that is missing from this paper/approach is how to decompose the client-tier into "micro apps". By that, here's what I mean: ...
0
votes
1answer
119 views

Which package should unrelated classes belong to in Java? [closed]

In a project, certain related classes can be grouped together in one package. But some other useful classes are not related to any other class and so cannot be put into a package with any other ...
0
votes
2answers
204 views

Why use Creational patterns in Java?

How are Creational patterns useful? Most of the material I came across explains the use case to "solve common problems associated with object creation, improve flexibility". I can think of just two ...
0
votes
0answers
72 views

Java 8 Streams API HAVING clause equivalent in a GroupingBy? [migrated]

I've run into a hard to solve problem in Streams API. Well, it is solvable but not elegantly within a single call from what I can tell. Below, taking a stream of FeatureContentWeight objects, I want ...
0
votes
1answer
68 views

Cleanest choice for symmetric operations

I have a need to do some processing from a format A to a format B and from B to A. The job in one direction is very similar to its counterpart. Both formats are represented with an interface Msg. In ...
1
vote
0answers
46 views

Incorporating custom Algorithm in SOLR-LUCENE , before Indexing?

CURRENT FLOW: I am using a custom algorithm(presently in php) to rank the MYSQL records before INDEXING it to SOLR . WHAT I WANT : Is it possible implementing this ALGORITHM(may be in JAVA) inside ...
2
votes
2answers
104 views

Designing a system to archive databases with referential integrity

I have a very large Oracle database, with many many tables and millions of rows. I need to delete some of the rows end-to-end. By end-to-end, I mean, if I want to delete a row from a table then I must ...
-2
votes
1answer
61 views

Naming of classes [closed]

I am creating an Email sending client. My POJO domain model conssts of 2 string fields, userName and userId. My thought process around designing the classes was to club these 2 fields into a domain ...
-3
votes
3answers
124 views

What programming languages are most suitable for implementing design patterns? [closed]

What programming language is best for implementing design patterns, (Factory , etc) especially for example if I need to develop a engineer scheduling system in less than a month. Would Java be my ...
0
votes
0answers
123 views

How to design multiplayer online game with a battlefield?

I'm designing a simple game where all players use one battlefield via browser. I'm using websockets. So I'm wondering should I always send all data about battlefield to every user when smth is being ...
0
votes
2answers
86 views

Java Streams API Documentation

Currently learning Java so this may be a question resulting from lack of understanding of Java (while also learning Streams API) In the declarations of function I often see two templated types for ...
50
votes
7answers
6k views

Should a getter throw an exception if its object has invalid state?

I often run into this problem, especially in Java, even if I think it's a general OOP issue. That is: raising an exception reveals a design problem. Suppose that I have a class that has a String name ...
-2
votes
0answers
22 views

What is the difference between SDK and API [duplicate]

Few things I know: SDK stands for Software Development Kit and API stands for Application Programming Interface. If you want to develop an application or software you need SDK because it contains ...
-1
votes
0answers
14 views

ACM ICPC how to use PC^2? [migrated]

Yesterday we had a practice on the PC^2 it is the official judge software for the contest but I had a problems with it, my code for the problem is correct and the answer is correct but when I send it ...
2
votes
2answers
95 views

Defensive copy in in the client class or in the service class?

I have one service method that receive parameters as a Map. I will need to add new attributes to this map inside the service. If I pass the original Map object to the parameter instead of a copy, the ...
0
votes
0answers
6 views

How would I compare field values of two Java objects of the same but unknown type recursively? [migrated]

We are parsing XML configuration files with JAXB into Java objects. The XML files are versioned and after loading version 1.0 and 2.0 into objects we would like to compare the two objects of the same ...
2
votes
3answers
405 views

Should one value simpler code over performance when returning multiple values?

I'm too often facing situations where I need to get several types of information from a method. I usually think long and hard to circumvent these situations but I'm thinking it's pointless work that ...
0
votes
0answers
15 views

webdav in jsr268 portal application

We have a web application that we have made portal compatible(JSR 268) using spring. One part that has not been ported across is a WebDav servlet. Is it possible to have a portlet handle WebDav? or ...
2
votes
0answers
91 views

Java Memory Management - java web start “Error: could not create the java virtual machine” [migrated]

I have defined a jnlp file with initial-heap-size="512m" max-heap-size="1024m" on a machine that has 16Gb with 12Gb available. The JVM running is a 32-bit JVM because of native libraries. I ...
0
votes
1answer
76 views

Algorithm to create custom ConcurrentHashMap?

I tried to look into concurrent HashMap source code to look in to how it is implemented. To me it looked very difficult to understand((In no way i am saying its not required :))). I thought if i need ...
0
votes
0answers
64 views

Strange result from perlin noise generator [migrated]

I have been experimenting with perlin noie generation for a game i want to program but i have run into some strange results. When i let my code run and draw the result in grayscale i get the following ...
4
votes
0answers
125 views

How to get a one-way hash function that is collision safe for about 1 million unique inputs? [duplicate]

Forgive me if this is a noob question - My CS education is a somewhat incomplete Basically, I need a way to hash an input, so that someone seeing the output doesn't see the original input value. ...
0
votes
1answer
79 views

Debugging xml and annotations

By now, most web containers have an annotation variant of their xml configurations for Java EE. I'm guessing this is because it's better to keep things in Java where they can be managed, coded with ...
0
votes
0answers
4 views

Programming in Debug context in Eclipse IDE [migrated]

Is there a way to program (Java), I mean, write some piece of code anywhere in IDE, to evaluate something in the current debug context when the program execution is waiting on some debug point in an ...
0
votes
1answer
188 views

How to spawn multiple “monsters” from a single class [closed]

How to spawn multiple "monsters" from a single class? Can store it in an array, ok, but later on, how can I paint it? Because if I do: enemy = new Enemy(); enemy2 = new Enemy(); I create two ...
17
votes
7answers
2k views

What can one do to improve readability of math-oriented code in C#, Java, and similar? [closed]

As both a C programmer and a C# programmer, one of the things I don't like about C# is how verbose math functions are. Every time you would have to use a Sin, cosine, or power function for example, ...
1
vote
3answers
321 views

Pluggable UI Components in Java Web Applications

I will try to explain my question with an example. Let us say that we are writing a hotel reservation system which is web based using Java. We will have different payment methods, say Paypal, Master ...
1
vote
3answers
219 views

Implements > extends, but what about variables?

It's preferable to write programs that depend on interfaces rather than on superclasses, but what when you want a class to have certain variables? Sometimes you want a class to implement a certain ...
0
votes
2answers
129 views

Should I have an object as attribute or primitive id? [duplicate]

I am wondering which principle should I use. Here is my situation. I have a class named TravelOffer. This class looks like this: public class TravelOffer { private final long id; private ...
1
vote
1answer
89 views

Best approach to a defined datastructure

I have a plain text file with some data that I can't change, so I have to create a datastructure to use in reading the file and with that datastructure do some thousands of interactions. The file ...
-1
votes
1answer
61 views

Inheritance vs Association in this example

I'm designing a very simple fixed asset management system in Java. The system consists of the following entities as displayed in the following ER diagram. My problem is the design approach to be ...
0
votes
2answers
242 views

What type of structure is this in java?

I was reading the following code listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) ...
2
votes
1answer
140 views

CopyOnWriteArrayList: Why do we have to make a full copy of source data?

I have a lot of confusion about Java's CopyOnWriteArrayist. I know, when we have a modification on it like update, insert of set, it will lock the whole list, copy out a total copy of the source list, ...
1
vote
4answers
387 views

Should all programmers know how to solve algorithms, etc [closed]

I'm 15 and have been programming for about 3-4 years. I mostly program in Java as it was my first language. I would like to be a programmer when I'm older, but I'm not sure about the differences. ...
-3
votes
1answer
52 views

Java Licenses, GPL, GNU Questions

I would like to ask a few questions about software licenses, with regards to a (Java) program I am making. I am very very new to licenses, so please bear with me. 1. If I produce a Java program using ...
0
votes
0answers
31 views

Java API initialization step

I am developing an Android Library which involves both Network and Bluetooth communication. In order to start using the library it must be configured. In other words a request to the backend must be ...
0
votes
1answer
219 views

Separating UI from logic

I'm trying to develop a little game and for this I'd like to separate the UI from the game logic. So I'm thinking of using an "Animator" class that will be responsible for rendering the objects, but ...
1
vote
2answers
147 views

Ensure scheduled event only runs once a day?

In a hobby project of mine, a "smart home" for controlling lights, I'm planning to create a feature which turns off all lights at a given time of day. There are also several other features which runs ...
2
votes
1answer
77 views

Is there a limitation when using the Bloch's Builder Pattern with mandatory fields?

Background I have a class TextDrawable which draws text on top of a shape. There are a number of properties that can be set while creating a TextDrawable object. Mandatory Properties: Text Shape ...
1
vote
1answer
132 views

Best OOP pattern to use for creating a commandline SQL API for a proprietary json based company datastore

We need to create a SQL commandline tool for querying a proprietary json based datastore. I'll be using java. Any suggestions on the primary OOP design pattern I should use for building this API? ...
0
votes
1answer
83 views

when would you wrap a service object with an interface? [duplicate]

I'm new to UT and some of the best practices and anti-patterns when writing testable code, made me think. I used to wrap any service object with interface. but I see many mocking frameworks can ...
0
votes
0answers
54 views

when would you write static method as it avoid a “seam” for testing [duplicate]

when would you write static method. I used to write it in utils classes where all the methods are static and work state-lessly on arguments only. But now I know it blocks from creating a seam in ...
0
votes
2answers
136 views

Java Multithreading and CPU cores [closed]

I have a simple question this time. If I write an java application with 4 Threads ( each thread does different work ), what will be the difference between single-core, dual core and quad core cpu ( ...