JRE: Java runtime environment, consists of JVM (abstract computing machine, have an instruction set that uses memory), Java platform core classes, supporting Java platform libs.
JIT: just in time compiler, improvement execution performance, especially for long running, compute-intense programs. If JIT env var is on, JVM passes .class file to JIT. JIT compiles the bytecode to native code (e.g. Intel machine code) for the platform on which it is running.
Native code: the code that is compiled to run with a particular processor and its set of instructions. Unmanaged code: program that get directly compiled into machine code, like C, C++. Managed code, program runs in a virtual environment, like Java, C#.
CGI files: common gateway interface, generate dynamci content on web pages and web applications. When implemened on web servers, provide an interface between web servers and programs (CGI scripts) that generate the web content. Containing code in perl, etc.
RSA: public key cryptographic algorithm. Bases on the difficulty of interger factorization of large numbers.
Open window from command line in Ubuntu: nautilus .
Read input from stdin c++:
string s = ""; getline(cin, s); // Read entire line. Allow spaces // Or cin >> s; // read a word. Do not allow spaces.
Primary data types are allocated on the stack and dynamic data types are allocated on the heap. A char array is allocated on the stack, if return it from a function, the user that uses this char array may not see it because after function, the stack is cleared out.
Determine if two integers have the same sign: (dividend ^ divisor) >> 31.
1 GB = 2^10 MB = 2^20 KB = 2^30Byte. 4 GB is about 4 billion (2^32) bytes.
P and NP: P–>An exclusive club a problem can join if there exists a polynomial-time algorithm to solve it. (shortest path, minimum spanning tree). NP–> A less exclusive club for algorithmic problems whose solutions can be verified in polynomial-time. (TSM, satisfiability, vertex cover) (P get free pass to NP).
Lexicographical ordering: First, sort by length; Then, sort by dictionary order.
Bit shift in C++: bit shift returns a value.
int n = 1;
n = n << 1; // Correct, multiple n by 2, thus, n is 2
n << 1; // Won't update n, n is still 1
Copy constructor in c++: ClassName(const ClassName& otherObj);
. Since pass by reference, members can be access using “.” . Such as int x = otherObj.value;
For class with pointers data members, usually
— Include destructor;
— Include copy constructor;
— Overload assignment operator;
Polymorphism Java vs C++: Java: routines are overridable by default. Routine must declared as final to avoid derived classes overriding it. C++: routines are not overridable by default. Routine must declared as virtual in base class to be overridable.
Abstraction vs Encapsulation: Abstraction: manage complexity by providing models that allows you to ignore implementation details. Encapsulation: prevents you from looking at details even if you want to. Friend classes violate encapsulation.
Abstract Data Type: a collection of data and operations that work on that data.
Asynchronous: Events occur independently of the main program flow. Actions executed in a non-blocking scheme, allowing the main program flow to continue processing (AMD). Synchronous vs asynchronous: a synchronous operations block a process until operation is finished. An asynchronous operation is non-blocking and only initiate the operation.
Pass by reference and by value in Java: Java does manipulate objects by reference, and all object variables are references. However, Java doesn’t pass method arguments by reference; it passes them by value.
StringBuffer: thread safe (manipulating shared data structure guarantee safe execution of multiple threads at the same time). StringBuilder: non thread safe. Both create immutable strings in Java.
Better rounding: add 0.5 before truncating to nearest integer results a better rounding. Instead 9.99->9, we have 9.99 + 0.5 -> 10.
Endless loop: for(;;) { statement; }
Cross Compiler: a compiler that is capable of creating executable for a platform other than the one on which the compiler is running. Often used to compile code for embedded systems since it is infeasible to do the compiling on such systems.
Native code (machine code): atomic instructions (operations, jump) executed directly by a CPU. However, bytecode is executed by an interpreter.
Interpreter: a computer program that executes instructions written in a programming language. 1) executes source code directly (Lisp); 2) translates source to efficient intermediate code and execute (Perl, Python, Matlab, Ruby); 3) execute precompiled code.
Memory leak occurs:
- when a compute program consumes memory but is unable to release it back to the operating system.
- when an object is stored in memory but cannot be accessed by the running code.
Check if x is power of 2:
int isPowerOfTwo (unsigned int x) { while (((x % 2) == 0) &amp;amp;amp;&amp;amp;amp; x &amp;amp;gt; 1) /* While x is even and &amp;amp;gt; 1 */ x /= 2; return (x == 1); }
CLASSPATH
In order to include certain jar files for java to use, you need to set environment variable CLASSPATH
to include the path to that jar file.
export CLASSPATH=~/myjarfile.jar:$CLASSPATH
Parameters:
- Formal parameter: the variable as found in the function definition (parameter).
- Actual parameter: the actual value passed (argument).
Function like macro:
#define getmax(a, b) a>b?a:b
De facto standard:
A de facto standard is a system that has achieved a dominant position by public acceptance or market forces.
Anonymous namespace in C++:
namespace{ ... }
Anonymous namespaces are to C++ what the static
keyword is to C. It makes the things declared inside of the anonymous namespace visible only to the current file.