Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

-1
votes
0answers
13 views

Mapping to I/O method results [on hold]

Consider the following Java code: Stream.of(1, 2, 3).map(i -> i*i).mapToInt(Integer::intValue).sum() This is pure and will result in the same answer every ...
-3
votes
0answers
13 views

How to call paint method with a canvas in Swing? [on hold]

I've searched everywhere about how to use awt's canvas, but there's one thing that I just don't get: how do you actually call the paint method? Yes, you have to override it to draw whatever, but when,...
1
vote
3answers
30 views

Determine a list contains two elements with a given sum

On interview I was asked to write method with following contract: boolean checkList(List<Long> list, long sum){...} for example it has to return true for ...
0
votes
0answers
25 views

Determine indexes in a string for the first and last word in variable word length strings

I was wondering whether people could recommend some modifications they would make to this code if it were theirs. :) In my project, I utilise OCR to read user's timetables. This code is to determine ...
0
votes
0answers
15 views

Creating text game with JavaFX Interface

It's only my third day with Java and I already got a recommendation to check out JavaFX and build a simple text game. I do like text games, but I had no idea how to implement the features that I ...
1
vote
1answer
51 views

Integer to Roman Numerals (1 - 2999)

This is a homework assignment. Convert an integer (1 - 2999) to roman numerals. I was wondering if I could make my code more efficient. The way I have it set up is that I take the digits of the input (...
1
vote
1answer
23 views

Counting results of die rolls

The algorithm bellow is meant to allow a user to roll a die as many times as he would like, then print how many times each side was rolled and how many rolls there were total. ...
0
votes
0answers
21 views

Pattern to ensure only valid Positions are created, in as easy a way as possible

In the game engine that I'm creating, I have a Position Service. This service is the single authority of what is or isn't a valid position in the world. A goal of mine for this project is to make it ...
0
votes
0answers
13 views

FutureTaskWrapper for Java v2

I did not like that get synchronizes every time I call it - because I may be calling it more than once. So I wrote the wrapper for the future interface which keeps not synchronized local variable for ...
0
votes
0answers
14 views

Fastest way to space-separate a text file into memory

I want to take a text file like: hello my friend and read it into memory, for example as a LinkedList, so I get ...
2
votes
0answers
27 views

Comparing performance of multi- and single - thread search of a maximum number

I have a class that compares the performance of two methods (multi- and single- thread) that searches for maximum number in the string of numbers. I want to improve the performance of a multithreaded ...
-3
votes
1answer
36 views

Given an array of positive integers, find shortest subarray whose sum exceeds a threshold [on hold]

Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0 instead. Example: Input: ...
0
votes
0answers
9 views

Detecting Touch Events on 25 Views in Layout [on hold]

Use case : There are 25 different ImageViews on the screen, check the touch event either MotionEvent.ACTION_DOWN or ...
-2
votes
0answers
17 views

Why is my A-star not working [on hold]

I'm trying to code A* search algorithm but I can't seem to get it to work. I'm copying the pseudocode from wikipedia. My code seems to just search every possible node. Here's my showPath() function: <...
-3
votes
0answers
43 views

return the longest size period of turbulence in A - codility [on hold]

Your team is analysing a flight of a plane. Your task is to find the longest period of turbulence. The height of the plane above the ground is measured once every second of the flight. The ...
-3
votes
0answers
16 views

Effiicient implementation of A* [on hold]

Does anyone know where I can find a fairly efficient implementation of A* for Java? Searching doesn't prove fruitful as search engines ignore or treat the * as a special character which makes ...
-4
votes
0answers
70 views

Which Pattern is Better for Checking Conditions? [on hold]

In most of the methods I write, Especially methods for APIs, I have to check some conditions and then return messages. in general, I can think of two coding styles and patterns to do so. Pattern 1: ...
1
vote
2answers
64 views

Performance of generic VS non-generic method (array generating function)

I'm trying to improve performance for a generic function that turns a string into a multidimensional array. Expected input: A string that was generated by the function ...
0
votes
1answer
66 views

Print odd and even numbers using two threads in Java

I was asked below question in an interview where I need to print out even and odd numbers using two threads so I came up with below code one without synchronization and other with synchronization. <...
0
votes
1answer
30 views

TLE in FOXLINGS SPOJ

Problem Statement: FOXLINGS It’s Christmas time in the forest, and both the Fox and the Wolf families are celebrating. The rather large Fox family consists of two parents as well as \$N\$ (\$...
1
vote
1answer
38 views

Using Enum in java to store a fixed set of mutable objects

I already posted this on Stack Overflow, but someone suggested to post it to Code Review instead. I am creating an Android app that draws to the canvas. For this, ...
-3
votes
1answer
26 views

SFTP a file to remote server, and if successful, also SFTP second file [on hold]

This code has an objective of sending a file1 to a remote server and sends file2 if and only if file1 sftp is successful. //Initiate Class ...
2
votes
2answers
50 views

Given an array of numbers, return array of products of all other numbers

I was recently asked the following interview question over the phone: Given an array of integers, produce an array whose values are the product of every other integer excluding the current index. ...
-5
votes
0answers
32 views

How To Multiply Two Polynomials with java [closed]

I have a problem about java.Just started learning java and my lecturer gave me homework(Multiply 2 Polynomials). Just use String charAt(), String compareTo(), String equals(), String indexof(),string ...
-3
votes
0answers
16 views

OnTouchListener event for the keyboard [closed]

I want to use the OnTouchListener event for the keyboard for example case 301: currentInputConnection.commitText ("1" + "\ n", 1); return; Add this OnTouchListener code
0
votes
0answers
33 views

Function for Replacing Keywords in html

everyone. I have a code for replace text in html by matching them with the keywords provided. I have to run this on many records on my database so It should be memory efficient as possible. ...
-1
votes
0answers
17 views

how to get svg map id of click area in webview [closed]

I am trying to show a dialog when clicking on SVG particular area. The ID is stored in the path of SVG. on click of area retrieve id. How can I get the ID from the path. ...
5
votes
2answers
482 views

Java user roles modeling

I have the following code where I try to manage user roles in teams: Teams have entries, an entry has a creator. This creator is member of a team and has a specified role. Moderators may delete all ...
0
votes
4answers
107 views

Simple OOP Blackjack game in Java

I've created a relatively simple Blackjack game in java. The reason why I decided to do this specific project was to improve my object orientated programming in java. I will post my code so feel ...
1
vote
1answer
55 views
+50

Sign Up layout in android

I have created a sign up layout as image below. Does this part of code looked bad since the dp I used for the floating button are quite large. ...
0
votes
1answer
36 views

How to use java 8 streams to get more readability and performance to this code [closed]

I got a forms list, and it has a tags list. I received from my front end app an array of tags (String), gotta filter these forms by these tags. ...
1
vote
1answer
42 views
0
votes
1answer
37 views

Logging util with static lambda function

So again, I am a bit confused about some notes that i'am getting from my reviewer. I have some kind of utils, to print/prepare log messages. Yea, maybe I am a bit fanatic java 8 lambda guy but I think ...
0
votes
1answer
25 views

Assert LinkedHashMap element in jUnit test [closed]

So I have some test, maybe the given side of that test is not so important to catch the point of my confusion. I wrote ...
0
votes
0answers
16 views

Accounting Reporting Engine [closed]

Problem: We are looking to find a good open source tool in terms of a database that is great at the following; We use Spring boot and Microservice architecture Good with aggregate in i.e sum, ...
2
votes
0answers
59 views

Longest Palindromic Substring challenge

My code is a mix-up between dynamic programming with the HashMap and brute force with the way I reach out the results and substring. I don't know how to optimize my ...
0
votes
0answers
35 views

Make n asynchronous calls from list and invoke method when all calls are completed

I make n asynchronous calls (n being the size of the ArrayList, and indexes passed as ...
1
vote
0answers
94 views

Thread-safe Java class for managing XML files <> domain models

This Java class (aka application component) role is to handle a series of XML files stored in the file system. It must convert those XML files to the corresponding application domain model, and it ...
1
vote
2answers
47 views
0
votes
1answer
36 views

CodingBat warm up: conditionally prepending “not” to a string

I solved this CodingBat problem: Given a string, return a new string where "not " has been added to the front. However, if the string already begins with "not", return the string unchanged. Note: ...
1
vote
1answer
54 views

Bowling kata solution in java

This is my first bowling kata solution in java. I would be very grateful if you say something about that. I want to learn from you to become a better programmer. I think the score method is quite ...
1
vote
0answers
23 views

Drawing sprites and adding new ones

I have some code that draws sprites and and allows new ones to be added. To do this, I use 2 lists: 1 for the sprites that need to be drawn, and one for the new sprites that need to be added to the ...
0
votes
1answer
27 views

Console output of multiplication table

I have a method, which outputs multiplication table sized by given maximum number. Also, it visually separates first row and column from the rest table. How my code could be improved or optimized? ...
0
votes
0answers
31 views

Generics : Is this the right way to implement Generic calculator?

I have implemented a Generic calculator using Generics and lambda expressions. I have written only 2 methods Below is the code : ...
2
votes
3answers
111 views

Fastest way to determine if a number is perfect square

I'm looking for the fastest way to determine if a long value is a perfect square (i.e. its square root is another integer). I was asked this in an interview recently. Here is the very simple and ...
1
vote
1answer
46 views

Handler for several kinds of requests to modify a database in an Android app

I'm working on an Android app, and at one point I need to retrieve a request code in a callback method and perform some database operations depending on the request code. It started out ok when there ...
1
vote
0answers
37 views

Java Multipart text file analysis to zip

So I am working on a project that should take .txt file as an input and analyze words in it (assuming all words are English). Program must run asynchronously. Final output should be multiple .txt ...
2
votes
1answer
50 views

Print out all possible letter combinations a given phone number can represent

I am working on a problem in which given a 7 digit telephone number, we need to print out all possible combinations of letters that each number could represent. I came up with below code and I was ...
1
vote
1answer
45 views

Optimizing loop - Reducing native calls

I am developing Android-Disassembler. I need to optimize the loop below. It is currectly calling native method for each instructions(about 4 bytes). So this loop will be looped about millions of ...
-2
votes
1answer
41 views

Using Reflection to call multiple methods and cast various classes [closed]

I have written the following Reflection code: ...