I will no longer be accepting answers. Thanks for everyone who participated! I'm glad to hear a lot of people found it to be a fun learning experience
I'm sorry for the delay on the answers. I have been quite busy the past few days, and I'm hoping time frees up in the future. The developers I have chosen will be taking some courses I have designed (and might release in some form..) to ensure they are ready for what's to come!
Once again, thanks for the patience and participation. Great things are to come
____________________
Preface:
So I'm finally getting into the botting/scripting scene. I have quite a bit planned, and it would take quite a while to push these projects out without some help. So I created a short quiz for anyone who may be interested in working with me on some projects. I don't expect all questions to be answered; this is more to get an idea of what you know. I don't mind teaching before bringing you on board, as long as you have a good view on programming already. You can take this quiz even if you aren't interested in working on botting related projects with me. Please send your answers to me in a private message, so others can't copy! A few of these questions may be googlable, so I expect an original answers in your own words. I've bee all up and down google, so don't try to be sneaky Positions are no longer available! Sorry!
Quiz (with answers):
1. What's an efficient way to measure elapsed time in Java? Why?
Anything independent of the system clock (such as System.nanoTime()) to prevent interferences while measuring time (manually changing the clock)
2. What's the difference between java.util.Timer and javax.swing.Timer?
swing.Timer executes on the Event Dispatch Thread. util.Timer executes on a background thread 3. Why do we use synchronization in multithreaded applications?
To ensure sequential memory ordering between a release and subsequent aquire of two locks, and to prevent thread interference 4. What is immutability? Give an original example of immutability
The inability to modify the state of something.
public final class ID {
private final Picture picture;
private final Date experation;
public ID(Picture picture, Date experation) {
}
//no setters; prevent client from modifying
//some immutable classes use setters like this:
public ID changePicture(Picture picture) {
return new ID(picture, experation);
}
} 5. Java divides memory into 3 main sections. What are these sections and what purposes do they serve?
Thread Call Stacks - stores the frames of execution (in the form of methods) as well as local values.
Heap - stores objects and their instance values.
Metaspace - stores class data and static values 6. If you notice your application consuming a lot of memory due to short-lived object not being collected by the GC often, what do you do?
Tune your heap. In this case, shrink your young generation (more specifically, edan space)
7.
class Game implements KeyListener, MouseMotionListener {
private Player player = new Player();
private Dragon enemy = new Dragon();
private boolean[] keys = new boolean[300];
private Point mouseLocation = new Point(0, 0);
public void update() {
if(keys[KeyEvent.VK_UP])
player.move(Direction.NORTH);
// handle other input events
}
public void keyPressed(KeyEvent e) {
keys[e.getKeyCode()] = true;
}
public void keyReleased(KeyEvent e) {
keys[e.getKeyCode()] = true;
}
public void keyTyped(KeyEvent e) {
}
public void mouseMoved(MouseEvent e) {
mouseLocation = e.getPoint();
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
}
This code violates every SOLID principle. List how it violates each principle, and what can be done to fix it.
SRP - Has the responsibility of managing input, managing entities and managing game logic. Break down the responsibilities into their own objects (decomposition)
OCP - Requires modification of the class to update/add behavior to things like game logic and handling input. Create an abstraction and allow the client to specify different "strategies" rather than hardcoding systems into the class
LSP - Game is at risk of being extended upon, allowing the subclass to completely modify the behavior (by overriding critical methods like update, resulting in undesired results when we replace all instances of the base class Game with instances of it's subclasses). Either make the methods final, make the class final, or supply template methods that can't interfere with desired results if misused.
ISP - Forced to declare (but doesn't depend on) keyTyped, mouseEntered, mouseExited. Use KeyAdapter and MouseAdapter
DIP - The enemy is depending on a concrete type (Dragon) rather than an abstraction. Change the field type to something less concrete (Enemy)
8. What is the purpose of String interning, and when is it performed?
To prevent creating multiple String objects that contain the same character values. It's performed when using String literals or when you invoke String#intern() 9. Are Strings read in from an input stream interned?
No. They're transfered using bytes, then recreated into a String manually. 10. What's the difference between a blocking network server, a non blocking network server and an asynchronous network server?
Blocking halts a thread (blocks the thread) attempting to perform network operations until the operation is complete. Will wait if nothing is available (which is why it's considered blocking).
Non-blocking returns a null value if nothing is currently available, removing the need to block.
Asynchronous dispatches network operations (which may block) to "worker" threads (reusable threads) 11. When should you manually invoke System.gc()?
Never. It's a request which can be ignored, usually a sign of a "code smell" 12. List every form of object creation you know of.
The standard "new keyword followed by constructor call"
Reflection
Deserialization
Cloning 13. List some reasons why Singletons is now considered an anti-pattern.
Introduces global state and widely overused in places stronger design (such as dependency injection and aspect orientation) should be applied. 14. How do you properly terminate a Thread?
Let it "die gracefully". If it's continuous, create a (volatile) boolean which allows you to stop it from outside of the thread. If the thread is currently blocking, use interrupt(). 15. Why are wildcard imports frowned upon?
The create ambiguity.
import javax.swing.Timer;
import java.util.Timer;
class MyClass {
Timer timer; //swing or util?
} 16. volatile longs and double are "atomic". Why?
On 32 bit machines (or 64bit with compressed oops enabled), longs and doubles are 64bits long, which cannot fit in a 32bit register. It's split in 2, so we need to create a "happens before" relationship betwee the 2 registers when accessing ghe value. 17. What is double checked locking and when should it be used?
It's a form of synchronization that accounts for the possibility of 2 threads performing interleaved null-checks and variable assignments, accidentally generating a useless object (which gets dereferenced and replace with a new object immediately).
It should be used for lazy initialization in multithreaded environments. The "initialization on demand" idiom is a lot cleaner and should be preferred. 18. What's the difference between a programmer, a developer and a computer scientist?
Programmers understand the syntax of the language, such as specifications (conditionals, loops, objects) but do not fully understand the best use-cases for the specifications; they lack design skills.
Developers understand how to create structured environments. They tend to use tools like UMLs and flow charts to help guide design.
Computer scientists are the philosophers of the conputer world, setting the standards and conventions we use today. They are the innovators, which tries to improve things from how to manage things better at a transistor level, and how to manage things better at a source level (although the latter is rarer, they are the ones who brought us design patterns and philosophies like "Tell, don't ask!") 19. A programmer asks you "I need to get the location of the mouse without GUI. How do I do so?" What would you answer with?
You would need to either access the mouse natively through JNI (or use a third party API like JNativeHook) or simply use MouseInfo.getPointerInfo().getLocation()
20. What is a cross-cutting concern? How should you handle them?
An aspect of programming that applies to all other aspects, which results in coupling irrelevant things (such as Logging, which applies just about everywhere). You should handle them using aspect orientation; Java has frameworks like AspectJ which guides this task 21. What is delta timing?
Measuring responsiveness while measuring elapsed time. Accounts for possible delays and spare time in the current frame, which affects the next to reduce latency 22. Lambdas were intended to replace anonymous classes when working with functional interfaces. Some say it's nothing more than syntactic sugar. Is that true?
No. Lambdas use method handles under the hood, rather than declaring a new class and instantiating it. 23. What's the purpose of method references?
To lower the verbosity of lambda expressions that perform 1 function call.
24. Primitive types are not allowed to be specified for generic type parameters. Some developers choose to use primitive wrapper types to get around this. What should you be aware of when using primitive wrapper types?
Autoboxing and unboxing
25.
List<String> list = new ArrayList<>();
list.add("hey");
for(String string : list) {
list.remove(string);
}
The code above throws a ConcurrentModificationException. Why? What can you do to fix this?
It's modifying the collection directly while it's being iterated over. To avoid this, use a non fail-fast iterator or modify the collection using the iterator (not directly) 26. It's possible for a ClassCastException to occur when initializing a variable with an object that derived from the same class:
class MyType {
}
class OtherClass {
public MyType get() {
return new MyType();
}
}
MyType type = OtherClass.get(); //ClassCastException
What could possibly cause this?
MyType in class Main was loaded by a different classloader than MyType in OtherClass.get(). Types must be loaded by thensame classloader to be identical
27. What are compressed oops
An optimization technique which involves shrinking the size of oops (ordinary object pointers) to 32bit for 64bit machines. Since Java 7, this is enabled by default. Once again, I do not expect you to answer them all. But the more you can answer the better. All profits made would be split equally based on your impact on the project, and will be fully credited for anything you do. Please do not post your answers here so people can't copy; send them to me in a message! Good luck!