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
4
votes
1answer
603 views

Critique of Pascal's Triangle Class

I'm working my way through The Java Programming Language, Fourth Edition - The Java Series. This is Exercise 7.3: Write a program that calculates Pascal's triangle to a depth of 12, storing each ...
3
votes
2answers
165 views

Optimizing code block using Switch Case

I have a implementation of following code block, ...
2
votes
1answer
2k views

Anagrams for a given input 2.0

This question follows on from :Previous Question Here is what my reworked code looks like. I neatened it up as much as I could. Changed some of the semantics of it. I also tried to add some faster ...
6
votes
4answers
18k views

Anagrams for a given input

This question is the first draft, my new revised code is here: Anagrams for a given input 2.0 Here is my code that I wrote, which basically lists the anagrams for a given input. I did this by ...
1
vote
1answer
733 views

How to reduce code from different alert-dialogue?

I have three types alert dialogue. Each alert dialogue behave differently but I don't like to write three types of alert dialogue in same class because it extends the class size drastically. Here are ...
3
votes
2answers
828 views

Implement String's valueOf function, code review request

Ok, code reviewers, I want you to pick my code apart and give me some feedback on how I could make it better or more simple. ...
5
votes
4answers
317 views

Configuring toString via a public static variable

Sometimes I need toString() to be quite verbose, normally I don't. It can't be nicely solved by using other methods as toString()...
1
vote
2answers
4k views

Merge three ByteArrays together and then split resulting ByteArrays

I have a ByteArray value as avroBinaryValue , Schema Id value as ...
0
votes
1answer
784 views

Trie - code review request for improvement

Ok, code reviewers, I want you to pick my code apart and give me some feedback on how I could make it better or more simple. ...
3
votes
1answer
9k views

Create a binary tree, code review request

Ok, code reviewers, I want you to pick my code apart and give me some feedback on how I could make it better or more simple. ( Generics would be added a bit later). ...
2
votes
1answer
2k views

Print all path from root to leaves - code review request

Ok, code reviewers, I want you to pick my code apart and give me some feedback on how I could make it better or more simple. ...
6
votes
4answers
721 views

A character array of arbitary length with 'R', 'B', 'W' is needed to be sorted in that order

There is a char array of n length. The array can have elements only from any order of R, B, W. You need to sort the array so that order should R,B,W (i.e. all R will come first followed by B and ...
3
votes
1answer
192 views

Critique of enum

I'm working my way through The Java Programming Language, Fourth Edition - The Java Series. This is Exercise 6.4: Expand your traffic light color enum from Exercise 6.1 on page 152 so that each ...
2
votes
1answer
729 views

Using twitter4j to fetch usernames that retweeted me

I'm using using twitter4j to fetch usernames that retweeted me. I'm interested in any feedback that make the code more elegant, and also that might reduce the number of calls I'm making to the Twitter ...
1
vote
1answer
4k views

Removing nodes from queue

I had an exercise to create two methods for simple queue class, first to delete last element and second to delete element at k position. Particularly I'm not asking for better implementation. Is it ...
2
votes
1answer
1k views

Is this the right way to retrieve all the fields from any Object?

I have a method that returns a List<Object> from any given Object containing its values. It doesn't get the values of any <...
3
votes
3answers
1k views

Prompting for values to plug into a formula — how to do it elegantly

This is my first program in java. I am wondering if there would be a better way to tackle this. I am only allowed to use one class. It's not quite finished, but I am thinking it doesn't look very ...
4
votes
1answer
1k views

Linked List in Java (Garbage Collection)

So I'm implementing a linked list in Java, and so far it looks like this: ...
4
votes
3answers
170 views

Is there a better, more object oriented way to write this Finder method?

I have several lists of objects which are stored in different locations, based on what they are and who needs them - the system, or the user, for example. There are times where I am only given an ID ...
5
votes
1answer
158 views

Writing an effective method that reflects good OO design and fixes this broke method

I'm working on my personal project and have recently had a bit of trouble with a method I wrote during the week. This method compares user input from the same ...
2
votes
2answers
85 views

CharacterEscaper - further optimizable? Bugs?

I have been working on a character escaper for a production server that receives quite a few requests per second (sometimes in the range of 400). We forward some "query" requests to apache Lucent/...
2
votes
3answers
10k views

Using the wildcard when importing packages [closed]

I am learning java and browsing posts on CodeReview and StackOverflow. In my text Introduction to Java Programming- Y Daniel Liang it states: The wildcard import imports all classes in a ...
3
votes
2answers
5k views

Java Bouncing Ball Review

Just looking for some help reviewing/refactoring. For example, could the classes random/vertical be refactored into 1 class instead of 2? BouncingBalls.java ...
1
vote
3answers
131 views

Is my code unit testable

I've written a piece of code. Would like to know is the below piece of code unit testable or does it need any kind of refactoring. MatchCilentUrls is the primary method for matching two urls. Based ...
3
votes
2answers
931 views

Is this correct to reassign already intialized variable? [closed]

I am reading hadoop source code , Here I have a doubt "org.apache.hadoop.util.StringUtils" they reassigned a list which is already intiailized. ...
-1
votes
1answer
44 views

How to organize these several lists of booleans to avoid code duplication?

My class Person has a number of boolean values: isMoving, hasEyesOpen, ...
3
votes
5answers
16k views

How to fill in this HashMap neatly without code duplication? [closed]

I'm supplying a HashMap with data in the following way: ...
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 ...
2
votes
3answers
2k views

Game Of Life 3 in Java

I have this version of John Conway's Game Of Life in Java: Frame class: ...
4
votes
1answer
641 views

Game of Life Animation Java

I have this Board class: ...
3
votes
2answers
472 views

Method Of Retrieving Random Value Depending on Type

I was wondering what would be the most appealing way of achieving this goal. I have a blackbox. I give it a supported type and it returns a random value base off ...
4
votes
1answer
327 views

Java/Swing GUI code/layout, am I doing this wrong?

I've never done Java GUI's before. After much trouble I've gotten my GUI to look how I want, however it feels as if my code is very inefficient, as if I'm going about this the wrong way? ...
3
votes
1answer
197 views

Static variable Current in Application

I was finding myself frequently calling getApplication() and casting it as MyApplication so that I could call a method in ...
3
votes
2answers
955 views

Print largest two integers from a stream

I'm writing a program for my intro to comp sci course where I'm supposed to prompt the user to enter a stream of integers, and then return the largest two. We were given the hint to use a scanner and ...
4
votes
2answers
1k views

Is this recursion a bad idea and does it make for clean code?

This is a program I made to bounce the letter a across the screen. I made a few others, but this one I made with a recursive bounce() method. I know ...
1
vote
2answers
6k views
1
vote
2answers
4k views

ReentrantReadWriteLock lock upgrade method

I have a question about lock upgrading.Specifically what bothers me is between readlock.unlock() and following writelock.lock()... I am providing a nearly complete implementation for a sample cache.I ...
4
votes
1answer
5k views

Unit test an ExecutorService in a deamon

To execute tasks sequentially with a timeout I use ExecutorService.submit() and Future.get(). As I don't want to block calling ...
1
vote
1answer
2k views

Print Longest Decreasing Segment

I'm trying to brush up on my Dynamic Programming by doing some example problems. I've got the following... Given an array of integers, print the longest decreasing segment. For example ...
9
votes
6answers
17k views

Many if statements - refactoring [closed]

Yesterday I found some nice video from some IT conference about removing if statements from code. I saw a very nice example of refactoring. I am curious what do you think about it, especially what ...
2
votes
2answers
365 views
2
votes
1answer
229 views

Singleton has logic and state, and logic has state

------edit--------- note: this is for a MUD client, so the commands are issued to the MUD game server -----end edit-------- For an overview, here's the structure of the project: ...
6
votes
6answers
323 views

Long conditionals in ifs [closed]

Very easy question for these who spend some time on analyzing code written by co-workers. When I write my code, I do my best to write it in a very, extremely readable way. But sometimes I have an ...
1
vote
1answer
73 views

Can MD5ing all the files in a table cause a memory leak?

I'm running this code with the FastMD5 library. Could it lead to memory leaks, or does it seem OK? ...
4
votes
2answers
361 views

Review of reservoir sampling

I've been studying Reservoir sampling for a couple of days. What I've tried here is draw a uniformly random sample of size 3 from bigger data (the 26 characters of the English alphabet) via reservoir ...
1
vote
3answers
143 views

When to catch/wrap an exception vs declaring that method throws exception

In the snippet below the three exceptions I declare in the throws clause are all thrown by BeanUtils.setProperty(), which is a third party library. Is letting ...
3
votes
2answers
7k views

What's wrong with static utility classes, versus beans?

My inclination is to make these methods static: ...
6
votes
3answers
2k views

Static methods or singleton?

I have class that handles HTTP requests: ...
1
vote
1answer
525 views

Calling different bundles in parallel using ExecutorService

I am working on a project in which I will be having different Bundles. Let's take an example, Suppose I have 5 Bundles and each of those bundles will have a method name ...
2
votes
1answer
712 views