Questions tagged [java]

Java (not to be confused with JavaScript) is a class-based, object-oriented, strongly typed, reflective language and run-time environment (JRE). Java programs are compiled to bytecode and run in a virtual machine (JVM) enabling a "write once, run anywhere" (WORA) methodology.

Filter by
Sorted by
Tagged with
9
votes
3answers
6k views

Handle Java Process outputs without extra-threads

Usually, people would create two extra-threads in order to read the standard output and error respectively. However, the following code would allow to handle a Process outputs without those threads (...
12
votes
3answers
7k views

Concurrent programming with a simple server

I am creating a simple server that accepts a int and returns the value received twice: ...
12
votes
7answers
9k views

Sieve of Eratosthenes

For practice, I've implemented Sieve of Eratosthenes in Java by thinking about this visual animation. I would like to hear some suggestions for improvements, especially how to make it more efficient ...
3
votes
2answers
6k views

Boolean flags encoded as integer implemented with EnumSet

I'm a beginner in Java so I would appreciate a review of following simple class - in fact it's my first real usage of enums. The background: I'm parsing MySQL internal client-server protocol. One of ...
5
votes
3answers
383 views

Should I design my enumeration in some way that indicates what the highest value is?

This is a subtle question about design in which I want to find the most elegant and appropriate solution. I have an enumeration representing a French card deck (see code below). With it I need to do ...
25
votes
3answers
26k views

Reusing StringBuilder or creating a new one? [closed]

Given that it is better to reuse objects than create new ones when developing with Android, is it worth while deleting the contents of a StringBuilder and reusing ...
1
vote
2answers
5k views

How to delete last element in java.util.Set efficiently?

...
3
votes
2answers
3k views

Extracting Android contact Info

I am new to Android programming and I'm working on an Activity in an app that will plot the location of contacts from a specific email account on to a map. The following is what I in a class that the ...
3
votes
2answers
247 views

Reflecting and counting points on a 2D grid

First number indicates the number of points, followed by N points (x,y). Then the next number indicates Q num_queries, followed by Q queries: Reflect all points between point i and j both ...
2
votes
3answers
903 views

Is this correct java? Attributes and constructors especially

I'm learning java, although because of work I didn't had much time to go to classes. We had a final work to do but since I'm more familiarised with python I'm not sure if I'm doing java correctly... ...
6
votes
2answers
1k views

Integer to String recursive method

I was experimenting with lists, sets, and finally maps when I spotted a pattern in my code to make it recursive. Now I haven't used recursion much in the past or at work and I was very excited to have ...
2
votes
4answers
209 views

looking for OO input , is any of this code good OO or am i doing it all wrong?

Some code im working with for a stock system , i have two ways to do this, looking for review on if any of them are correct and if so which one is better OO than the other ...
3
votes
1answer
3k views

Output strings from a set in lexicographical order

Puzzle Description: You are given 'n' strings w1, w2, ......, wn. Let Si denote the set of strings formed by considering all unique substrings of the string wi. A substring is defined as a ...
4
votes
2answers
943 views

k_diff challenge in Java

Puzzle Description Given \$N\$ numbers, \$N <= 10^5\$, count the total pairs of numbers \$(N_i, N_j)\$ that have a difference of \$K = N_i - N_j\$ where \$0 < K < 10^9\$. Input ...
8
votes
2answers
32k views

Secure AES encryption and decryption in Android [closed]

Is this implementation of AES for Android safe? Is it 128 bit encryption? How can I strengthen this implementation? Please help me, all suggestions are welcome :) ...
6
votes
3answers
3k views

Calculating sum of similarities of strings

Puzzle: For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings "abc" and "abd" ...
3
votes
2answers
4k views

Rot -n algorithm in Java

This is a rot-n (rotate n times) encrypt/decrypt algorithm, where n can be any integer (+/-). It's written to encrypt/decrypt all the alphabets (upper/lower case) and leaving behind all non-alphas. ...
7
votes
3answers
2k views

Review on code for duplicate removal

I am trying to remove duplicates from a string without using additional buffers. This seems to work correct, I think. Can this be improved? Should I be doing it differently? ...
4
votes
7answers
2k views

Reduce repetitive code in Lotto simulator

I'm extremely new to Java, and I had a bit of an attempt at making something that you could call lotto. I've still got a lot more to go on it, but things are becoming tedious, and I am sure there is a ...
4
votes
2answers
349 views

Extracting the five most frequent queries from a log file

I'm trying to print the top 5 most queried strings from a text file. I can't use other third-party libraries to make it easier w.r.t hashmap implementations. I need to improve on these if possible: ...
1
vote
2answers
311 views

Is there a more efficient way of loading views within my java app?

I'm building a web application in Java. I'm new to Java, so before I get too far into this... I'm hoping to take advantage of all the experience here and learn the problems with this setup. My ...
2
votes
3answers
914 views

Permutations Finder Help Number 2

Previous question: Java application for finding permutations efficiently> I have changed quite a bit of code, and need some more reviews. ...
4
votes
5answers
704 views

Synonymiser refactoring

I am interested in seeing how people would refactor this code to make it more readable, remove local variables, etc. The code checks a string against a number of arrays. The first (0) field of each ...
3
votes
2answers
12k views

Queue Implementation

First time I'm using stackexchange. I'm in 8th standard. I tried to implement Queue in Java. I wrote something like this> Right now I'm not able to test it because I don't have JVM in my machine. So I ...
2
votes
1answer
2k views

Converting input from a FileReader to JSON and outputting it again

Below is my code which I use to read data from a remote URL (which is GZipped), convert it to a Map, process the map (remove various unwanted fields, etc), the ...
15
votes
5answers
16k views

Java blocking queue

...
8
votes
1answer
748 views

Java application for finding permutations efficiently

I am an eighth grader with a school project of creating and application in Java that returns the total permutations of two given numbers. It needs to be light and efficient, for later deployment on a ...
2
votes
1answer
149 views

Improvement of this method

I'm coding a small web app with no real functionality. It's like a pilot program for something bigger. What I want is construct a program that works as a clock on/off for a restaurant. Actually I'm ...
8
votes
3answers
1k views

Quick Sort Implementation

I have written the below code for quick sort in Java: ...
19
votes
3answers
75k views

List objects in a Amazon S3 folder without also listing objects in sub folders

I'm using the Amazon S3 Java SDK to fetch a list of files in a (simulated) sub-folder. This code is rather standard (AWSConfiguration is a class that contains a ...
4
votes
2answers
721 views

Reusable configuration reader for Java

This is related to a question I posted on Stack Overflow. The consensus was to use JAXB, which is what I did. One of the requirements was that it needed to work with legacy XML configuration files. ...
6
votes
1answer
122 views

Refactoring code duplication so the same textArea is not used in 4 different classes

Looking for the best way to do this. Currently in 4 different classes I have: ...
3
votes
3answers
244 views

Struggling to refactor code to remove duplication

I really need some help removing some duplicated code. I've linked the methods causing me issues. http://pastebin.com/cZJihM4J As you can see each method does similar things but retrieve different ...
8
votes
3answers
7k views

Check if a binary tree is a subtree of another tree

I am doing a refresher on algorithms. I tried to solve the problem of determining if you have 2 trees (T1 and T2), one is a subtree of the other. I came up with the following: ...
6
votes
1answer
469 views

Database interaction logic

I have a database-intensive app, almost every activity requires access to the database, both reading and writing. I had a lot of problems with separate threads and activities on the stack closing ...
2
votes
1answer
7k views

Text based 2D Minesweeper

I got my 1 dimensional program to work just fine so I figured I just need a few tweaks to get the 2D to work as well. It's not fully completed but it would helpful to know if I am on the right track ...
4
votes
1answer
2k views

Sudoku Solver Optimization

I am currently working on a Sudoku solver that should be able to solve a 25 x 25 grid. However, I am experiencing problems optimizing it to run quick enough to actually get a result with any grid ...
3
votes
1answer
2k views

Game Of Life rewritten into two classes, PetriDish and Cell

Follow-up to: Game Of Life implemented with for-loops and a boolean-array As proposed by palacsint I went on and rewrote my implementation of the Game Of Life and extracted everything into two ...
2
votes
3answers
445 views

What is the security issue in this code?

I was asked how this code has a security risk. Does anyone have any ideas what it is? I am new on the security topic and don't know what to look for. ...
4
votes
2answers
953 views

Listener pattern implementation

In my project, I am doing asynchronous processes in almost every classes. To explain my problem, I have created a sample: ...
3
votes
3answers
8k views

Java console calculator

...
0
votes
1answer
279 views

Unit testing where you depend on implementation of another method [closed]

I am implementing a gap buffer and am trying to write a test for the insert method, the test currently looks something like this: ...
2
votes
2answers
2k views

An object-oriented student record system

I'm after a collection of opinions regarding cohesion and coupling with my application to improve OO programming. Control Class - Populates test data and calls main menu ...
2
votes
1answer
3k views

Game Of Life implemented with for-loops and a boolean-array

There's a Follow-up: Game Of Life rewritten into two classes, PetriDish and Cell I wrote an implementation of the Game Of Life using the easiest approach, a bunch of loops and a boolean array. Yet I ...
4
votes
4answers
361 views

Search module methods

Constructive criticism is required for the 2 methods below. I'm trying to develop better OO skills. ...
46
votes
4answers
9k views

Ternary operation in Java - isn't this abuse?

I think the below code is difficult to understand. I also feel it abuses Java's ternary operator. ...
3
votes
1answer
1k views

Is this proper usage of “safe publication”?

With regards to Safe Publication, consider this piece of code: ...
6
votes
4answers
5k views

Student record system

In particular, I'm not happy with case 5 in the Control class. Basically, in case 5, I would like the user to attach a student from the students array onto a module from the modules array without ...
5
votes
1answer
5k views

Singleton class extending a parent class to utilise shared functionality

I have a singleton class which extends from an abstract java class. Two singleton classes extend from ItemImageThreadManager, the reason for this is to use shared ...
3
votes
2answers
260 views

Switching functionality on and off in a Scheduled Thread

To illustrate how to do leader election with Apache Zookeeper I've created an straightforward application and I would like to have to threading part of the application reviewed. I've created a simple ...