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.
0
votes
0answers
12 views
Same computational flow, but different functionalities
Recently I wrote a small piece of code for my project need and the code works fine...
...
-2
votes
0answers
20 views
Condition checked twice, function called twice [on hold]
Although it's working, I don't find my code very elegant:
...
-1
votes
0answers
12 views
How to generate random alpha numeric String to send as OTP [on hold]
I have to implemented mobile verification services through OTP.
Till date i m sending numeric 6 digit OTP through message and its
generating random 6 digit number with out any problem.
...
2
votes
1answer
269 views
SMS sending through Clickatell
I have to implement a method in which i'm passing two arguments as Mobile number and second one is Message to be sent.
I'm using clickatell for the first time and its successfully sending the ...
0
votes
1answer
32 views
Compute all possible attendance records with length n, which will be regarded as rewardable
Given a positive integer n, return the number of all possible attendance records with length n, which will be regarded as rewardable. The answer may be very large, return it after \$\mod 10^9 + 7\$.
...
1
vote
1answer
52 views
Create all combinations of length N from a given alphabet
I have some (very limited) experience in Java 6 and decided to revisit the language. To do so I wrote a solution for the following challenge:
You are given a number N and a string S. Print all of ...
2
votes
2answers
34 views
BinaryGap challenge
A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.
For example, number 9 has binary ...
2
votes
1answer
36 views
Generic OOP Implementation of a Deck-package in Java
I have posted some versions of this question (or at least similar ones) before. But I once again tried to improve it.
The goal is to be able to use this package whether it's for a traditional card-...
-1
votes
0answers
54 views
Placing a player in some zone in a video game, if no player by that name exists anywhere [on hold]
I'm creating a simple online video game and I have a problem on the server side. I need to store associations between players (String username) and the node where ...
-3
votes
0answers
17 views
4
votes
2answers
96 views
Find all words in a dictionary that can be made with a string of characters (Recursion/Binary Search)
I'm working on an algorithm that could take in a string of 20 random characters, and display to the user every word in a dictionary that can be successfully made with those letters, regardless of ...
2
votes
1answer
91 views
Check where the integers are Tprime or not
The objective of the code is to check the given inputs are tprime or not.
Example:
...
2
votes
1answer
58 views
Create a GUI to update parameters of an Object
I have an Glob object which represents a glob of data. It has several parameters like size, the date it was created, who created it, and so on. I'm building a GUI ...
6
votes
2answers
81 views
Connection Pool in Java 8 using Strategy and Factory Pattern
How can I improve the following code and features?
It is based on active911's C++ connection pool.
The full code and unit tests are here : https://github.com/spakai/connection_pool
the README ...
4
votes
2answers
77 views
Tic Tac Toe in Swing
This is a Tic Tac Toe game I wrote in Java (Swing). It fully works when detecting the winner or a tie. I'm wondering if there's any way I can improve it or clean it up.
I'm trying to achieve a 3 by ...
-1
votes
1answer
34 views
Efficient Hangman algorithm [on hold]
I'm trying to find the most efficient algorithm for solving Hangman. For those who are not familiar, it's a game where people need to guess the correct letters in a word.
I've written the following ...
0
votes
1answer
32 views
Foreach vs Iterator [on hold]
I have implemented a trim method which removes objects having empty properties.
This list has average size of 3 or so. Probably, the max length is 7 or 8.
I ...
-1
votes
0answers
22 views
Someone please clear my doubts on this code - linked lists [on hold]
This code creates a simple LinkedList with two nodes. So I am learning Java and this source code is from Tim Buchalka's java course.
ListItem Class
...
0
votes
1answer
48 views
Sum and stock size concurrent code using Executor
The code should parse the input values and calculate the sum and size of particular stocks, using Executor thread pool by dynamically adding the thread count.
Please review the following code for ...
-1
votes
2answers
48 views
Preorder traversal of a tree
I am practising my coding skills on interviewbit. I got one question about preorder (for a tree). This is what I did first:
...
-1
votes
0answers
17 views
Making another method similar to this one java [on hold]
I am trying to find the number of times a character appears in a .txt file so I created a method that can solve for that. But it only solves for one letter that I input. I figure if I can make the ...
5
votes
2answers
95 views
Textual mathematician game
I tried to make my first game with my little experience of programming and using much of the aspects that i learned from my little book. In this game you are a mathematician that has to solve ...
2
votes
0answers
37 views
Using blocking queue to calculate data stream - Generalized
A followup on my previous question Using blocking queue to calculate data stream. This time suppose we have a list of blocking queues as stated in the following manner:
Suppose you have a list of ...
0
votes
1answer
44 views
Reverse an array without affecting special characters
Given a string, that contains special character together with alphabets (‘a’ to ‘z’ and ‘A’ to ‘Z’), reverse the string in a way that special characters are not affected.
Example:
Input: str = "a:b!...
2
votes
0answers
12 views
Computer Algebra System that computes symbolic derivatives
I have a system that parses a mathematical expression String, creates a derivative expression tree, and reconstructs the derived expression into a new ...
0
votes
0answers
27 views
Designing transport service app in Android
I am new to this SE and so bear with me. Sorry for the long post. But this much info is needed to explain !
Background:
I am student and working in one science institute. Our university has bunch of ...
2
votes
4answers
65 views
Book repository for storing books that are accessed by ISBN
I want to implement a book repository using a map where books can be added, removed and updated. Books in this repository should be accessed by their ISBN which is an object property. The books should ...
0
votes
0answers
41 views
Using blocking queue to calculate data stream
I was coding for the following programming question:
Suppose you have two independent blocking queues that will keep getting new data, the new data will always be greater than the last element of ...
4
votes
1answer
57 views
Convert Ternary Expression to a Binary Tree
This is programming question I came across (geeksforgeeks) :
Given a string that contains ternary expressions. The expressions may be nested, task is convert the given ternary expression to a binary ...
2
votes
1answer
52 views
Prime Number related class design
I am creating a class which should contain all the methods related to Prime numbers. Now in that I have to implement a method isPrime() to check the primality of a number. I have to implement that in ...
0
votes
0answers
50 views
Is it bad practice to call a Runnable in a loop? [closed]
I have an abstract class with the abstract method
public abstract void doRender() {}
that is called in a loop repeatedly. I am thinking about removing the ...
4
votes
1answer
50 views
Repeated comparison of sorted subarrays
This question is from a recently concluded competition on Codechef.
You are given an array A of size n, and there are ...
-1
votes
1answer
78 views
Given a string, replace “ is ” with “ is not ”
Given a string, if string has " is "(before and after space) in it:
replace it with "is not".
Example:
Original: This is a string
New: This is not a string
I am implementing it ...
0
votes
1answer
45 views
String methods to manipulate strings [closed]
So im working on an assignment that is asking me to create three methods.
1) displayMenu(), which works just like it sounds... ive got this one working
2) stringFinder() - This method wants a user to ...
5
votes
2answers
412 views
Select top 2 employees based on Grade and Alphabetical Order
Given a list of Employees ( name and grade). Output the names of the top 2 employees selected for a task(sorted based on grade and then alphabetically).
I am using a maxHeap and override the ...
3
votes
2answers
68 views
Checking number of words in a string and assigning them to a value
I am learning Java and trying to write a program to check the number of words in a string and am trying append them to create username and email id. If the number of words in the name are 3 then the ...
5
votes
1answer
118 views
Java OO Design - Reverse Polish Notation Calculator
The following is my implementation of Reverse Polish Notation. I should have mentioned that this is for a coding question, which asked for unary, binary, ternary, etc. operations that also allows user-...
-2
votes
1answer
40 views
the name of the game is TicTacToe [closed]
This is a tic tac toe game that I wrote myself.
I need help breaking down this code such as identifying the methods that I used, etc. For example, I know that I used multiple 2D arrays, but I am ...
4
votes
1answer
55 views
Textual Dictionary Program
I am a beginner in programming and I have written a little program that manages a list of words or strings to examine my understanding of Java and object oriented programming. I am interested in your ...
0
votes
1answer
32 views
ListView + ArrayAdapter: Setting OnClickListener to items
I've recently written a Java program that displays a list of Word objects using a ListView and a custom ArrayAdapter.
I also want to set an OnClickListener on the items that plays an audio file (...
3
votes
1answer
51 views
Inserting a Node in a singly linked list
I'm currently writing an "insert" function for a linked list. The code works but I would like to know if there is any way I can improve this code and at the same time covering all the "special" cases.`...
5
votes
1answer
22 views
Creative triangle stacks using for loops
I was wondering if someone can help me out with achieving the following result (using for loops):
|../\..../\..|
|./\/\../\/\.|
|/\/\/\/\/\/\|
This is the code that I have written:
...
4
votes
1answer
67 views
Random name generator in Java
I wrote working random name generator in Java. Here's my code:
NameGenerator.java:
...
2
votes
1answer
41 views
Glorified Document Chooser
I'm primarily concerned about the design of this MVC application. But will gladly take any suggestions!
Primary objective: Create an interface that allows a user to choose a document from a database.
...
1
vote
0answers
46 views
Synchronous cinema hall, with StampedLock
I'm beginner in Java concurrency mechanism. I wrote some application to train a synchronization between many threads. I noticed that I wrote a lot of if statements, and it looks really ugly. Maby is ...
6
votes
4answers
243 views
Count patterns that start and end with “1”, with 0's in between
A string contains many patterns of the form 1(0+)1 where (0+) represents any non-empty consecutive sequence of 0's. The patterns are allowed to overlap.
For example, consider string "1101001", we can ...
3
votes
2answers
72 views
Segregate an array of 0s and 1s
I think that my code contains a lot of if and else statements that are probably not required.I suppose that this code could be condensed to a shorter form where the logic applied would look clearer ...
0
votes
1answer
35 views
Building object from unusually custom object
Say we have this method which is my main concern for this question. It's really not optimal way to get values out of it. Each time I'm running through list twice for to just get one field value for <...
2
votes
1answer
48 views
Find the length of the longest Common Subsequence
I have a DP based implementation for the Longest Common Subsequence(LCS) problem
to find the length of the LCS.
I wanted to know if there is room for improvement in terms of efficiency(space/time).
...
0
votes
1answer
59 views
Java merge sort implementation efficiency
The problem was to implement merge sort algorithm in Java, where I recursively split and merge the array until I have the sorted array. Even though the code is working properly, I feel it is verbose ...