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
10 votes
3 answers
13k views

Rock, Paper, Scissors Game in Java

I made a Rock, Paper, Scissors game and would like the code to be reviewed. Main class: ...
2 votes
1 answer
533 views

Minesweeper, Bombcount method

I have a method which checks all of its surrounding squares and returns the number of bombs around it. It uses a long list of if statements, which is pretty ugly ...
3 votes
1 answer
10k 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 ...
2 votes
1 answer
339 views

HTML downloader and parser for CR

This program downloads a Code Review HTML file and parses it. Could you review my program? Main.java ...
2 votes
1 answer
2k views

Binary HeapSort and Ternary HeapSort implementation

This is my take on binary and ternary heapsort implementation for a university assignment. The code works but I wonder if there are any mistakes or things to improve. ...
4 votes
1 answer
6k views

Cron expression validator for Apache Quartz

Not too long ago, I had to create a cron expression for a route in Apache Camel. I had a bit of a struggle to find the right expression. So I made a small program to output the n next valid dates ...
3 votes
1 answer
135 views

Examining programming laboratory exercise for faculty

I'm developing software for examining programming laboratory exercise for faculty. I have an Error object that can be attached to students work. It can be attached ...
3 votes
3 answers
244 views

Is SList class an ADT?

As per the definition given in lecture, ADT is, With reference to this definition, I would like to call SList class an ADT following 6 invariants: Multiple users ...
6 votes
2 answers
216 views

Performance of speech enhancement code for Android app

I wrote a speech enhancement code for an Android App. The algorithm runs on 256 size frames of voice samples. On my PC the code runs per about 5ms per frame, while on my Nexsus 5 it more like 50ms per ...
5 votes
4 answers
387 views

Find the number of times that the difference of array values are equal to the number

I wrote the following code to answer this, but I am wondering if there is any better approach. For example If the following array is given: {10,21,34,45,56} we ...
15 votes
2 answers
5k views

Trading Card Game Prototype GUI with JavaFX

Most of my programming experience is with Objective-C, but I have recently started learning Java and JavaFX to build the user interface for a Trading Card Game. This is the most Java I have ever ...
5 votes
1 answer
318 views

Software Key Generator

I have created a Java program which generates a key (for activating a piece of software for example) my code works correctly however there are parts of it that I know can be improved. In particular ...
2 votes
2 answers
414 views

CR Stack Exchange crawler

I am writing a program which automatically crawls codes from this site! Would you please review my code? The required .jars: jsoup, org.apache.commons.io. Main.java: ...
7 votes
1 answer
29k views

Sending HTML-formatted mail in Java

This is my code for sending mail in HTML format: ...
1 vote
3 answers
3k views

Preorder traversal of binary tree to produce formatted string

Given a complete binary tree returns the following format (Parent ( leftchild (leftchild, rightchild), rightchild(leftchild,rightchild) ). Looking for code review, optimizations and best practices. <...
5 votes
2 answers
4k views

Remove Nth Node from End of Linked List

I am solving the well known problem Remove Nth Node From End of List: Given a linked list, remove the n-th node from the end of list and return its head. Assume that n is between 0 and the ...
4 votes
3 answers
48k views

Implementation of a doubly linked list in Java

I'd like to improve this code. DoublyLinkList.java ...
5 votes
2 answers
1k views

Simple factorial program using recursion

Two concepts I realized I needed to understand and use more are recursion and Exceptions. Thus, I combined both in the following program. Although it began with a focus on using recursion it became ...
26 votes
2 answers
3k views

Android Flashlight app

This is my first project, a Flashlight application for Android-based devices: ...
1 vote
1 answer
67 views

Follow-up: Find number of times that difference of array values are equals to a number

This question is follow-up to this question. Sample Calculation ...
8 votes
3 answers
1k views

Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree

Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree. Given tree: ...
1 vote
3 answers
990 views

Check if all leaves are at same level

Check if all leaves are at same level. This question is attributed to geek for geeks. Looking for code-review, optimization and best practices. ...
3 votes
1 answer
172 views

Reverse values of alternate nodes of the tree

Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree. Given tree: ...
3 votes
2 answers
1k views

Inorder traversal of a tree without recursion or stack

Please review the code for code cleanup, smart optimizations and best practices. Also verify my complexity: \$O(n^2)\$, where \$n\$ is the number of nodes. ...
3 votes
2 answers
213 views

Join/ connect all levels of Binary tree without any aux storage

This program connects all nodes of the binary tree at the same level. A node of a tree contains a left, right and a sibling pointer which would connect it to the next node at the same level. This ...
1 vote
2 answers
3k views

Serializing/deserializing binary tree in most space-efficient way

I'm looking for corrections, optimizations, general code review, etc. ...
2 votes
2 answers
2k views

Get the levels of a binary tree

Given a binary tree, return a list of each level. I'm looking for a general review and a mention on best-practices, optimization, and verification of my complexities. Time complexity: \$O(n)\$ ...
1 vote
1 answer
2k views

Convert a doubly linked list into balanced binary search tree in-place

Given a doubly linked list which has data members sorted in ascending order, construct a balanced binary search tree which has same data members as the given doubly linked list. The tree must be ...
2 votes
2 answers
17k views

Iterator for binary tree - pre, in, and post order iterators

Implemented iterator for a binary tree and "pre" "in" and "post" order flavors. I'm looking for code review, best practices, optimizations etc. ...
0 votes
2 answers
625 views

Return the next right node

Given a binary tree, return the next right node. This question is attributed to GeeksForGeeks. For example, consider the following Binary Tree. Output for 2 is 6, output for 4 is 5. Output for 10, 6 ...
2 votes
2 answers
933 views

Isomorphic trees verification

Two trees are called isomorphic if one of them can be obtained from other by a series of flips, i.e. by swapping left and right children of a number of nodes. Any number of nodes at any level can have ...
4 votes
1 answer
2k views

Detect a complete binary tree

Follow-up question: Detect if a tree is complete binary tree Detect if a tree is complete binary tree or not. Looking for code review, optimizations and best practices. ...
2 votes
1 answer
1k views

Extract Leaves of a Binary Tree in a Doubly Linked List

Given a Binary Tree, extract all leaves of it in a Doubly Linked List (DLL). Note that the DLL need to be created in-place. Assume that the node structure of DLL and Binary Tree is same, only the ...
4 votes
2 answers
178 views

Find sum of number of times that each character of source occurs in the target

I wrote the following code in response to this question "find sum of number of times that each character of source occurs in the target", is there any better solution for it? Analysis ...
1 vote
1 answer
149 views

HeapSort Efficiency

For heap (array based) sort, we need to start at index 1, ignoring the 0th index. If I want to make a static function like ...
6 votes
2 answers
2k views

Parallel "wget" in Java

Purpose: write Java program that downloads a list of URLs specified on commandline in parallel (simultaneously), reporting download completion every second. My solution follows below, please point ...
5 votes
4 answers
3k views

Sorting Algorithms

A group of basic sorting algos. Based on Algorithms, 4th Edition - Robert Sedgewick | Kevine Wayne. Just making sure all of my logic and everything is correct. ...
4 votes
2 answers
721 views

Efficiency and design of Dijkstra's algorithm modified for connected nodes

I've written an AI (well... it's not really that intelligent) that plays the board game Ticket to Ride. In that game, cities are essentially nodes of a graph, linked together by train tracks (the ...
2 votes
1 answer
6k views

Group by two lists in one map using lambda

I've got two collections: collection of rules, and collection of keys that can handle specific rules. Key have method ...
4 votes
2 answers
2k views

Searching through a contact list for given criteria

I have been staring at this code for awhile now and I am thinking there is a way to optimize it (namely the if-else statement ...
3 votes
2 answers
5k views

Calculating the ideal body weight

The following question was taken from Absolute Java 5th ed. by Walter Savitch: A simple rule to estimate your ideal body weight is to allow 110 pounds for the first 5 feet of height and 5 pounds ...
13 votes
4 answers
7k views

Split camel cased/snake cased String

I want to implement a method which, given some camelcased or underscored String, will return a list of separate words that make up this ...
5 votes
3 answers
2k views

Calculating the number of candy bars and gumballs that can be redeemed using coupons

The following question was taken from Absolute Java 5th ed. by Walter Savitch: The video game machines at your local arcade output coupons according to how well you play the game. You can redeem 10 ...
11 votes
2 answers
698 views

A method that generates a Comparator<String> using lambda expression

Given below is an exercise from the book *Java SE 8 for the Really Impatient( by Cay S. Horstmann: Write a method that generates a Comparator that can be normal or reversed, case-sensitive or ...
5 votes
2 answers
150 views

Performance for tags for cars in Java

...
2 votes
1 answer
267 views

Refactoring the Iffy Tractor task

There is a test of OO knowledge called Iffy Tractor. The task is to refactor the code and make it as much flexible as possible for the future modifications. I have placed the code here. It was taken ...
6 votes
1 answer
346 views

Dangerworld game

You can download the Dangerworld game in pre-alpha version and review the code. The particular issues I have are making the character walk over steps instead of sliding NPC AI how to make the enemy ...
4 votes
2 answers
4k views

Performance of hashmap-based session object

Unfortunately, I can't use the Tomcat session for storing the key/value pairs for each user (restricted because it's an IVR domain-based project). But I need the same functionality like a ...
2 votes
1 answer
2k views

Encoding and decoding exercise

I was issued the following coding challenge from a company to write an encoding and decoding function: Encoding: This function needs to accept a signed integer in the 14-bit range [-8192..+8191] ...
3 votes
1 answer
50 views

Input on where and how I can make improvements on my randomizer

As my title states I'm just looking for a little input on how I can improve one of my side projects when I'm not doing my CS assignments. All my program is, is a primitive randomizer for Battlefield 4 ...

1
183 184
185
186 187
218