The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
3answers
2k views

Extending java.util.Random.nextInt(int) into nextLong(long)

In java.util.Random the Oracle implementation of nextInt(int) is as follows: ...
2
votes
1answer
684 views

Rewriting nested for loops to give better formatted output

The following is code from a university practical I am doing. It reads in a txt file of twenty clients, whose information is stored in the txt file like this: ...
2
votes
2answers
249 views

How to use inversion of control within a strategy when using the strategy pattern

I am creating a skeleton application to demonstrate use of the Strategy design pattern and inversion of control inside a Strategy. The application is the backend of a simple board game, which also ...
3
votes
2answers
435 views

Optimization of exponentiation

I'm writing some crypto code, and as part of it, we have to implement modular exponentiation. I have it working, both with the right-to-left binary method and with the Montgomery formula. While ...
3
votes
2answers
784 views

Closable BlockingQueue

I am working on legacy code, specifically a sort of BoundedBlockingQueue (mainly used as a pipe between different threads). As it is heavily used in the system and the current implementation features ...
2
votes
2answers
511 views

Session in Struts2 and Google App Engine

Im using Struts2 running in google app engine. User can use their google and facebook account to login to the site. When a user login, i have: ...
2
votes
2answers
4k views

Modular exponentiation optimisation in Java

As part of an assignment in Cryptography I've been asked to write code that involves calculating modular exponentiation. The BigInteger modPow is not allowed in this case, we have to implement it ...
1
vote
2answers
115 views
1
vote
1answer
3k views

Persistent Cookie Store

So my app needed a cookie store that persists over the app closing, device reboot etc. I decided to use the sharedPreferences for this. The class works pretty well, in both my tests and on the device. ...
1
vote
1answer
147 views

Kindly review this class [closed]

What I can think of improving is: Show stack on screen to fail gracefully i.e. improved catch part of try..catch Make the try part shorter to improve readability Make imports with * to improve ...
7
votes
2answers
2k views

How to increase download speed using the following method?

I have written an Android application which downloads pdf files through web service. I am using kSoap2 android library to parse the response of web service which basically contains file name & ...
1
vote
1answer
849 views

Java Swing Panel layout [closed]

I am working on a Java project for college that involves us setting up a TCP Server and Client. I have that part working and now to add more of a feel to my project I want to add a GUI. We have not ...
4
votes
1answer
1k views

Cryptographic key exchange

I initially posted this on StackOverflow, and was redirected here. I have been playing around with Bouncy Castle (Java) for the last few days, and I've reached the point where I believe I can securely ...
1
vote
2answers
838 views

Interview street Median challenge [closed]

I was trying to solve the Median challenge at Interviewstreet.com. I wasn't able to pass most of the test cases. But according to my understanding my code should work fine. Here is the question: ...
6
votes
1answer
99 views

Which is better for checking previous object in list?

I have a for loop which loops through a list and builds and object, I needed to check the previous object with the one i'm building...which way is better? This way?: ...
6
votes
2answers
1k views

Vector-based flood-fill algorithm queue class

I want to implement the flood-fill algorithm for https://stackoverflow.com/questions/12995378/is-there-a-proper-algorithm-for-detecting-the-background-color-of-a-figure. I did it recursively, but I ...
1
vote
2answers
1k views

Reading a Bitmap from disk on a separate thread on Android

I want to defer the reading of a bitmap to another thread. I'm mainly concerned about concurrency issues since I'm kind of green on that subject, so I would like to know if this code has any potential ...
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 ...
3
votes
1answer
2k views

Any problems in using hibernate's session.connection() to run native sql

In my project, they use Hibernate's session the below mentioned way and then save entity objects with in a transaction. ...
1
vote
4answers
278 views

Insertion vs Selection

I currently have a selection sorting algorithm, but need some help turning it into a insertion sort, I understand a insertion sort if faster? The hand array is full, and it needs to sort from lowest ...
10
votes
3answers
3k views

Better way to write nested loop, if condition and breaking it

This is a Java method that takes as input a 2 dimensional array called grid. It uses the i1 and ...
5
votes
1answer
3k views

Is this the best approch to combine 2 Interfaces?

I have a use case where I want to use both HttpRequestInterceptor and HttpResponseInterceptor in one ...
3
votes
2answers
161 views

Subclassing or not?

I have a class called Foo ...
4
votes
2answers
1k views

Binary tree max sum level - better design?

I have written some code for finding a level in a binary tree, having a maximum number of elements. I have a few questions: Is it a good design? I have used 2 queues but the total sum of elements ...
0
votes
1answer
106 views

Method Ordering - Readability / Maintainability [closed]

What is your opinion on method ordering? Should it be public methods at the top followed by private methods? or Should it be linear order so that methods calling methods stack on top of each other? ...
5
votes
1answer
5k views

Java implementation of the longest monotone increasing subsequence

Problem: Given a set of n distinct numbers, find the length of the longest monotone increasing subsequence. For example, let's take this array ...
2
votes
1answer
68 views

Can this graph search be optimized?

I have the following which searches my graph to see if a vertex is reachable from the first vertex, which everything should be connected to. I do this to ensure there are no disconnected parts. ...
4
votes
1answer
156 views

MySQL Java Connection with my application

the following is my code for the Java class connection to mysql server, i need to see if there is any suggestion to make it better. this class not making the connection, it just control transactions, ...
3
votes
2answers
2k views

Format names to title case

So I'm writing a program to format names to title case and display them in alphabetic order. Any advice please? And how can i add more methods? ...
2
votes
1answer
1k views

Java foolproof input class

I started learning java a few days ago. I prefer C++ but since I'll need java this college semester I decided to learn a few things to ease myself in. Anyway in C++ I always used a foolproof input ...
2
votes
1answer
589 views

Is my DSL good idea to replace builder pattern?

I want to build a set of builders for generating test data. On one side I want my builders API to be natural to use for my teammates. On the other side I'm great fun of creating DSLs, because it ...
4
votes
1answer
120 views

Refactoring code finding if Binary Tree is BST

I have written an code to find if a given tree is a BST. Need help in refactoring it. Some of the things I am looking are. Getting Rid of temp variables (As suggested by Martin Fowler) Combining ...
5
votes
2answers
2k views

Checking if entity exist in Google App Engine Datastore using JPA 1

Below is my method in checking if entity already exist. ...
3
votes
1answer
6k views

Java Slick 2D Collision Detection Methodology

I have a collision detection for terrain setup (non-terrain is handled with a quadtree I implemented apart from this) and I was wondering how others have done it compared to mine and what I could ...
3
votes
1answer
161 views

Designing a listener method and making it Testable

I have a java based server application that needs to support multiple clients. In the main class I have a method that runs in an infinite loop and waits for client connection. Following is this method:...
5
votes
1answer
2k views

How can I make placing JButtons from an array more elegant?

I am trying to place JButtons from an array onto a JFrame. The way I'm doing it is having it test how many more buttons are left,...
3
votes
3answers
7k views

Describe how you could use a single array to implement three stacks

I'm preparing for an interview so I'm trying to solve some problems to stretch my mind. Here is one: Describe how you could use a single array to implement three stacks. And here is my ...
3
votes
1answer
2k views

Java: Find the smallest integer not in the list - Memory Efficiency

This is a fairly popular interview question that I conceptually understand but have never really attempted to implement. In other similar implementations of this in Java I have seen they typically ...
5
votes
1answer
161 views

what is Null Test in java? and how to rewrite the code to do the same by avoiding null test

I would like to know what is null test in java? How to rewrite the below code by avoiding null test. I was asked this question in an online test. I'll be grateful for any help offered. ...
2
votes
2answers
4k views

String pattern matching - method needs improving

I'm trying to build simple pattern matching in a string. ie., Given a template of: "Hello ${1}" and an ...
5
votes
1answer
410 views

Any better way to copy from Readable to OutputStream?

I neglected java.nio package in the past and now I am wondering if this is the best way to copy everything from a Readable to an ...
2
votes
2answers
424 views

Can this Google Hurdles code be made to run any faster?

Anyone can play Google Hurdles today. Here is my score: 1.1 second. Is there are way of improving this score and running faster than a second? http://www.google.com/doodles/hurdles-2012 ...
4
votes
2answers
1k views

Can not clearing a local java.util.Vector cause a memory leak?

In the code below, does not clearing or setting the local variable completed to null create the potential for a memory leak? ...
6
votes
1answer
6k views

Java 2d array nested loops

Okay, So I have this method I made that searches a 2d array of user input column length and row length comprised of integers. The method is suppose to find 4 alike numbers in rows, columns, and both ...
12
votes
4answers
52k views

Simplify splitting a String into alpha and numeric parts

Requirement: Parse a String into chunks of numeric characters and alpha characters. Alpha characters should be separated from the numeric, other characters should be ignored. Example Data: Input ...
2
votes
1answer
351 views

Thread pausing/resuming implementation

I saw this question on StackOverflow and realized i didn't know how to solve it either, so i started trying to figure it out, using this answer as base point. Could you please review and comment on ...
8
votes
1answer
2k views

What more can be done to add quality to Swing JPanel drawings?

I'm sorry if I have not worded the question title to well, so let me explain. I am creating a game, actually a few and I see that most of the time when painting ect I use a JPanel, so I went and ...
3
votes
2answers
486 views

Is this Sudoku a good use of the Fluent Builder Pattern?

Code Sudoku.java ...
1
vote
2answers
101 views

Linearized Fit to Data

I'm creating a class to describe a "zigzag line" fit to a set of data. It implements my interface Fittable, which just contains evaluate() (I have mulitple kinds of ...
2
votes
2answers
174 views

Can you guys look at my java project and give me some tips?

So I feel like I'm a good coder, but that's from my point of view. Can you take a look at my code and give me some tips or criticize me on my code. Or give me some tips or things to add or make things ...