Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 13728

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 vote

How to write this program efficiently and much shorter?

You need to compile and interpret a programming language, even though your language is rather simple expression language. Write recursive descent parser or use ANTLR.
Alexei Kaigorodov's user avatar
1 vote
Accepted

Is this the right way to retrieve all the fields from any Object?

In principle, your code is correct (provided you really do not want to deal with fields in superclass). But it can be optimized: inside the first loop, you already have fields so there is no need to s …
Alexei Kaigorodov's user avatar
3 votes
Accepted

Java - Object declaration out of while loop

At the bytecode level, there is no such thing as inner block. All local variables are declared at the scope of the method. As a result, both your variants should produce equivalent bytecode. To make s …
Alexei Kaigorodov's user avatar
0 votes

Replicating C#-style events in Java using reflection

In Java, typical approach is to represent listener as a single object, which implements specific interface. …
Alexei Kaigorodov's user avatar
2 votes

Resource Pool implementation with ReentrantLock and Condition

No need to use synchronization in the constructor - at the moment of creation the object is not yet visible to any concurrent thread. Declare a field Constructor<R> resourceConstructor and in the con …
Alexei Kaigorodov's user avatar
4 votes

Oriented-object approach on how to control different classes cleanly

CommandManager referes to a CommandControllable, and CommandControllable refers to a set of CommandManagers. Who controls who? Such loops in dependency graph should be avoided. Then, think if the Act …
Alexei Kaigorodov's user avatar
1 vote

Moving from normal threads to ExecutorService thread pools in java

As I understand, you're still using blocking I/O. So each connection still consumes the whole thread, and there is little difference whether this thread was created manually or taken from a pool. To …
Alexei Kaigorodov's user avatar
3 votes
5 answers
490 views

Does this Actor implementation has synchronization problems?

As a part of a job test, I wrote following implementation of the Actor execution model: import java.util.LinkedList; import java.util.Queue; import java.util.concurrent.Executor; public abstract clas …
Alexei Kaigorodov's user avatar
3 votes

Find the uncommon elements from two sets

This should work faster: private void findUnCommon{ Set<Integer> a = new HashSet<>(Arrays.asList(1, 2, 3, 4)); Set<Integer> b = new HashSet<>(Arrays.asList(3, 4, 5, 6)); Set<Integer> re …
Alexei Kaigorodov's user avatar
1 vote

Optimize Conway's Game of Life

instead of universeDoubleBuffer[someIndex] use 2 separate fields and 2 separate local variables, swapping values of local variables each step of the loop. Thus one expensive array access operation is …
Alexei Kaigorodov's user avatar
2 votes

Bidirectional hash map in Java

it could be done in much less code out of 2 maps: HashMap<K,V> and HashMap<V, List<K>>.
Alexei Kaigorodov's user avatar
1 vote
Accepted

Closable BlockingQueue

read or write methods requires 3 synchronization operations (2 semaphore operations and one access to the LinkedBlockingQueue. If you use synchronized methods (or locking with ReentrantLock) and non- …
Alexei Kaigorodov's user avatar
0 votes

Solving Diophantine equations

When you compare sorted lists, you want to find identical values. It can be done in one pass, without nested loops. Take first values from both lists and compare. If values are equal, only then make a …
Alexei Kaigorodov's user avatar
0 votes

Evaluating a math expression given in string format

To make your code short, understandable, elegant, maintainable, and fast, I recommend to: implement separately syntax and semantics for syntax part, construct recursive descent parser. read somethi …
Alexei Kaigorodov's user avatar
0 votes

Unbounded, High-performance(?), Generic, Thread-Safe(?), BatchedCircularQueue

0) - agreed with toto2 2) - no. You did not say how many messages per second your buffer can pass through itself (and did not provide test code to run), but high performance counts in millions, and I …
Alexei Kaigorodov's user avatar

15 30 50 per page