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

Discrete random variable generator

There is my SSCCE to generate a value of discrete random variable. values is set of value the RV can take and procents is ...
2
votes
3answers
781 views

File-exclusion based on an array of prefixes

I am trying to remove files based on an array of prefixes, from files present in sourceDirectory. I am using prefixFileFilter to ...
4
votes
1answer
4k views

Recursive search to delete n'th child in tree

I have to implement a tree programming here. What I mean by tree programming is I have data stored in tree format. I have a parent object which will have child objects of same type the level of ...
4
votes
5answers
51k views

Student details project

I have made a student details project. The user is asked to enter the info for two students, which is then displayed on the screen. Questions: Have I used inheritance correctly? What would be a ...
5
votes
3answers
486 views

Readable code with many components (Swing)

Please help me to make more readable and simple code like this. What if I had 20 components? Is it right to organize code like this? ...
8
votes
3answers
37k views

Student information system

I have made a small project and I am just wondering if I could add more functionality to the project e.g more classed etc. Is a better way of displaying my results and what error handling I could do? ...
0
votes
1answer
155 views

Redesign a module to be generic

I am having trouble designing a module, can anybody help me? Because it will be hard to maintain this kind of module, I also think that this can test my skill of design pattern usage. Requirement ...
3
votes
3answers
2k views

Which one is more readable for mutually exclusive but mandatory command line parameters validation?

I have a small validation code that needs to make sure that exactly one of two parameter is set I consider two options, the "Naive" that has some repetitions and might look "clumsy" but is very ...
4
votes
2answers
145 views

Is using return appropriate here?

I wanted to get the boolean status from a function. Here is my sample code, wherein I used return in try and catch, to get the status of function. ...
6
votes
1answer
2k views

Finding the longest common substring between two tweets

I retrieved 200 tweets using the Jersey API. I want to find two tweets which have the longest common substring. tweetList is an ...
4
votes
1answer
2k views

JPA connection : is this code is efficient enough

By reading some tutorial i have written some peace of code to do crud operation . I just want to know how is this code is efficient or how can i make better ? Here i am giving code of 3 class 1. ...
4
votes
1answer
9k views

Ranking and sorting on Array/List

My apology, I am quite new to posting a question in this forum. I had a task where I was supposed to write a solution to sort entries(Name, score - in an array/list) in order of score and generate ...
1
vote
1answer
2k views

Array sort-rank class

I had a task where I was supposed to write a solution to sort entries(Name, score - in an array/list) in order of score and generate ranking based on higher score to lower scores. I tried doing that, ...
1
vote
1answer
341 views

Factory pattern for getting xml data

i am trying to implement factory pattern for getting XML Document from server (using javax.xml.parsers.DocumentBuilder) I have the classes below for now, could you give your opinion ? Does the ...
4
votes
3answers
677 views

Text menu shopping cart for mobile phone store

I made a mobile store, with prices in Indian rupees. Now I went for nested switch over functions, because I wanted to try out something new - biggest mistake in my life. Since 3 days I've been trying ...
0
votes
3answers
2k views

Am I getting the builder pattern right?

Despite being the clever Java coder I am, I noticed I know way too little about various design patterns. The builder pattern caught my eye as something to learn, as I have certainly seen my fair share ...
1
vote
1answer
5k views

Force Stop by Error in httpClient.execute(httpPost);

It work's at Smartphone(Android 2.3.3) but Tablet(Android 4.0) => Force Close!! ...
2
votes
2answers
133 views

2D model simulating water breaking a floodbank

For a homework assignment we have to write a class that simulates water breaking a floodbank (very simplistic 2D simulation). My implementation works fine but I found that there were many downcasts (...
3
votes
2answers
9k views

Multithreaded Client-Server file downloading application

A multithreaded client server program to download image files. If you want to execute it on your machine you should change the file paths. Since there are four files to download the client makes the ...
0
votes
1answer
174 views

What is the better way to retrieve value from this cache implementaion?

I have the following methods in CacheUtil class ...
17
votes
7answers
134k views

Finding repeating numbers in an array

I want to search through an array of n numbers and find the numbers that are repeated. So far I have this code, which does the job, but I find it to be a rather cumbersome method, but I can't seem to ...
3
votes
2answers
176 views

how to write generic extensions for standard collection types in java?

I am a Java beginner and I am looking for an idiomatic way of writing a function that involves generics. I wrote this helper class (below) that pushes items into a sorted generic collection and I ...
8
votes
4answers
3k views

Given two sorted arrays, add the elements of the second array into the first

In Cracking the Coding Interview by Gayle Laakmann McDowell, there's a question that asks you to write code for the following: Given two sorted arrays, A and B. Write a method merging the elements ...
5
votes
1answer
856 views

What is wrong with my knapsack alghoritm?

My alghoritm works and produces good result, but it takes too much time(6 s for 300 input items that is too much for branch and bound alghoritm), so I have maken a mistake somewhere, but really can't ...
4
votes
1answer
378 views

Swedish Tax Calculator

I'm submitting this code in a couple of days as part of an an interview process. The company knows that I don't have any formal experience with Java. I'm hoping they are testing my ability to learn ...
3
votes
1answer
2k views

Resource Pool implementation with ReentrantLock and Condition

The Resource Pool is similar to the implementation of a semaphore. It takes the class type of the resource and number of resource pools associated with it as the constructor parameters. There is a ...
3
votes
2answers
486 views

Lowest Common Ancestor

here is my implementation to find the lowest common ancestor in a binary tree. It works but i would like to know if i could have done anything better or if i have missed an specific case. would really ...
7
votes
4answers
5k views

What do you think of my Recursive FizzBuzz?

I wanted to see if I fully understood recursion so I attempted the FizzBuzz challenge and applied recursion to it. Did I do it correctly? Is this good code? Is there a more efficient way of doing it?...
2
votes
1answer
710 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: ...
3
votes
3answers
527 views

Listing a number's prime factors

I wrote a little code to list a number's prime factors: ...
5
votes
2answers
439 views

Multithreading correctly done?

I rarely write multithreaded code, and am on shaky ground when doing so. I make mistakes. I would like a sanity check of something I am going to introduce in one of my apps. There will be exactly ...
3
votes
1answer
792 views

Very simple async MixpanelAPI

I would love to hear feedback on my first open source project (a very simple async API for Mixpanel). It implements a REST client for this REST HTTP API. Review requested on the following aspects: ...
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
3answers
1k views

Solving Diophantine equations

I have a project for solving Diophantine equations, where a solution exists if $$A^5 + B^5 + C^5 + D^5 + E^5 = F^5$$ where \$0 < A <= B <= C <= D <=E <= F <= N\$ The program ...
2
votes
1answer
342 views

Cipher and passphrase classes using Java cryptography

I use some basic cryptography in a project of mine. Because I want my application to run cross-platform and because it seems pretty sophisticated I decided to go with the Java Cryptography ...
3
votes
3answers
3k views

Is it good practice in Java to pass a StringBuffer to a method to get error messages

I have a class that has a method which takes a user as an argument and performs several validation checks on the user and returns a boolean to indicate if theyare valid. I want to be able to get ...
3
votes
1answer
388 views

Sum the difference of two arrays

I have a function in App Engine Java where I compare two patterns stored in an int array: ...
3
votes
2answers
34k views

Converting timedate timezones with Joda-Time

I've been struggling to get to grips with Joda-Time, but feel that I've finnaly managed to get a grip on some of the functionality that I need. I have written a function that will convert a ...
1
vote
2answers
899 views

Querying a list of jobs on a server using EJBs

Inspired by this question, I have a Java Enterprise application running in Glassfish 2.1 and a Java SE client that communicates with the server application. For this I have a bean that maintains a ...
7
votes
4answers
453 views

Handling messages from a server

I've never really done anything with concurrency, so I'm not sure if this is done correctly. Basically, I have a class that handles all messages from the server and decides what to do them. It uses ...
3
votes
2answers
1k views

BinaryTree class with extra methods

I am taking a data structures course. I would like to check whether my BinaryTree code is perfect, fine or has lots of mistakes. I would like any kind of advice ...
8
votes
3answers
49k views

Determining triangle type from three integer inputs

The logic is simple, but I was wondering if anyone could help with rewriting the conditional logic. Also, the only error conditions I can think of are the sides should not be equal to or less than ...
3
votes
2answers
856 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 ...
9
votes
5answers
13k views

Find missing number from list

I was asked a question in an interview the other day: You have an array list of numbers from 1 to 100, the problem is that one number is missing. How would you find that number? This is a mock ...
3
votes
2answers
852 views

Not getting Log(n) performance from quadtree

Here is my QuadTree class and node. The problem is really with Querying. In my game, I have a city which can have n * n streets (randomly generated). And each street has buildings. What I do is put ...
2
votes
3answers
546 views

ACM API based Java exercise

I came across an exercise (in the book "The Art and Science of Java" by Eric Roberts) that requires using only GArc and GLine classes to create a lettering library which draws your initials on the ...
7
votes
7answers
24k views

Looping over a list, checking a boolean and return value

There are a number of different ways to do this. What do people prefer and why? ...
2
votes
2answers
11k views

Change View visibility programmatically or through XML?

I have an XML layout used by 2 activities. Within this layout, there's a view that is visible for Activity1 and ...

1
188 189
190
191 192
201