Pig
UDF
Map Reduce
When you do join in Hive, what's going on behind the scene.
Redis
1. What is Kafka:
Scala based distributed messaging system .
2. What is Cassandra:
A distributed NOSQL database(Key-Value Document-based), it doesn't support MapReduce
3. What is Redis:
In memory data structure store. Let's say you have 400TB data and you want to access them very fast
in a local variable. you want to use Redis.
Tuesday, June 27, 2017
news source
https://www.bloomberg.com/markets
http://www.cnbc.com/investing/
http://www.reuters.com/news/archive/marketsNews?view=page&page=1&pageSize=100
http://www.marketwatch.com/
https://www.google.com/finance/market_news?ei=QDonWfmzNc6amAHqpLGQDQ
http://www.cnbc.com/investing/
http://www.reuters.com/news/archive/marketsNews?view=page&page=1&pageSize=100
http://www.marketwatch.com/
https://www.google.com/finance/market_news?ei=QDonWfmzNc6amAHqpLGQDQ
Sunday, June 25, 2017
Java Spring/Hibernate Questions
1. Pros and Cons about Sping
Cons:
Huge, I wouldn't put 3000 jars in my hobby project
Slower than other DI, like juice
getting more and more complex in annotation and XML
Pros:
decoupling
readable
2. What are the common types of Dependency Injection:
Constructor-based:
Use for mandatory injection
Setter-based:
invoking a no-argument constructor or no-argument static factory method to instantiate your bean.
Use for optional injection
1. Inject differently
2. Constructor guarantees injection while setter injection can be failed
3. Setter injection can detect circular dependency by throwing ObjectCurrentlyInCreationException
http://javarevisited.blogspot.com/2012/11/difference-between-setter-injection-vs-constructor-injection-spring-framework.html
3. What is the scope of Java Spring bean?
singleton: one object/ container prototype/request: one object/ bean is requested or HTTP requested
Cons:
Huge, I wouldn't put 3000 jars in my hobby project
Slower than other DI, like juice
getting more and more complex in annotation and XML
Pros:
decoupling
readable
2. What are the common types of Dependency Injection:
Constructor-based:
Use for mandatory injection
Setter-based:
invoking a no-argument constructor or no-argument static factory method to instantiate your bean.
Use for optional injection
1. Inject differently
2. Constructor guarantees injection while setter injection can be failed
3. Setter injection can detect circular dependency by throwing ObjectCurrentlyInCreationException
http://javarevisited.blogspot.com/2012/11/difference-between-setter-injection-vs-constructor-injection-spring-framework.html
3. What is the scope of Java Spring bean?
singleton: one object/ container prototype/request: one object/ bean is requested or HTTP requested
Java GC/Memory Model Questions
GC
1. What are the six reachability states in Java?
Strongly reachable objects
Softly reachable objects
Weakly reachable objects
(Weak Refer: a reference that doesn't protect the referenced object from collection)
Resurrect-able reachable objects
Phantomly reachable objects
Unreachable reachable objects
https://stackoverflow.com/questions/299659/what-is-the-difference-between-a-soft-reference-and-a-weak-reference-in-java
2. How does GC work and when do JVM perform GC


What is Eden: newly created objects will be putted here
What is survivor: objects which survived Eden GC
Why there are two survivors: Only put things to old generation if objects survives many GC
What are the major GCs:
Minor GC: Clean eden, move Eden to survivors
When to collet:
Minor When don't have enough space to allocate new space in Eden
Major: New candidate for Old generation is bigger than free space in Old generation
What to collect:
Go through GC roots. Any unreachable objects will be marked as OK to collect
What happened:
stop some threads and finalize some objects
1. What are the six reachability states in Java?
Strongly reachable objects
Softly reachable objects
Weakly reachable objects
(Weak Refer: a reference that doesn't protect the referenced object from collection)
Resurrect-able reachable objects
Phantomly reachable objects
Unreachable reachable objects
https://stackoverflow.com/questions/299659/what-is-the-difference-between-a-soft-reference-and-a-weak-reference-in-java
2. How does GC work and when do JVM perform GC


What is Eden: newly created objects will be putted here
What is survivor: objects which survived Eden GC
Why there are two survivors: Only put things to old generation if objects survives many GC
What are the major GCs:
Minor GC: Clean eden, move Eden to survivors
Full GC: Clean entire heap space
When to collet:
Minor When don't have enough space to allocate new space in Eden
Major: New candidate for Old generation is bigger than free space in Old generation
What to collect:
Go through GC roots. Any unreachable objects will be marked as OK to collect
What happened:
stop some threads and finalize some objects
Java Multithread Questions
1. What is the difference between Callable and Runnable?
Runnable is Old and has been there for a while.
People knows how to run at the beginning. Once she runs away, you don't get back from her.
Callable can return a result and cannot throw a checked exception
2. How to detect deadlock in Java?
Use ThreadMXBean class. It has a method called findDeadlockedThreads.
3. Difference between static variable and volatile variable in Multithread java
Declaring a static variable in Java, means that there will be only one copy, no matter how many objects of the class are created. However, threads may have locally cached values of it.
When a variable is volatile and not static, there will be one variable for each Object.
Runnable is Old and has been there for a while.
People knows how to run at the beginning. Once she runs away, you don't get back from her.
Callable can return a result and cannot throw a checked exception
2. How to detect deadlock in Java?
Use ThreadMXBean class. It has a method called findDeadlockedThreads.
3. Difference between static variable and volatile variable in Multithread java
Declaring a static variable in Java, means that there will be only one copy, no matter how many objects of the class are created. However, threads may have locally cached values of it.
When a variable is volatile and not static, there will be one variable for each Object.
Java OOP/Core Java Questions
1. What is JVM and is it platform independent:
JVM is Java Virtual Machine and is responsible for converting byte code into machine readable code.
2. Difference between JVM and JDK and JRE:
JVM is used to execute bytecode JDK is for dev
JRE = JVM + java binary libraries
If u wanna run Java program, u need JR
3. Which class is the superclass of all classes?
java.lang.Object is the root class for all the java classes and we don’t need to extend it.
3.5 Difference between Extends / Implements
Implements is for implementing an interface (can implement multiple interfaces)
Extends is for extending a class(can only extends one )
Interface method generally doesn't have implementation.
4.Why Java doesn’t support multiple inheritance(extends a class )?
Because of Diamond Problem
Diamond Problem:

Let's say we have a method in A. B and C both override that method. Should D take B's implementation or C's implementation
5. What is path and classpath:
path is sys environment
classpath is used for Java to locate class files
6. What is overload and overriding:
Overload means same method signature with different parameter
Override, one in parent class and another in child class. Use to override method in parent class
7. Can we overload main method:
yes, we can have multiple method named with main, but only public static void main(String args[])
will be treated as main method
8. Can we have more than one public class in one java source file
no, only one public Java class is allowed in one java file
9. What is final/finally/finalize keyword:
For class: to make sure no other class can extend it, String class is final and can't be extended
For method: child class cannot override parent's method
For variable: make sure variable can only be assigned once, however, the state of the variable can
be changed. For example, we can assign a final variable to an object only once, but the object
variable can be changed later on
Java interface variables are by default final and static
Finally block: put the code which will always be executed even if any exception thrown by the try
catch block.
Finalize: Tell JVM it is good to do GC
10. What is static keyword:
For method: A static method can only access that class' static variable and invoke
For variable: can be used within class level to make it global. all objects will share the same variable
10.5 What is super keyword:
Access super class method you have overridden in child class
Invoke superclass's consturctor
11. What is Interface:
Provide a way to achieve abstraction in java and used to define the contract for the subclasses to implement. Interface method doesn't have implementation
12. What is an abstract class:
Abstract classes have some default method implementations for subclasses.
An abstract class can have abstract method(no body) and real method(with body)
Abstract class cannot be instantiated
13. Abstract class VS Interface:
Abstract class can have method implementation while Interfaces can't
A class can implements >1 interfaces while can only extends one abstract class
Abstract uses abstract to define abstract class while interface uses interface to define interface
14. Can Interface implement/extend another interface:
Interface can implement >2 interfaces
15. Four elements of OOP
EA has a good IP
Encapsulation: hide data and implementation from outside by using setter/getter
Abstraction: It is a concept. One class should not know detail of another to use it.
Inheritance: Extends/Implement. Classes can be derived from other classes.
Polymorphism: Overload/Override. One name can have multiple implementation
16. What is default constructor?
Compiler automatically creates default no-args constructor for classes. If there are other constructors defined, the compiler won't create default constructor.
17. Can we have try (possible with finally)without catch block:
Yes.
18 What is GC?
Look through heap memory and delete objects not in use.
19 What is mock object?
Mocking or mock objects is a unit testing strategy. Replace code chunk with dummy codes. For example, if you want to test a method in class A. Class A depends on class B/C/D, you can create some dummy objects b,c,d to testing class A instead of implementing class B/C/D
20. How to create immutable objects?
JVM is Java Virtual Machine and is responsible for converting byte code into machine readable code.
2. Difference between JVM and JDK and JRE:
JVM is used to execute bytecode JDK is for dev
JRE = JVM + java binary libraries
If u wanna run Java program, u need JR
3. Which class is the superclass of all classes?
java.lang.Object is the root class for all the java classes and we don’t need to extend it.
3.5 Difference between Extends / Implements
Implements is for implementing an interface (can implement multiple interfaces)
Extends is for extending a class(can only extends one )
Interface method generally doesn't have implementation.
4.Why Java doesn’t support multiple inheritance(extends a class )?
Because of Diamond Problem
Diamond Problem:
Let's say we have a method in A. B and C both override that method. Should D take B's implementation or C's implementation
5. What is path and classpath:
path is sys environment
classpath is used for Java to locate class files
6. What is overload and overriding:
Overload means same method signature with different parameter
Override, one in parent class and another in child class. Use to override method in parent class
7. Can we overload main method:
yes, we can have multiple method named with main, but only public static void main(String args[])
will be treated as main method
8. Can we have more than one public class in one java source file
no, only one public Java class is allowed in one java file
9. What is final/finally/finalize keyword:
For class: to make sure no other class can extend it, String class is final and can't be extended
For method: child class cannot override parent's method
For variable: make sure variable can only be assigned once, however, the state of the variable can
be changed. For example, we can assign a final variable to an object only once, but the object
variable can be changed later on
Java interface variables are by default final and static
Finally block: put the code which will always be executed even if any exception thrown by the try
catch block.
Finalize: Tell JVM it is good to do GC
10. What is static keyword:
For method: A static method can only access that class' static variable and invoke
For variable: can be used within class level to make it global. all objects will share the same variable
10.5 What is super keyword:
Access super class method you have overridden in child class
Invoke superclass's consturctor
11. What is Interface:
Provide a way to achieve abstraction in java and used to define the contract for the subclasses to implement. Interface method doesn't have implementation
12. What is an abstract class:
Abstract classes have some default method implementations for subclasses.
An abstract class can have abstract method(no body) and real method(with body)
Abstract class cannot be instantiated
13. Abstract class VS Interface:
Abstract class can have method implementation while Interfaces can't
A class can implements >1 interfaces while can only extends one abstract class
Abstract uses abstract to define abstract class while interface uses interface to define interface
14. Can Interface implement/extend another interface:
Interface can implement >2 interfaces
15. Four elements of OOP
EA has a good IP
Encapsulation: hide data and implementation from outside by using setter/getter
Abstraction: It is a concept. One class should not know detail of another to use it.
Inheritance: Extends/Implement. Classes can be derived from other classes.
Polymorphism: Overload/Override. One name can have multiple implementation
16. What is default constructor?
Compiler automatically creates default no-args constructor for classes. If there are other constructors defined, the compiler won't create default constructor.
17. Can we have try (possible with finally)without catch block:
Yes.
18 What is GC?
Look through heap memory and delete objects not in use.
19 What is mock object?
Mocking or mock objects is a unit testing strategy. Replace code chunk with dummy codes. For example, if you want to test a method in class A. Class A depends on class B/C/D, you can create some dummy objects b,c,d to testing class A instead of implementing class B/C/D
20. How to create immutable objects?
- Don’t provide any methods that modify the object’s state (known as mutators).
- Ensure that the class can’t be extended.
- Make all fields final.
- Make all fields private. This prevents clients from obtaining access to mutable objects referred to by fields and modifying these objects directly.
- Make defensive copies. Ensure exclusive access to any mutable components.
21. How sets avoid duplicates internally ?
It roughly works like this
if (!collection.contains(element))
collection.add(element);
And the contains method, would use equals/hashcode.
In TreeSet, the elements are stored in a Red-Black Tree,
In HashSet, uses a HashMap to traverse buckets and use equals() to check equality
22. What is TreeMap
The TreeMap class implements the Map interface by using a tree. A TreeMap provides an efficient means of storing key/value pairs in sorted order, and allows rapid retrieval.
A tree map guarantees that its elements will be sorted in an ascending key order
Wednesday, June 14, 2017
Dairy
今天Lockheed Martin来电话了,说因为身份问题,把offer要收回去。HR真的太不专业了,浪费了我和公司的时间。还好我提前问了,要不然我真的drop了two week然后他再和我说这个,我就傻眼了。看来F35花400多亿美金还造不出来。是有原因的。
今天早上电面了彭博。题目本身不难但也不简单。考了两个题目。
1. Sliding Windows 变种
2. LRU
拿到题目有点紧张是真的。
[Leetcode]Best Time to Buy and Sell Stock 1
https://leetcode.com/problems/best-time-to-buy-and-sell-stock/#/description
The idea here is keep a currMin and iterate through whole prices list. Through each iteration, we update currMin and currMaxProfit
Tuesday, June 13, 2017
Fibonacci Recursion and Iterative
First 9 Fibonacci number
1 1 2 3 5 8 13 21 34
[Leetcode]Largest Number
https://leetcode.com/problems/largest-number/#/description
Given a list of non negative integers, arrange them such that they form the largest number.
For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.
For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.
1. A naive approach would be put 9 in front of 5, 4, 3. but that would be way too complex for the case when we have 5656 and 56. The right approach is to compare numbers like that. Let’s say we have [3, 34]. We combine them to 343 and 334. 343 is larger than 334 so our list will be sorted to [34, 3]
2. define your own comparator, 1 if a > b, -1 if a < b 3. Syntax for using customized comparator in sorted() sorted(list, cmp = self.methodName)
2. define your own comparator, 1 if a > b, -1 if a < b 3. Syntax for using customized comparator in sorted() sorted(list, cmp = self.methodName)
[Leetcode]Swap Nodes in Pairs
https://leetcode.com/problems/largest-number/
1. in Line 17 , you need to have a clear mind what is the new value for curr. curr = one will do the work but might be confusing. curr = curr.next.next is sound and safe
Subscribe to:
Comments (Atom)