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
44 views

RecyclerView with different ViewHolder using generic

I have different ViewHolder for different Feed implementations. But I can't use the best practice of having each ...
5
votes
0answers
83 views

Java objects for a network sniffer program

I'm working on a network sniffer program, whose structure uses 3 main classes: Frame Class - One per monitored frame, holds reference to all the other sub frames Parse Class - Holds the hex value of ...
0
votes
0answers
17 views

Given a resource ID, instantiate, retrieve and localize a Linked Resource for a REST API call

During a question on Stack Overflow, another user had some comments about the way this code works. He had a few choice words for it, including "magic", "ugly contraption", "you're doing things you ...
7
votes
2answers
102 views

Finding collisions of the first few bits of a SHA-1 hash

My objective is to find a hash collision of my modified hash function. Assuming my modified hash only outputs the first 36 bits of SHA-1. As we know, SHA-1 is a 160-bit hash value, hence, we only need ...
3
votes
1answer
93 views

Random String Chooser

I was tasked with creating the class RandomStringChooser that prints the strings in the passed array in a random order, based on the ...
1
vote
2answers
108 views

Implementation of Dijkstra algorithm

I am trying to implement Dijkstra algorithm. I try to calculate cost of reaching every node from first node. Though I have tried with couple of graphs and results are correct but I have one doubt ...
2
votes
1answer
40 views

Check if current time is within the timeframe using Joda-Time

Novice Java developer here. I've never really used a time/date library before and I'm curious how an experienced developer would solve this. You're given 4 ints: startHour, startMinute, endHour and ...
0
votes
2answers
57 views

Creating a Java text-based game map [closed]

i got a college project and i'm trying to create a map for my text-based game in Java. Me and my colleague* created this code: ...
3
votes
2answers
150 views

Strategy advisor for a Yahtzee Roll

I'm implementing a Yahtzee app and i have a class StrategicAdvisor that is responsible for deciding which strategy should be followed. The ...
6
votes
3answers
115 views

Postfix calculator in Java

I made a postfix calculator in Java. The code performs the functions I planned without problems, However, I'm not satisfied with it, because it's too verbose and I couldn't split it up into methods ...
1
vote
0answers
42 views

Near immutable, thread safe Builder

I'm writing a torrent streaming client. The plan is to wrap WebTorrent-cli and provide a Java interface to observe download state, cancel or pause downloads etc. Anyways, I came up with the following ...
3
votes
2answers
63 views

Gram-Schmidt process in Java for computing independent bases in linear spaces

Given a set of \$k\$ \$n\$-vectors \$\vec{x_1}, \dots, \vec{x_k}\$, Gram-Schmidt process computes a basis \$\vec{y_1}, \dots, \vec{y_m}\$ (\$m \leq k\$) the vectors of which span the same space as \$\...
2
votes
2answers
69 views

Sudoku generator using seed Sudoku

I have created a Sudoku generator in Java. Here I am using a basic solved sudoku as seed and by transposing it and shuffling its row and columns I get a new solved sudoku. ...
2
votes
1answer
44 views

Sum of Two Matrices

For a homework assignment, I was asked to do this problem. It worked, but it looks messy in my opinion. I want to know if this is the best way to accomplish this task, and if there can be any ...
3
votes
1answer
81 views

Matryoshka Doll Recursion

I was tasked with writing a Matryoshka doll program that manages the following: howManyDolls : returns an integer based on how many dolls are inside the stack howManyWearingBabushkas : returns an ...
4
votes
1answer
264 views

Converting long values in Java to unsigned strings

This one is a research attempt to find out how to convert long values as unsigned long integers to Strings. It is much slower ...
7
votes
2answers
170 views

Snake Game with own Field API

Some days ago, I posted a question here: Field class as basis for a role playing game I payed respect to tips I find useful and made a further development of my Field-classes. These classes have to ...
1
vote
0answers
47 views

Spring (boot) MVC Abstract Controller

I'm writing an application that will end up with a set of standard CRUD operations for a bunch of object types, and I thought it would help simplify things if all the separate controllers had some ...
3
votes
2answers
68 views

Island perimeter code challenge in Java

Problem: Source (with example): https://leetcode.com/problems/island-perimeter/ You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. ...
1
vote
2answers
52 views

Optimize printing massive strings to System.out with respect to time

I need to cut the time it takes to print a large string by ~50%. I went from using s1 + s2 to using StringBuilder, and instead ...
-1
votes
1answer
48 views

java for loop with map merge [closed]

Simple conversion of one type to another. Is there a better way with streams : ...
3
votes
1answer
182 views

N-puzzle solver using A* search

I have written a Java program to solve a N-puzzle with A* search and manhattan distance. My program can solve every 8-puzzle I have tested under 1 second, but it can't solve a 15-puzzle after 30 ...
2
votes
1answer
69 views

Code which creates the Game Of life In Java

Link to github Link to github: https://github.com/zombi3123/Game-Of-Life/ Source code: Window.Java ...
5
votes
2answers
781 views

Find hamming distance between two Strings of equal length in Java

I have a private class that I want to be able to find the shortest Hamming Distance between two Strings of equal length in Java. The private class holds a char[] ...
2
votes
0answers
36 views

Streaming video from PiCamera to Windows using Java and Python

I'm making a robot with Raspberry. My goal is: Code a server on Rasbperry using Python that captures the image from camera and sends data via socket Code a client on PC using Java that reads data ...
2
votes
0answers
58 views

Game involving finding words containing letters from a memorized list

I wrote this Java game where the user memorizes a list, gets given letters and needs to find a word that contains those letters. The player has only a few seconds to enter the word. Example: Program ...
3
votes
1answer
75 views

A simple Java game where the player guesses the word

It's a simple word guessing game. The game picks a random word - you guess a letter until it's correct, the game automatically starts a new one. Is my code readable? Am I doing anything that could be ...
5
votes
1answer
55 views

Find amounts that cannot be composed using the given coins

I need to make a program that receives a set of currencies and tests which values between 1 and 10,000 units can not be produced with these currencies. The program must have 2 input data: The ...
4
votes
1answer
54 views

KeyboardTeacher

I would like to hear opinions from people with bigger experience about KeyboardTeacher application. It fetches text from a text file, and shows the first line in console. If user types the whole line ...
1
vote
1answer
74 views

Writing billions of lines to text file in java [closed]

I'm trying to write billions of strings lines to a file, it works for up to 40 million lines, but it's throwing out "java.nio.BufferOverflowException" error for 400 million lines. I also think my ...
4
votes
1answer
50 views

Google Maps API - reading locations from file and displaying markers on map

I'm working with Google Maps and want to read in location objects into the map. I'm loading them in from a .csv file and create Shelter objects for each location that I save in an ArrayList. To ...
5
votes
2answers
99 views

Pascal's Triangle Java (performance)

I need to get some information about the Pascal Triangle. What is a pascal triangle ? It is a triangle of integers with 1 at the top and at the sides. Any number inside is equal to the sum of the ...
4
votes
2answers
121 views

Word ladder finding class

I have a class that I'm using to find the shortest word ladder between two words. Each "Step" in that ladder is returned as a String element in a ...
3
votes
1answer
94 views

Rubik's Cube in Java

I have this Java implementation of a Rubik's cube's state. My primary concern is DRYness of my code: RubiksCubeNode.java ...
2
votes
0answers
48 views

Breadth-first search in Java: Competitive style - follow-up

I have improved my BFS in Java according to vnp's suggestions. Again, we wish to find shortest paths in directed unweighted graphs using BFS, competitive style (no ...
1
vote
1answer
82 views

Breadth-first search in Java: competitive style

Here my attempt was to write a graph algorithm the way a competitive programmer would write under time pressure. The problem to solve was to find a shortest path in a directed, unweighted graph using ...
3
votes
0answers
56 views

Java code to convert BigDecimal to/from .NET decimal

Background In many languages we have built-in data types for representing decimal floating point numbers. In .NET that's decimal, and in Java we have ...
4
votes
1answer
80 views

Android clock in/out app

I am writing a clock in / out and payroll app for Android. I am no professional, but I was hoping I could get some feedback on whether my code is spaghetti or not. This is just one of many classes &...
1
vote
2answers
129 views

Leetcode - find if BST is valid or not

Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node'...
1
vote
2answers
27 views

Initializing BufferedReader and DataOutputStream in infinite loop

Is it a good practice to initialize the BufferedReader and DataOutputStream in infinite loop? ...
2
votes
3answers
153 views

Armstrong number generator

This is my code to generate all possible Armstrong numbers between the two given numbers. The logic uses string instead of integer to separate the digits to optimize the code. ...
-2
votes
2answers
168 views

ArmstrongNumber checker

This is my code written to check whether a given number is armstrong or not . but the logic differs from the conventional logic of using integer and separating its digits and calculating , instead i ...
3
votes
2answers
154 views

Finding products of all other members of an array

I had the following interview question: Given an array of integers, for each member of the array find the product of all the other members of the array. So for instance, if you have this array: <...
2
votes
1answer
40 views

SafeBlockPopulator to ensure neighboring chunks are generated before population

Bukkit/CraftBukkit/Spigot are Minecraft server extenders that allow for creating and using plugins. A particular type of plugin is a generator, which creates the game world. Generators operate chunk-...
3
votes
2answers
67 views

Leetcode - First Unique Character in a String

Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: ...
2
votes
0answers
32 views

Android+Firebase testing using Mockito

I have an interactor/usecase class in my application. My application follows MVVM architecture with interactor/usecases responsible for logic (e.g. get data from api-service, store in local-database ...
1
vote
1answer
88 views

employing AES algorithm in Java

I have employed an AES algorithm in order to encrypt files within a GUI. I was wondering if my algorithm is secure. Could I change anything to improve it? Is my IV secure and is it producing different ...
1
vote
1answer
27 views

Leetcode - product of array except self

Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Example: ...
3
votes
2answers
62 views

Add three integers and report the sign of the sum

I am in my first high school programming course; the assignment is: Write a program that asks the user to input three integers and outputs a message indicating their sum and whether it is ...
3
votes
2answers
301 views

Tic-Tac-Toe Player vs Computer

I have created a logical AI for a Tic-Tac-Toe game. I want a review about how good or bad it is. Here the computer AI will defend all your attacks as well as try to attack whenever it gets a chance. <...