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
2
votes
1answer
101 views

Implementing logic in a different way

I need to write a function which will do the following functionalities I would get a string and a array as input parameters The string would be like one of the following for example ...
10
votes
2answers
4k views

Safely accepting a known SSL certificate with a different host name

My app communicates with a server over an internal network through HTTPS. The SSL certificate on this server is listed for the host as its external host name. I want to accept this certificate, but I ...
3
votes
0answers
460 views

Rhino helper class to support ECMA-262 regular expressions

This is a sample class using Rhino (1.7R4). I need it because in the context of JSON Schema, regexes should be ECMA 262. One requirement is that it is thread safe, and it is. But I'm not sure I ...
4
votes
1answer
1k views

BlockingQueue Implemetation using ReentrantLock

I was writing my own implementation of BlockingQueue for practice. I am trying to avoid using the synchronized keyword for the methods. I would instead like to use ReentrantLock. What is the best way ...
2
votes
2answers
527 views

Minesweeper clone using Swing

I'm coding a Minesweeper clone using Java and Swing. For my current knowledge, I manage to keep it working but two things are giving me nightmares. Namely, I have a VERY repetitive code so I suppose ...
1
vote
3answers
1k views

Java Exception Message

I have a few custom exception classes that I created simply for the sake of having my own exception message: ...
1
vote
1answer
3k views

Implementing the midpoint displacement algorithm in Java

Thanks for taking the time to read this first off. I want to say that I have always been very interested in generating random terrain and since I'm new to any sort of graphical programming, I decided ...
2
votes
1answer
1k views

Finding the max subset of non-overlapping intervals

How could this code become cleaner? I think that the way I handle the interfaces and binary search could be improved. I am trying to understand how to structure such a code (and usage of APIs) in a ...
2
votes
2answers
5k views

Four basic Java exercises - what should have been done better? [closed]

So I would be very grateful if you could check these four tasks - I'm a Java newbie and recently coded such things on a Introduction to CS test which I didn't score so well at and would love to know ...
2
votes
1answer
1k views

Count the number of cyclic words in an input

Cyclic Words Problem Statement We can think of a cyclic word as a word written in a circle. To represent a cyclic word, we choose an arbitrary starting position and read the characters in ...
1
vote
2answers
177 views

Repetitive code for different Database Entities with same implementation

I have this code in LogInService ...
4
votes
2answers
308 views

Shortening System.out - which is better? [closed]

Oftentimes people will shorten System.out to just out and make an analog called in (e.g. <...
3
votes
2answers
1k views

Code to redirect console IO to strings

This code allows calling a method while redirecting the IO to strings. This is useful for unit testing where you have to direct something to the console or examine output that comes from it. I ...
2
votes
1answer
2k views

Sorting parallel ArrayList

I have a model class that contains 3 ArrayList which are in order by parallel of the same size. ...
1
vote
1answer
292 views

Displaying plotted data in serpentine order

I have to display some set of: Data in serpentine order. In an experiment there are replication, range, and plot. Replications contains range a plot. A range contains a plot. If there are 2 ...
2
votes
5answers
133 views
3
votes
3answers
2k views

Classes for a small space invaders game

Below are some of the classes I have written for a small space invaders game. It's not finished but it's at the bare bones stage. I am still learning how to properly use the Slick2D library. I know ...
2
votes
3answers
9k views

Slicing up an image into rows and columns in Java

I have created some code in Java that slices up an image into rows and columns and then saves each image to the file system. This works but there are some improvements I would like to make I would ...
2
votes
1answer
272 views

Generated code proxy

In my library Transfuse I use a code generator to build a handful of classes that look up resources. Each of these look up classes are proxied by a static utility class so they may be referenced ...
6
votes
3answers
2k views

A scala implementation of the Java trim method

I'm a Scala beginner and looking at the trim() method of the Java API. I noticed side effects, so I attempted to implement a functional version in Scala. Here is ...
2
votes
4answers
9k views

Faster way to determine largest prime factor

Project Euler problem 3 asks: What is the largest prime factor of the number 600851475143? The first step I took is to determine the highest value number I should be looking at as a possibility (...
3
votes
2answers
137 views

String Building

Before, I had this code, sometimes it is longer: ...
1
vote
2answers
2k views

InterviewStreet Triplet optimization

I came up with a solution for the InterviewStreet problem "Triplet" In short, there is an integer array d which does not contain more than two elements of the same value. How many distinct ascending ...
5
votes
3answers
153 views

Conditional execution based on input string's prefix

I have this method that basically takes a string and does different things depending on what the string starts with. Is there a cleaner way to write this method? ...
1
vote
2answers
166 views

Review code for optimization and implementation

The below code does Read csv files and process it to do some sort of cacluations.This is more of small picture code , to introduce big picture. The csv file contains information of seeds of crop which ...
1
vote
1answer
2k views

Partition a linked list arround an element

This is my code to partition a list into two parts according to a value. I.e. nodes smaller than value x should precede nodes larger than the value ...
6
votes
3answers
2k views

Java - How to represent the result of an operation

Introduction In my Java application, I need to represent the result of an operation. This can either be OK or ERROR + an error message. Background I have a class to verify the integrity of a ...
2
votes
2answers
3k views

Enormous Input Test - reducing program runtime

This is my solution to SPOJ Problem 442. How can I make this code run faster? What are some techniques that can be used to make this faster? I am getting a Time Limit Exceed Error here. ...
3
votes
1answer
949 views

Returning Binary Search Tree Nodes in Zig Zag manner

I tried to implement an answer for the algorithm question given below. I implemented two different solutions. I couldn't decide which one is better. ( Maybe none ) Note: Node class and ZigZag ...
5
votes
4answers
34k views

Comparing two Strings which could be null or blank in a Comparator

I would like a review of how I am comparing two java.util.String in a private method in a java.util.Comparator. Either of the <...
6
votes
3answers
4k views

Converting Arabic numerals to Roman numerals

These classes are part of a program I am working on to convert Arabic numerals to Roman numerals and vice-versa. Do these classes look correct for representing objects in Java? ...
6
votes
1answer
419 views

Circular dependencies between immutable objects; the Freeze Pattern

Generally, I structure small threadsafe immutable objects like this: ...
2
votes
1answer
583 views

Ogg audio format conversion classes

This is my command interface: public interface IConverter { void convert(); } This is my Receiver class: ...
5
votes
2answers
13k views

Converting audio to different file formats

I have this code that converts audio to different file formats: ...
1
vote
2answers
534 views

Collection-like classes in Java - taking advantage of varargs

I quite often need to implement collection-like classes and - to make using them more comfortable - would like to take advantage of a constructor with variable arguments. The following implementation ...
2
votes
1answer
170 views

Expanding a synchronous grammar

Background: A synchronous grammar is a like two context-free grammars connected in parallel. It is used for translation. For example, here is a small synchronous grammar that can be used for ...
4
votes
3answers
16k views

Minesweeper Code

I created some code for Minesweeper but I need help going over it. I would like if someone could go over it and point out anything (repeating code, code being called multiple times when not needed, ...
3
votes
1answer
4k views

Recursion and iteration how can i optimize this code

I have written some code which will fetch contents from a resource which is actually stored in a tree format. Since it is in a tree format, there will be a parent-child relation and hence recursion. ...
3
votes
2answers
4k views

Random Prime generator

I have this method that will give a random prime for a given range (min inclusive an max not inclusive) all comments are welcome: ...
1
vote
1answer
2k views

Recursion to map phone number to strings

I am trying to solve the following via recursion: In a phone we have each digit mapped to a number. Example: ...
2
votes
2answers
3k views

Lock-Free Ring Implementation

I am wondering if someone can take a look at my lock-free, circular ring implementation which I use to implement a background logger. The CircularRing pre-...
28
votes
1answer
5k views

Improving the Java UUID class performance

I am looking to submit the following code (adapted to fit into java.util obviously) which significantly improves performance and reduces useless allocations of <...
1
vote
1answer
5k views

Crossword game - designing class structure

I've planning to create crosswords game for Android platform. Basically, crossword is a matrix of TextFields (EditTexts) and <...
23
votes
7answers
48k views

Convert String to Integer with default value

I want to convert a java.lang.String to a java.lang.Integer, assigning a default value of 0 ...
8
votes
2answers
12k views

How is my BlackJack game design?

This is a command line BlackJack game created in Java as my final project for an advanced programming class. What do you think about it? Have I used OOP correctly? What grade should I get for this? :...
4
votes
2answers
5k views

Stringed musical instrument class

I humbly submit the following for critique. This was my final project for an Intro To Java Programming class ("handed-in" already, I can't make changes). The abundant commenting is required by the ...
2
votes
2answers
464 views

Closing a ResultSet and rethrowing an Exception

Is this an acceptable way to make sure a java.sql.ResultSet is always closed, and also make sure that an Exception caught is propagated to the caller? Please don't hesitate to review other aspects ...
5
votes
1answer
11k views

Optimizations to 8-puzzle

I am a CS student about to enter my junior year. I am attempting to get better and better at programming and thought that this would be a good place to toss my code out there to see if some of you ...
6
votes
1answer
649 views

Change Sudoku code to OOP

I just started learning how to write code in Java. I want to turn the code to OOP with fewer methods, using classes like Sudoku rather than int[][] puzzle. ...
3
votes
3answers
361 views

Making my Rock, Paper, Scissors game shorter

I am looking for advice on making the following code shorter. Any help is appreciated. ...

1
187 188
189
190 191
201