-
Notifications
You must be signed in to change notification settings - Fork 1
Asynchronous JavaScript and XML
Javascript to make a CROS Domain XHR call:
XMLHttpRequest (XHR) is an API in the form of an object whose methods transfer data between a web browser and a web server. The object is provided by the browser's JavaScript environment.
Cross-Origin Resource Sharing (CORS) is a W3C spec that allows cross-domain communication from the browser.
https://mdn.mozillademos.org/files/14295/CORS_principle.png
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/cors_principle.png

Creating the XMLHttpRequest object Client | Browser Example::
- Origin
- Access-Control-Request-Method
- Access-Control-Request-Headers
var method = GET;
var url = "https://developer.mozilla.org/en/docs/Web/HTTP/Access_control_CORS";
var xhr = new XMLHttpRequest();
xhr.open(method, url, true);
xhr.setRequestHeader('X-PINGOTHER', 'pingpong');
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
var form_urlencoded = encodeURIComponent("Sensitive Information");
xhr.send("queryParamUserData="+form_urlencoded+
"&queryParamDate="+ new Date() );
xhr.onreadystatechange = function() {
// xhr.onload = function() {} When the request has successfully completed.
if (xhr.readyState == 4 && xhr.status == 200) {
var responseText = xhr.responseText;
console.log(responseText);
// process the response.
}
}
JAVA Response headers:
Unlike simple requests (discussed above), "preflighted"
requests first send an HTTP request by the OPTIONS method to the resource on the other domain, in order to determine whether the actual request is safe to send.
https://www.html5rocks.com/static/images/cors_flow.png
- Access-Control-Allow-Origin
- Access-Control-Allow-Credentials
- Access-Control-Expose-Headers
- Access-Control-Max-Age
- Access-Control-Allow-Methods
- Access-Control-Allow-Headers
private void addCorsHeader(HttpServletResponse response) {
// An Access-Control-Allow-Origin (ACAO) header with a wild-card that allows all domains:
response.addHeader("Access-Control-Allow-Origin", "*");
//CORS also supports other types of HTTP requests [ GET, POST, PUT, DELETE, OPTIONS, HEAD ]
response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
// The list of non-standard | custom HTTP headers.
response.addHeader("Access-Control-Allow-Headers", "X-PINGOTHER, Origin, X-Requested-With, Content-Type, Accept");
// Tell client that this Pre-flight info is valid for 86400 seconds is 24 hours.
response.addHeader("Access-Control-Max-Age", "86400");
}
public void sendResponse( String text ) {
PrintWriter pw = response.getWriter();
pw.print( text );
}
https://mdn.mozillademos.org/files/14289/prelight.png
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/preflight_correct.png
In a class-based object-oriented language, in general, state is carried by instances, methods are carried by classes, and inheritance is only of structure and behavior. Basic, Refactoring Techniques
Method signature: It consists of method name and parameter list (number/type/order of the parameters). methodName(parametersList y)
. An instance method in a subclass with the same signature
and return type
as an instance method in the super-class overrides the super-class's method.
Java OOP concepts
Class - Collection of a common features of a group of object [static/instance Fields, blocks and Methods]
Object - Instance of a class (instance fields)
Abstraction - Process of hiding complex info and providing required info like API, Marker Interfaces ...
Encapsulation(Security) - Class Binding up with data members(fields) and member functions.
Inheritance (Reusability by placing common code in single class)
1. Multilevel - {A -> B -> C} 2. Multiple - Diamond problem {A <- (B) -> C} [Java not supports] 3. Cyclic {A <-> B} [Java not supports]
* Is-A Relation - Class A extends B
* Hash-A Relation - Class A { B obj = new B(); } - (Composition/Aggregation)
Polymorphism (Flexibility) 1. Compile-Time Overloading 2. Runtime Overriding [Greek - "many forms"]
int[] arr = {1,2,3}; int arrLength = arr.length; // Fixed length of sequential blocks to hold same data type
String str = "Yash"; int strLength = str.length(); // Immutable Object value can't be changed.
List<?> collections = new ArrayList<String>(); int collectionGroupSize = collections.size();
Map<?, ?> mapEntry = new HashMap<String, String>();
Set<?> keySet = mapEntry.keySet(); // Set of Key's
Set<?> entrySet = mapEntry.entrySet(); // Set of Entries [Key, Value]
// Immutable Objects once created they can't be modified. final class Integer/String/Employee
Integer val = Integer.valueOf("100"); String str2 = String.valueOf(100); // Immutable classes
final class Employee { // All Wrapper classes, java.util.UUID, java.io.File ...
private final String empName; // Field as Final(values can be assigned only once) Only getter functions.
public Employee(String name) { this.empName = name; }
}
Native Java Code for Hashtable.h
, Hashtable.cpp
SQL API
.
You can check your current JDK and JRE versions on your command prompt respectively,
- JDK
javac -version [C:\Program Files\Java\jdk1.8.0_121\bin]
o/p:javac 1.8.0_121
- JRE
java -version
[C:\Program Files\Java\jdk1.8.0_121\bin]
o/P:java version "1.8.0_102"
JAVA_HOME - Must be set to JDK otherwise maven projects leads to compilation error. [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
C:\Softwares\OpenJDK\
, 7-zip
Fatal error compiling: invalid target release: JRE and JDK must be of same version
1.8.0.XXX
Disable TLS 1.0 and 1.1
security-libs/javax.net.ssl
: TLS 1.0 and 1.1 are versions of the TLS protocol that are no longer considered secure and have been superseded by more secure and modern versions (TLS 1.2 and 1.3).
Core Java
-
Java Programming Language Basics
- Object, Class, Encapsulation, Interface, Inheritance, Polymorphism (Method Overloading, Overriding)
- JVM Architecture, Memory Areas
- JVM Class Loader SubSystem
- Core Java Interview Questions & Programs
- Interview Concepts
Stack Posts
- Comparable vs Comparator
- Collections and Arrays
-
String, StringBuffer, and StringBuilder
- String reverse
- Remove single char
- File data to String
- Unicode equality check Spacing entities
- split(String regex, int limit)
- Longest String of an array
-
Object Serialization
- Interface's Serializable vs Externalizable
- Transient Keyword
-
implements Runnable
vsextends Thread
- JSON
- Files,
Logging API
- Append text to Existing file
- Counting number of words in a file
- Properties
- Properties with reference key