17. ● JavaScript is ubiquitous in the browser
- Supported in every browser
- Integration with HTML and CSS
● JavaScript is not affected by negative publicity....
17
Unless it is absolutely necessary to run Java in web browsers, disable it as
described below, even after updating to 7u11. This will help mitigate other Java
vulnerabilities that may be discovered in the future.
This and previous Java vulnerabilities have been widely targeted by attackers, and
new Java vulnerabilities are likely to be discovered. To defend against this and future
Java vulnerabilities, consider disabling Java in web browsers…
Programming in the Browser
18. 18
FullStack JavaScript Development
● Reuse of programming skills and teams
● Reuse of skills for both client and server side code
● Reuse of “isomorphic” code components
● Reuse of code for both client and server
● Write One Run Anywhere
● Faster user experience performance
● Use of server side rendering
24. 24
● Average 45% less code required for Node.js implementation
Code required to implement benchmarks
25. 25
var cluster = require('cluster');
var cpus = require('os').cpus().length;
var http = require('http');
if (cluster.isMaster) {
for (var i = 0; i < cpus; i++) {
cluster.fork();
}
cluster.on('death', function(worker) {
console.log("Worker" + worker.pid + "died");
});
} else {
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World!n");
response.end();
}).listen(8080);
}
Writing a HTTP Server
26. 26
var cluster = require('cluster');
var cpus = require('os').cpus().length;
var http = require('http');
if (cluster.isMaster) {
for (var i = 0; i < cpus; i++) {
cluster.fork();
}
cluster.on('death', function(worker) {
console.log("Worker" + worker.pid + "died");
});
} else {
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World!n");
response.end();
}).listen(8080);
}
And Clustering It….
27. 27
● One thread (or process) per connection
- Each thread waits on a response
- Scalability determined by the number of
threads
● Each thread:
- consumes memory
- is relatively idle
● Concurrency determined by number of depot
workers
Typical Java Approach to Scalable I/O
28. 28
● One thread multiplexes for multiple requests
- No waiting for a response
- Handles return from I/O when notified
● Scalability determined by:
- CPU usage
- “Back end” responsiveness
● Concurrency determined by how fast the food
server can work
Node.js approach to Scalable I/O
35. 35
Simple Calculation: 5 + 3
private static void add (int a, int b){
System.out.println(a + b);
}
public static void main(String[] args){
int a = 5;
int b = 3;
add(a, b);
}
> javac app.java
> java app
> 8
var add = function (a, b) {
console.log(a + b);
}
var a = 5;
var b = 3;
add(a, b);
> node app.js
> 8
36. 36
Simple Calculation: 5 + 3
private static void add (int a, int b){
System.out.println(a + b);
}
public static void main(String[] args){
int a = 5;
int b = 3;
add(a, b);
}
> javac app.java
> java app
> 8
var add = function (a, b) {
console.log(a + b);
}
var a = 5;
var b = 3;
add(a, b);
> node app.js
> 8
37. 37
Simple Calculation: 5 + 3
private static void add (int a, int b){
System.out.println(a + b);
}
public static void main(String[] args){
int a = 5;
int b = 3;
add(a, b);
}
> javac app.java
> java app
> 8
var add = function (a, b) {
console.log(a + b);
}
var a = 5;
var b = 3;
add(a, b);
> node app.js
> 8
38. 38
Simple Calculation: 5 + 3
private static void add (int a, int b){
System.out.println(a + b);
}
public static void main(String[] args){
int a = 5;
int b = 3;
add(a, b);
}
> javac app.java
> java app
> 8
var add = function (a, b) {
console.log(a + b);
}
var a = 5;
var b = 3;
add(a, b);
> node app.js
> 8
39. 39
Simple Calculation: 5 + 3
private static void add (int a, int b){
System.out.println(a + b);
}
public static void main(String[] args){
int a = 5;
int b = 3;
add(a, b);
}
> javac app.java
> java app
> 8
var add = function (a, b) {
console.log(a + b);
}
var a = 5;
var b = 3;
add(a, b);
> node app.js
> 8
40. 40
Simple Calculation: 5 + 3
private static void add (int a, int b){
System.out.println(a + b);
}
public static void main(String[] args){
String a = new String(“5”);
int b = 3;
add(a, b);
}
> javac app.java
> java app
> 8
var add = function (a, b) {
console.log(a + b);
}
var a = ‘5’;
var b = 3;
add(a, b);
> node app.js
> 8
41. 41
Simple Calculation: 5 + 3
private static void add (int a, int b){
System.out.println(a + b);
}
public static void main(String[] args){
String a = new String(“5”);
int b = 3;
add(a, b);
}
> javac app.java
> java app
> 8
var add = function (a, b) {
console.log(a + b);
}
var a = ‘5’;
var b = 3;
add(a, b);
> node app.js
> 8
42. 42
Simple Calculation: 5 + 3
private static void add (int a, int b){
System.out.println(a + b);
}
public static void main(String[] args){
String a = new String(“5”);
int b = 3;
add(a, b);
}
> javac app.java
Error: incompatible types: String
cannot be converted to int
add(a, b);
^
var add = function (a, b) {
console.log(a + b);
}
var a = ‘5’;
var b = 3;
add(a, b);
> node app.js
> 8
43. 43
Simple Calculation: 5 + 3
private static void add (int a, int b){
System.out.println(a + b);
}
public static void main(String[] args){
String a = new String(“5”);
int b = 3;
add(a, b);
}
> javac app.java
Error: incompatible types: String
cannot be converted to int
add(a, b);
^
var add = function (a, b) {
console.log(a + b);
}
var a = ‘5’;
var b = 3;
add(a, b);
> node app.js
> 53
46. 46
JavaScript Calculations
> 5 + 3
8
> '5' + 3
'53'
> '5' – 3
2 // String is converted to a number for subtraction
> '5' – '4'
1 // String minus String = Integer??
> '5' + + '4'
54 // Multiple +'s are ok
> 'Hello' + 'World'
'HelloWorld' // Ok, that's expected
> 'Hello' + + 'World'
'HelloNaN' // ...but that isn't
47. 47
JavaScript Calculations
> 5 + 3
8
> '5' + 3
'53'
> '5' – 3
2 // String is converted to a number for subtraction
> '5' – '4'
1 // String minus String = Integer??
> '5' + + '4'
54 // Multiple +'s are ok
> 'Hello' + 'World'
'HelloWorld' // Ok, that's expected
> 'Hello' + + 'World'
'HelloNaN' // ...but that isn't
48. 48
JavaScript Calculations
> 5 + 3
8
> '5' + 3
'53'
> '5' – 3
2 // String is converted to a number for subtraction
> '5' – '4'
1 // Both Strings converted to number for subtraction
> '5' + + '4'
54 // Multiple +'s are ok
> 'Hello' + 'World'
'HelloWorld' // Ok, that's expected
> 'Hello' + + 'World'
'HelloNaN' // ...but that isn't
49. 49
JavaScript Calculations
> 5 + 3
8
> '5' + 3
'53'
> '5' – 3
2 // String is converted to a number for subtraction
> '5' – '4'
1 // Both Strings converted to number for subtraction
> '5' + + '4'
54 // Multiple +'s are ok
> 'Hello' + 'World'
'HelloWorld' // Ok, that's expected
> 'Hello' + + 'World'
'HelloNaN' // ...but that isn't
50. 50
JavaScript Calculations
> 5 + 3
8
> '5' + 3
'53'
> '5' – 3
2 // String is converted to a number for subtraction
> '5' – '4'
1 // Both Strings converted to number for subtraction
> '5' + + '4'
54 // Multiple +'s are ok
> 'Hello' + 'World'
'HelloWorld' // Ok, that's expected
> 'Hello' + + 'World'
'HelloNaN' // ...but that isn't
51. 51
JavaScript Calculations
> 5 + 3
8
> '5' + 3
'53'
> '5' – 3
2 // String is converted to a number for subtraction
> '5' – '4'
1 // Both Strings converted to number for subtraction
> '5' + + '4'
54 // Multiple +'s are ok
> 'Hello' + 'World'
'HelloWorld' // Ok, that's expected
> 'Hello' + + 'World'
'HelloNaN' // ...but that isn't
52. 52
JavaScript Calculations
> 5 + 3
8
> '5' + 3
'53'
> '5' – 3
2 // String is converted to a number for subtraction
> '5' – '4'
1 // Both Strings converted to number for subtraction
> '5' + + '4'
54 // Multiple +'s are ok
> 'Hello' + 'World'
'HelloWorld' // Ok, that's expected
> 'Hello' + + 'World'
'HelloNaN' // ...but that isn't
53. 53
JavaScript Calculations
> 5 + 3
8
> '5' + 3
'53'
> '5' – 3
2 // String is converted to a number for subtraction
> '5' – '4'
1 // Both Strings converted to number for subtraction
> '5' + + '4'
54 // Multiple +'s are ok
> 'Hello' + 'World'
'HelloWorld' // Ok, that's expected
> 'Hello' + + 'World'
'HelloNaN' // ...but that isn't
54. 54
JavaScript Calculations
> 5 + 3
8
> '5' + 3
'53'
> '5' – 3
2 // String is converted to a number for subtraction
> '5' – '4'
1 // Both Strings converted to number for subtraction
> '5' + + '4'
54 // Multiple +'s are ok
> 'Hello' + 'World'
'HelloWorld' // Ok, that's expected
> 'Hello' + + 'World'
'HelloNaN' // Multiple plus must cause String to number conversion
55. 55
JavaScript Calculations
> '5' + - '2'
'5-2' // I can just about see that works
> var x = 3
undefined
> '5' – x + x
5 // Ok, that makes sense
> var x = 3
undefined
> '5' + x - x
50 // What???
56. 56
JavaScript Calculations
> '5' + - '2'
'5-2' // I can just about see that works
> var x = 3
> '5' – x + x
5 // Ok, that makes sense
> var x = 3
undefined
> '5' + x - x
50 // What???
57. 57
JavaScript Calculations
> '5' + - '2'
'5-2' // I can just about see that works
> var x = 3
> '5' – x + x
5 // Ok, that makes sense
> var x = 3
> '5' + x - x
50 // What???
62. 62
Node.js
0
- 4x
+ 1/3x
Node.jsPerformanceRelativetoJava
CPU Bound I/O Bound
* based on TechEmpower benchmark results
Application Performance
(higher is better)
Choosing the Right Language for the Service
Error: incompatible types
ClassCastException
63. 63
Monolithic and Micro Services
Services are small and targeted to their task
Services are organized around capabilities
Services are self contained, storing their own data
“Do one thing, and do it well”
64. 64
● Higher performance for I/O
● Easier async programming
● Fullstack/isomorphic development
Choosing the Right Language for the Service
65. 65
Choosing the Right Language for the Service
● Higher processing performance
● Type safety for calculations
● Transaction processing frameworks
66. 66
● Highly performant, scalable rich web applications
● Highly performant, reliable transaction processing
● Self-contained micro-service components
Choosing the Right Language for the Service
+