#Java Generics using Wildcard Arguments
Explore tagged Tumblr posts
itsbeyondsimple-blog · 6 years ago
Photo
Tumblr media
Is your mind stuck in between and feel frustrated ?? Don’t worry just start clear your queries at Its beyond simple and implement it now to solve the errors easily. 
0 notes
rlxtechoff · 3 years ago
Text
0 notes
psychicanchortimemachine · 4 years ago
Text
Learning  Typescript  In  30  Minutes
Today we're getting to take a glance at matter, a compile-to-JavaScript language designed for developers to build massive and sophisticated apps. It inherits several programming ideas from languages like C# and Java that add a lot of discipline and order to the otherwise terribly relaxed and free-typed JavaScript.  This tutorial is aimed toward those who are fairly skilful in JavaScript however still beginners are once it involves matter. We've lived most of the fundamentals and key options whereas together with voluminous examples with commented code to assist you see the language in action. Let's begin!
Benefits  of Using  Typescript
JavaScript is pretty smart because it is and you'll surprise Do I actually ought to learn Typescript? Technically, you are doing not ought to learn matter to be a decent developer, the general public do exactly fine while not it. However, operating with matter undoubtedly has its benefits: Due to the static writing, code written in matter is a lot of sure, and is usually easier to right.
Makes it easier to arrange the code base for terribly massive and complex apps because of modules, namespaces and robust OOP support. Typescript contains a compilation step to JavaScript that catches every kind of errors before they reach runtime and break one thing. The approaching Angular two frameworks is written in matter and it's counseled that developers use the language in their daily use also.
The last purpose is really the foremost necessary to several individuals and is that the main reason to induce them into matter. Angular two is one amongst the most popular frameworks right away and though developers will use regular JavaScript with it, a majority of the tutorials and examples square measure written in TS. As Angular two expands its community, it's natural that a lot of and a lot of individuals are going to be learning matter.
Recent rise of Typescript’s popularity, data from Google Trends.  Installation
Installing TypeScript
You will need Node.js and Npm for this tutorial. Go
here
if you don't have them installed.The easiest way to setup Typescript is via
npm
. Using the command below ,we can install the Typescript package globally, making the TS compiler available in all of our projects:
npm install -g typescript
Try opening a terminal anywhere and running tsc -v to see if it has been properly installed.
tsc -v Version 1.8.10
Text editors
Text Editors with TypeScript Support
TypeScript is an open-source project however is developed and maintained by Microsoft and intrinsically was originally supported solely in Microsoft's Visual Studio platform. Nowadays, there are heaps additional text editors and day that either natively or through plugins provide support for the matter syntax, auto-complete suggestions, error catching, and even integral compilers.
1.  
Visual Studio Code
- Microsoft's other, lightweight open-source  code editor. TypeScript support is built in.2.   Official
Free Plugin
for Sublime Text.3.    The latest version of
WebStorm
comes with built in support.4.  
More
including Vim, Atom, Emacs and others
Compilation
Compiling to JavaScript
TypeScript is written in .ts files (or .tsx for JSX), that cannot be used directly within the browser and want to be translated to vanilla .js first. This compilation method is often worn out variety of various ways: ·  In the terminal using the previously mentioned command line tool tsc.·  Directly in Visual Studio or some of the other IDEs and text editors.·  Using automated task runners such as
gulp
.
We found the first way to be easiest and most beginner friendly, so that's what we're going to use in our lesson.The following command takes a TypeScript file named main.ts and translates it into its JavaScript version main.js. If main.js already exists it will be overwritten.
tsc main.ts
We can also compile multiple files at once by listing all of them or by applying wildcards:
# Will result in separate .js files: main.js worker.js. tsc main.ts worker.ts # Compiles all .ts files in the current folder. Does NOT work recursively. tsc *.ts
We can also use the --watch option to automatically compile a TypeScript file when changes are made:
# Initializes a watcher process that will keep main.js up to date. tsc main.ts --watch
More advanced TypeScript matter users may produce a tsconfig.json file, consisting of varied build settings. A configuration file is incredibly handy once acting on massive comes with variant .ts files since it somewhat automates the method. You’ll be able to browse additional concerning tsconfig.json within the matter docs
here
Static typing
Static Typing
A very delicacy of matter is that the support of static writing. This suggests that you simply will declare the categories of variables, and therefore the compiler can make certain that they don't seem to be assigned the incorrect kinds of values. If kind declarations are omitted, they're going to be inferred mechanically from your code.Here is an example. Any variable, operate argument or come price will have its kind outlined on initialization:
var burger: string = 'hamburger', // String calories: number = 300, // Numeric tasty: boolean = true; // Boolean // Alternatively, you can omit the type declaration: // var burger = 'hamburger'; // The function expects a string and an integer. // It doesn't return anything so the type of the function itself is void. function speak(food: string, energy: number): void { console.log("Our " + food + " has " + energy + " calories."); } speak(burger, calories);
Because TypeScript is compiled to JavaScript, and the latter has no idea what types are, they are completely removed:
// JavaScript code from the above TS example. var burger = 'hamburger', calories = 300, tasty = true; function speak(food, energy) { console.log("Our " + food + " has " + energy + " calories."); } speak(burger, calories);
However, if we try to do something illegal, on compilation tsc will warn us that there is an error in our code. For example:
// The given type is boolean, the provided value is a string. var tasty: boolean = "I haven't tried it yet"; main.ts(1,5): error TS2322: Type 'string' is not assignable to type 'boolean'.
It will also warn us if we pass the wrong argument to a function:
function speak(food: string, energy: number): void{ console.log("Our " + food + " has " + energy + " calories."); } // Arguments don't match the function parameters. speak("tripple cheesburger", "a ton of"); main.ts(5,30): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
Here are some of the most commonly used data types:
· Number - All numeric values are represented by the number type, there aren't separate definitions for integers, floats or others.· String - The text type, just like in vanilla JS strings can be surrounded by 'single quotes' or "double quotes".· Boolean - true or false, using 0 and 1 will cause a compilation error.· Any - A variable with this type can have it's value set to a string, number, or anything else.· Arrays - Has two possible syntaxes: my_arr: number[]; or my_arr: Array<number>.· Void - Used on function that don't return anything.To see a list of all of the available types, go to the official TypeScript docs -
here
.
Interfaces
Interfaces
// Here we define our Food interface, its properties, and their types. interface Food { name: string; calories: number; } // We tell our function to expect an object that fulfills the Food interface. // This way we know that the properties we need will always be available. function speak(food: Food): void{ console.log("Our " + food.name + " has " + food.calories + " calories."); } // We define an object that has all of the properties the Food interface expects. // Notice that types will be inferred automatically. var ice_cream = { name: "ice cream", calories: 200 } speak(ice_cream);
The order of the properties does NOT matter. We just need the required properties to be present and to be the right type. If something is missing, has the wrong type, or is named differently, the compiler will warn us.
interface Food { name: string; calories: number; } function speak(food: Food): void{ console.log("Our " + food.name + " has " + food.calories + " grams."); } // We've made a deliberate mistake and name is misspelled as nmae. var ice_cream = { nmae: "ice cream", calories: 200 } speak(ice_cream); main.ts(16,7): error TS2345: Argument of type '{ nmae: string; calories: number; } is not assignable to parameter of type 'Food'. Property 'name' is missing in type '{ nmae: string; calories: number; }'.
This is a beginner’s guide so we won't be going into more detail about interfaces. However, there is a lot more to them than what we've mentioned here so we recommend you check out the TypeScript docs -
here
.
Classes and loop
Classes
When building giant scale apps, the article orientated type of programming is most popular by several developers, most notably in languages like Java or C#. Matter offers a category system that's terribly the same as the one in these languages, together with inheritance, abstract categories, interface implementations, setters/getters, and more. It's also truthful to say that since the foremost recent JavaScript update (ECMAScript 2015), categories are native to vanilla JS and may be used while not matter. The 2 implementation are terribly similar however have their variations, matter being a touch a lot of strict. Continuing with the food theme, here could be a easy matter class:
class Menu { // Our properties: // By default they are public, but can also be private or protected. items: Array<string>; // The items in the menu, an array of strings. pages: number; // How many pages will the menu be, a number. // A straightforward constructor. constructor(item_list: Array<string>, total_pages: number) { // The this keyword is mandatory. this.items = item_list; this.pages = total_pages; } // Methods list(): void { console.log("Our menu for today:"); for(var i=0; i<this.items.length; i++) { console.log(this.items[i]); } } } // Create a new instance of the Menu class. var sundayMenu = new Menu(["pancakes","waffles","orange juice"], 1); // Call the list method. sundayMenu.list();
Anyone who has written at least a bit of Java or C# should find this syntax comfortably familiar. The same goes for inheritance:
class HappyMeal extends Menu { // Properties are inherited // A new constructor has to be defined. constructor(item_list: Array<string>, total_pages: number) { // In this case we want the exact same constructor as the parent class (Menu), // To automatically copy it we can call super() - a reference to the parent's constructor. super(item_list, total_pages); } // Just like the properties, methods are inherited from the parent. // However, we want to override the list() function so we redefine it. list(): void{ console.log("Our special menu for children:"); for(var i=0; i<this.items.length; i++) { console.log(this.items[i]); } } } // Create a new instance of the HappyMeal class. var menu_for_children = new HappyMeal(["candy","drink","toy"], 1); // This time the log message will begin with the special introduction. menu_for_children.list();
For a more in-depth look at classes in TS you can read the documentation -
here
.
Generics
Generics
Generics area unit templates that enable an equivalent operate to simply accept arguments of varied differing kinds. Making reusable elements victimization generics is healthier than victimization the any information sort, as generics preserve the categories of the variables that go into and out of them.A quick example would be a script that receives an argument and returns an array containing that same argument.
// The <T> after the function name symbolizes that it's a generic function. // When we call the function, every instance of T will be replaced with the actual provided type. // Receives one argument of type T, // Returns an array of type T. function genericFunc<T>(argument: T): T[] { var arrayOfT: T[] = []; // Create empty array of type T. arrayOfT.push(argument); // Push, now arrayOfT = [argument]. return arrayOfT; } var arrayFromString = genericFunc<string>("beep"); console.log(arrayFromString[0]); // "beep" console.log(typeof arrayFromString[0]) // String var arrayFromNumber = genericFunc(42); console.log(arrayFromNumber[0]); // 42 console.log(typeof arrayFromNumber[0]) // number
The first time we have a tendency to known as the perform we have a tendency to manually set the kind to string. This is not needed because the compiler will see what argument has been passed and mechanically decide what kind suits it best, like within the second decision. Though it is not obligatory, providing the kind when is taken into account sensible follow because the compiler may fail to guess the proper type in additional complicated situations. The TypeScript docs include a couple of advanced examples including generics classes, combining them with interfaces, and more. You can find them
here
.
Modules
Modules
Another necessary thought once engaged on giant apps is modularity. Having your code split into several little reusable parts helps your project keep organized and perceivable, compared to having one 10000-line file for everything. TypeScript introduces a syntax for commercialism and mercantilism modules, however cannot handle the particular wiring between files. To change external modules TS depends on third-party libraries: need.js for browser apps and CommonJS for Node.js. Let's take a glance at a straightforward example of matter modules with need.js:We will have two files. One exports a function, the other imports and calls it.
exporter.ts
var sayHi = function(): void { console.log("Hello!"); } export = sayHi;
importer.ts
import sayHi = require('./exporter'); sayHi();
Now we need to download require.js and include it in a script tag - see how
here
. The last step is to compile our two .ts files. An extra parameter needs to be added to tell TypeScript that we are building modules for require.js (also referred to as AMD), as opposed to CommonJS ones.
tsc --module amd *.ts
Modules are quite complex and are out of the scope of this tutorial. If you want to continue reading about them head out to the TS docs -
here
.
Declaration files
Third-party Declaration Files
When employing a library that was originally designed for normal JavaScript, we'd like to use a declaration file to create that library compatible with matter. A declaration file has the extension .d.ts and contains varied data regarding the library and its API.  TypeScript declaration files are sometimes written by hand, however there is a high probability that the library you wish already includes a .d.ts. file created by someone else. DefinitelyTyped is that the biggest public repository, containing files for over cardinal libraries. there's additionally a preferred Node.js module for managing matter definitions referred to as Typings. If you still need to write a declaration file yourself, this
guide
will get you started.
Typescript 2.0 features.
Upcoming Features in TypeScript 2.0
TypeScript is still under active development and is evlolving constantly. At the time of the writing of this tutorial the LTS version is 1.8.10, but Microsoft have already released a Beta for TypeScript 2.0. It's available for public testing and you can try it out now:
npm install -g typescript@beta
It introduces some handy new concepts such as:
· Non-nullable types flag which prevents some variables from having their value set to null or undefined.· New improved system for getting declaration files directly with an npm install.· Control flow type analysis that catches errors previously missed by the compiler.· Some innovations in the module export/import syntax.
Another long-awaited feature is the ability to control the flow of asynchronous functions in an async/await block. This should be available in a future 2.1 update.
Conclusion
We hope you enjoyed this tutorial! Do you have any thoughts on matter and would you concentrate on victimization it in your projects? Be happy to depart a comment below!
We will be happy to answer your questions on designing, developing, and deploying comprehensive enterprise web, mobile apps and customized software solutions that best fit your organization needs. As a reputed Software Solutions Developer we have expertise in providing dedicated remote and outsourced technical resources for software services at very nominal cost. Besides experts in full stacks We also build web solutions, mobile apps and work on system integration, performance enhancement, cloud migrations and big data analytics. Don’t hesitate to
get in touch with us!
0 notes
lakhwanabhishek · 4 years ago
Text
Learning  Typescript  In  30  Minutes
Today we're getting to take a glance at matter, a compile-to-JavaScript language designed for developers to build massive and sophisticated apps. It inherits several programming ideas from languages like C# and Java that add a lot of discipline and order to the otherwise terribly relaxed and free-typed JavaScript.  This tutorial is aimed toward those who are fairly skilful in JavaScript however still beginners are once it involves matter. We've lived most of the fundamentals and key options whereas together with voluminous examples with commented code to assist you see the language in action. Let's begin!
Benefits  of Using  Typescript
JavaScript is pretty smart because it is and you'll surprise Do I actually ought to learn Typescript? Technically, you are doing not ought to learn matter to be a decent developer, the general public do exactly fine while not it. However, operating with matter undoubtedly has its benefits: Due to the static writing, code written in matter is a lot of sure, and is usually easier to right.
Makes it easier to arrange the code base for terribly massive and complex apps because of modules, namespaces and robust OOP support. Typescript contains a compilation step to JavaScript that catches every kind of errors before they reach runtime and break one thing. The approaching Angular two frameworks is written in matter and it's counseled that developers use the language in their daily use also.
The last purpose is really the foremost necessary to several individuals and is that the main reason to induce them into matter. Angular two is one amongst the most popular frameworks right away and though developers will use regular JavaScript with it, a majority of the tutorials and examples square measure written in TS. As Angular two expands its community, it's natural that a lot of and a lot of individuals are going to be learning matter.
Recent rise of Typescript’s popularity, data from Google Trends.  Installation
Installing TypeScript
You will need Node.js and Npm for this tutorial. Go
here
if you don't have them installed.The easiest way to setup Typescript is via
npm
. Using the command below ,we can install the Typescript package globally, making the TS compiler available in all of our projects:
npm install -g typescript
Try opening a terminal anywhere and running tsc -v to see if it has been properly installed.
tsc -v Version 1.8.10
Text editors
Text Editors with TypeScript Support
TypeScript is an open-source project however is developed and maintained by Microsoft and intrinsically was originally supported solely in Microsoft's Visual Studio platform. Nowadays, there are heaps additional text editors and day that either natively or through plugins provide support for the matter syntax, auto-complete suggestions, error catching, and even integral compilers.
1.  
Visual Studio Code
- Microsoft's other, lightweight open-source  code editor. TypeScript support is built in.2.   Official
Free Plugin
for Sublime Text.3.    The latest version of
WebStorm
comes with built in support.4.  
More
including Vim, Atom, Emacs and others
Compilation
Compiling to JavaScript
TypeScript is written in .ts files (or .tsx for JSX), that cannot be used directly within the browser and want to be translated to vanilla .js first. This compilation method is often worn out variety of various ways: ·  In the terminal using the previously mentioned command line tool tsc.·  Directly in Visual Studio or some of the other IDEs and text editors.·  Using automated task runners such as
gulp
.
We found the first way to be easiest and most beginner friendly, so that's what we're going to use in our lesson.The following command takes a TypeScript file named main.ts and translates it into its JavaScript version main.js. If main.js already exists it will be overwritten.
tsc main.ts
We can also compile multiple files at once by listing all of them or by applying wildcards:
# Will result in separate .js files: main.js worker.js. tsc main.ts worker.ts # Compiles all .ts files in the current folder. Does NOT work recursively. tsc *.ts
We can also use the --watch option to automatically compile a TypeScript file when changes are made:
# Initializes a watcher process that will keep main.js up to date. tsc main.ts --watch
More advanced TypeScript matter users may produce a tsconfig.json file, consisting of varied build settings. A configuration file is incredibly handy once acting on massive comes with variant .ts files since it somewhat automates the method. You’ll be able to browse additional concerning tsconfig.json within the matter docs
here
Static typing
Static Typing
A very delicacy of matter is that the support of static writing. This suggests that you simply will declare the categories of variables, and therefore the compiler can make certain that they don't seem to be assigned the incorrect kinds of values. If kind declarations are omitted, they're going to be inferred mechanically from your code.Here is an example. Any variable, operate argument or come price will have its kind outlined on initialization:
var burger: string = 'hamburger', // String calories: number = 300, // Numeric tasty: boolean = true; // Boolean // Alternatively, you can omit the type declaration: // var burger = 'hamburger'; // The function expects a string and an integer. // It doesn't return anything so the type of the function itself is void. function speak(food: string, energy: number): void { console.log("Our " + food + " has " + energy + " calories."); } speak(burger, calories);
Because TypeScript is compiled to JavaScript, and the latter has no idea what types are, they are completely removed:
// JavaScript code from the above TS example. var burger = 'hamburger', calories = 300, tasty = true; function speak(food, energy) { console.log("Our " + food + " has " + energy + " calories."); } speak(burger, calories);
However, if we try to do something illegal, on compilation tsc will warn us that there is an error in our code. For example:
// The given type is boolean, the provided value is a string. var tasty: boolean = "I haven't tried it yet"; main.ts(1,5): error TS2322: Type 'string' is not assignable to type 'boolean'.
It will also warn us if we pass the wrong argument to a function:
function speak(food: string, energy: number): void{ console.log("Our " + food + " has " + energy + " calories."); } // Arguments don't match the function parameters. speak("tripple cheesburger", "a ton of"); main.ts(5,30): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
Here are some of the most commonly used data types:
· Number - All numeric values are represented by the number type, there aren't separate definitions for integers, floats or others.· String - The text type, just like in vanilla JS strings can be surrounded by 'single quotes' or "double quotes".· Boolean - true or false, using 0 and 1 will cause a compilation error.· Any - A variable with this type can have it's value set to a string, number, or anything else.· Arrays - Has two possible syntaxes: my_arr: number[]; or my_arr: Array<number>.· Void - Used on function that don't return anything.To see a list of all of the available types, go to the official TypeScript docs -
here
.
Interfaces
Interfaces
// Here we define our Food interface, its properties, and their types. interface Food { name: string; calories: number; } // We tell our function to expect an object that fulfills the Food interface. // This way we know that the properties we need will always be available. function speak(food: Food): void{ console.log("Our " + food.name + " has " + food.calories + " calories."); } // We define an object that has all of the properties the Food interface expects. // Notice that types will be inferred automatically. var ice_cream = { name: "ice cream", calories: 200 } speak(ice_cream);
The order of the properties does NOT matter. We just need the required properties to be present and to be the right type. If something is missing, has the wrong type, or is named differently, the compiler will warn us.
interface Food { name: string; calories: number; } function speak(food: Food): void{ console.log("Our " + food.name + " has " + food.calories + " grams."); } // We've made a deliberate mistake and name is misspelled as nmae. var ice_cream = { nmae: "ice cream", calories: 200 } speak(ice_cream); main.ts(16,7): error TS2345: Argument of type '{ nmae: string; calories: number; } is not assignable to parameter of type 'Food'. Property 'name' is missing in type '{ nmae: string; calories: number; }'.
This is a beginner’s guide so we won't be going into more detail about interfaces. However, there is a lot more to them than what we've mentioned here so we recommend you check out the TypeScript docs -
here
.
Classes and loop
Classes
When building giant scale apps, the article orientated type of programming is most popular by several developers, most notably in languages like Java or C#. Matter offers a category system that's terribly the same as the one in these languages, together with inheritance, abstract categories, interface implementations, setters/getters, and more. It's also truthful to say that since the foremost recent JavaScript update (ECMAScript 2015), categories are native to vanilla JS and may be used while not matter. The 2 implementation are terribly similar however have their variations, matter being a touch a lot of strict. Continuing with the food theme, here could be a easy matter class:
class Menu { // Our properties: // By default they are public, but can also be private or protected. items: Array<string>; // The items in the menu, an array of strings. pages: number; // How many pages will the menu be, a number. // A straightforward constructor. constructor(item_list: Array<string>, total_pages: number) { // The this keyword is mandatory. this.items = item_list; this.pages = total_pages; } // Methods list(): void { console.log("Our menu for today:"); for(var i=0; i<this.items.length; i++) { console.log(this.items[i]); } } } // Create a new instance of the Menu class. var sundayMenu = new Menu(["pancakes","waffles","orange juice"], 1); // Call the list method. sundayMenu.list();
Anyone who has written at least a bit of Java or C# should find this syntax comfortably familiar. The same goes for inheritance:
class HappyMeal extends Menu { // Properties are inherited // A new constructor has to be defined. constructor(item_list: Array<string>, total_pages: number) { // In this case we want the exact same constructor as the parent class (Menu), // To automatically copy it we can call super() - a reference to the parent's constructor. super(item_list, total_pages); } // Just like the properties, methods are inherited from the parent. // However, we want to override the list() function so we redefine it. list(): void{ console.log("Our special menu for children:"); for(var i=0; i<this.items.length; i++) { console.log(this.items[i]); } } } // Create a new instance of the HappyMeal class. var menu_for_children = new HappyMeal(["candy","drink","toy"], 1); // This time the log message will begin with the special introduction. menu_for_children.list();
For a more in-depth look at classes in TS you can read the documentation -
here
.
Generics
Generics
Generics area unit templates that enable an equivalent operate to simply accept arguments of varied differing kinds. Making reusable elements victimization generics is healthier than victimization the any information sort, as generics preserve the categories of the variables that go into and out of them.A quick example would be a script that receives an argument and returns an array containing that same argument.
// The <T> after the function name symbolizes that it's a generic function. // When we call the function, every instance of T will be replaced with the actual provided type. // Receives one argument of type T, // Returns an array of type T. function genericFunc<T>(argument: T): T[] { var arrayOfT: T[] = []; // Create empty array of type T. arrayOfT.push(argument); // Push, now arrayOfT = [argument]. return arrayOfT; } var arrayFromString = genericFunc<string>("beep"); console.log(arrayFromString[0]); // "beep" console.log(typeof arrayFromString[0]) // String var arrayFromNumber = genericFunc(42); console.log(arrayFromNumber[0]); // 42 console.log(typeof arrayFromNumber[0]) // number
The first time we have a tendency to known as the perform we have a tendency to manually set the kind to string. This is not needed because the compiler will see what argument has been passed and mechanically decide what kind suits it best, like within the second decision. Though it is not obligatory, providing the kind when is taken into account sensible follow because the compiler may fail to guess the proper type in additional complicated situations. The TypeScript docs include a couple of advanced examples including generics classes, combining them with interfaces, and more. You can find them
here
.
Modules
Modules
Another necessary thought once engaged on giant apps is modularity. Having your code split into several little reusable parts helps your project keep organized and perceivable, compared to having one 10000-line file for everything. TypeScript introduces a syntax for commercialism and mercantilism modules, however cannot handle the particular wiring between files. To change external modules TS depends on third-party libraries: need.js for browser apps and CommonJS for Node.js. Let's take a glance at a straightforward example of matter modules with need.js:We will have two files. One exports a function, the other imports and calls it.
exporter.ts
var sayHi = function(): void { console.log("Hello!"); } export = sayHi;
importer.ts
import sayHi = require('./exporter'); sayHi();
Now we need to download require.js and include it in a script tag - see how
here
. The last step is to compile our two .ts files. An extra parameter needs to be added to tell TypeScript that we are building modules for require.js (also referred to as AMD), as opposed to CommonJS ones.
tsc --module amd *.ts
Modules are quite complex and are out of the scope of this tutorial. If you want to continue reading about them head out to the TS docs -
here
.
Declaration files
Third-party Declaration Files
When employing a library that was originally designed for normal JavaScript, we'd like to use a declaration file to create that library compatible with matter. A declaration file has the extension .d.ts and contains varied data regarding the library and its API.  TypeScript declaration files are sometimes written by hand, however there is a high probability that the library you wish already includes a .d.ts. file created by someone else. DefinitelyTyped is that the biggest public repository, containing files for over cardinal libraries. there's additionally a preferred Node.js module for managing matter definitions referred to as Typings. If you still need to write a declaration file yourself, this
guide
will get you started.
Typescript 2.0 features.
Upcoming Features in TypeScript 2.0
TypeScript is still under active development and is evlolving constantly. At the time of the writing of this tutorial the LTS version is 1.8.10, but Microsoft have already released a Beta for TypeScript 2.0. It's available for public testing and you can try it out now:
npm install -g typescript@beta
It introduces some handy new concepts such as:
· Non-nullable types flag which prevents some variables from having their value set to null or undefined.· New improved system for getting declaration files directly with an npm install.· Control flow type analysis that catches errors previously missed by the compiler.· Some innovations in the module export/import syntax.
Another long-awaited feature is the ability to control the flow of asynchronous functions in an async/await block. This should be available in a future 2.1 update.
Conclusion
We hope you enjoyed this tutorial! Do you have any thoughts on matter and would you concentrate on victimization it in your projects? Be happy to depart a comment below!
We will be happy to answer your questions on designing, developing, and deploying comprehensive enterprise web, mobile apps and customized software solutions that best fit your organization needs. As a reputed Software Solutions Developer we have expertise in providing dedicated remote and outsourced technical resources for software services at very nominal cost. Besides experts in full stacks We also build web solutions, mobile apps and work on system integration, performance enhancement, cloud migrations and big data analytics. Don’t hesitate to
get in touch with us!
#b2bservices
#b2b ecommerce
#b2bsales
#b2b seo
0 notes
secretcupcakesublime · 4 years ago
Text
Learning  Typescript  In  30  Minutes
Today we're getting to take a glance at matter, a compile-to-JavaScript language designed for developers to build massive and sophisticated apps. It inherits several programming ideas from languages like C# and Java that add a lot of discipline and order to the otherwise terribly relaxed and free-typed JavaScript.  This tutorial is aimed toward those who are fairly skilful in JavaScript however still beginners are once it involves matter. We've lived most of the fundamentals and key options whereas together with voluminous examples with commented code to assist you see the language in action. Let's begin!
Benefits  of Using  Typescript
JavaScript is pretty smart because it is and you'll surprise Do I actually ought to learn Typescript? Technically, you are doing not ought to learn matter to be a decent developer, the general public do exactly fine while not it. However, operating with matter undoubtedly has its benefits: Due to the static writing, code written in matter is a lot of sure, and is usually easier to right.
Makes it easier to arrange the code base for terribly massive and complex apps because of modules, namespaces and robust OOP support. Typescript contains a compilation step to JavaScript that catches every kind of errors before they reach runtime and break one thing. The approaching Angular two frameworks is written in matter and it's counseled that developers use the language in their daily use also.
The last purpose is really the foremost necessary to several individuals and is that the main reason to induce them into matter. Angular two is one amongst the most popular frameworks right away and though developers will use regular JavaScript with it, a majority of the tutorials and examples square measure written in TS. As Angular two expands its community, it's natural that a lot of and a lot of individuals are going to be learning matter.
Recent rise of Typescript’s popularity, data from Google Trends.  Installation
Installing TypeScript
You will need Node.js and Npm for this tutorial. Go
here
if you don't have them installed.The easiest way to setup Typescript is via
npm
. Using the command below ,we can install the Typescript package globally, making the TS compiler available in all of our projects:
npm install -g typescript
Try opening a terminal anywhere and running tsc -v to see if it has been properly installed.
tsc -v Version 1.8.10
Text editors
Text Editors with TypeScript Support
TypeScript is an open-source project however is developed and maintained by Microsoft and intrinsically was originally supported solely in Microsoft's Visual Studio platform. Nowadays, there are heaps additional text editors and day that either natively or through plugins provide support for the matter syntax, auto-complete suggestions, error catching, and even integral compilers.
1.  
Visual Studio Code
- Microsoft's other, lightweight open-source  code editor. TypeScript support is built in.2.   Official
Free Plugin
for Sublime Text.3.    The latest version of
WebStorm
comes with built in support.4.  
More
including Vim, Atom, Emacs and others
Compilation
Compiling to JavaScript
TypeScript is written in .ts files (or .tsx for JSX), that cannot be used directly within the browser and want to be translated to vanilla .js first. This compilation method is often worn out variety of various ways: ·  In the terminal using the previously mentioned command line tool tsc.·  Directly in Visual Studio or some of the other IDEs and text editors.·  Using automated task runners such as
gulp
.
We found the first way to be easiest and most beginner friendly, so that's what we're going to use in our lesson.The following command takes a TypeScript file named main.ts and translates it into its JavaScript version main.js. If main.js already exists it will be overwritten.
tsc main.ts
We can also compile multiple files at once by listing all of them or by applying wildcards:
# Will result in separate .js files: main.js worker.js. tsc main.ts worker.ts # Compiles all .ts files in the current folder. Does NOT work recursively. tsc *.ts
We can also use the --watch option to automatically compile a TypeScript file when changes are made:
# Initializes a watcher process that will keep main.js up to date. tsc main.ts --watch
More advanced TypeScript matter users may produce a tsconfig.json file, consisting of varied build settings. A configuration file is incredibly handy once acting on massive comes with variant .ts files since it somewhat automates the method. You’ll be able to browse additional concerning tsconfig.json within the matter docs
here
Static typing
Static Typing
A very delicacy of matter is that the support of static writing. This suggests that you simply will declare the categories of variables, and therefore the compiler can make certain that they don't seem to be assigned the incorrect kinds of values. If kind declarations are omitted, they're going to be inferred mechanically from your code.Here is an example. Any variable, operate argument or come price will have its kind outlined on initialization:
var burger: string = 'hamburger', // String calories: number = 300, // Numeric tasty: boolean = true; // Boolean // Alternatively, you can omit the type declaration: // var burger = 'hamburger'; // The function expects a string and an integer. // It doesn't return anything so the type of the function itself is void. function speak(food: string, energy: number): void { console.log("Our " + food + " has " + energy + " calories."); } speak(burger, calories);
Because TypeScript is compiled to JavaScript, and the latter has no idea what types are, they are completely removed:
// JavaScript code from the above TS example. var burger = 'hamburger', calories = 300, tasty = true; function speak(food, energy) { console.log("Our " + food + " has " + energy + " calories."); } speak(burger, calories);
However, if we try to do something illegal, on compilation tsc will warn us that there is an error in our code. For example:
// The given type is boolean, the provided value is a string. var tasty: boolean = "I haven't tried it yet"; main.ts(1,5): error TS2322: Type 'string' is not assignable to type 'boolean'.
It will also warn us if we pass the wrong argument to a function:
function speak(food: string, energy: number): void{ console.log("Our " + food + " has " + energy + " calories."); } // Arguments don't match the function parameters. speak("tripple cheesburger", "a ton of"); main.ts(5,30): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
Here are some of the most commonly used data types:
· Number - All numeric values are represented by the number type, there aren't separate definitions for integers, floats or others.· String - The text type, just like in vanilla JS strings can be surrounded by 'single quotes' or "double quotes".· Boolean - true or false, using 0 and 1 will cause a compilation error.· Any - A variable with this type can have it's value set to a string, number, or anything else.· Arrays - Has two possible syntaxes: my_arr: number[]; or my_arr: Array<number>.· Void - Used on function that don't return anything.To see a list of all of the available types, go to the official TypeScript docs -
here
.
Interfaces
Interfaces
// Here we define our Food interface, its properties, and their types. interface Food { name: string; calories: number; } // We tell our function to expect an object that fulfills the Food interface. // This way we know that the properties we need will always be available. function speak(food: Food): void{ console.log("Our " + food.name + " has " + food.calories + " calories."); } // We define an object that has all of the properties the Food interface expects. // Notice that types will be inferred automatically. var ice_cream = { name: "ice cream", calories: 200 } speak(ice_cream);
The order of the properties does NOT matter. We just need the required properties to be present and to be the right type. If something is missing, has the wrong type, or is named differently, the compiler will warn us.
interface Food { name: string; calories: number; } function speak(food: Food): void{ console.log("Our " + food.name + " has " + food.calories + " grams."); } // We've made a deliberate mistake and name is misspelled as nmae. var ice_cream = { nmae: "ice cream", calories: 200 } speak(ice_cream); main.ts(16,7): error TS2345: Argument of type '{ nmae: string; calories: number; } is not assignable to parameter of type 'Food'. Property 'name' is missing in type '{ nmae: string; calories: number; }'.
This is a beginner’s guide so we won't be going into more detail about interfaces. However, there is a lot more to them than what we've mentioned here so we recommend you check out the TypeScript docs -
here
.
Classes and loop
Classes
When building giant scale apps, the article orientated type of programming is most popular by several developers, most notably in languages like Java or C#. Matter offers a category system that's terribly the same as the one in these languages, together with inheritance, abstract categories, interface implementations, setters/getters, and more. It's also truthful to say that since the foremost recent JavaScript update (ECMAScript 2015), categories are native to vanilla JS and may be used while not matter. The 2 implementation are terribly similar however have their variations, matter being a touch a lot of strict. Continuing with the food theme, here could be a easy matter class:
class Menu { // Our properties: // By default they are public, but can also be private or protected. items: Array<string>; // The items in the menu, an array of strings. pages: number; // How many pages will the menu be, a number. // A straightforward constructor. constructor(item_list: Array<string>, total_pages: number) { // The this keyword is mandatory. this.items = item_list; this.pages = total_pages; } // Methods list(): void { console.log("Our menu for today:"); for(var i=0; i<this.items.length; i++) { console.log(this.items[i]); } } } // Create a new instance of the Menu class. var sundayMenu = new Menu(["pancakes","waffles","orange juice"], 1); // Call the list method. sundayMenu.list();
Anyone who has written at least a bit of Java or C# should find this syntax comfortably familiar. The same goes for inheritance:
class HappyMeal extends Menu { // Properties are inherited // A new constructor has to be defined. constructor(item_list: Array<string>, total_pages: number) { // In this case we want the exact same constructor as the parent class (Menu), // To automatically copy it we can call super() - a reference to the parent's constructor. super(item_list, total_pages); } // Just like the properties, methods are inherited from the parent. // However, we want to override the list() function so we redefine it. list(): void{ console.log("Our special menu for children:"); for(var i=0; i<this.items.length; i++) { console.log(this.items[i]); } } } // Create a new instance of the HappyMeal class. var menu_for_children = new HappyMeal(["candy","drink","toy"], 1); // This time the log message will begin with the special introduction. menu_for_children.list();
For a more in-depth look at classes in TS you can read the documentation -
here
.
Generics
Generics
Generics area unit templates that enable an equivalent operate to simply accept arguments of varied differing kinds. Making reusable elements victimization generics is healthier than victimization the any information sort, as generics preserve the categories of the variables that go into and out of them.A quick example would be a script that receives an argument and returns an array containing that same argument.
// The <T> after the function name symbolizes that it's a generic function. // When we call the function, every instance of T will be replaced with the actual provided type. // Receives one argument of type T, // Returns an array of type T. function genericFunc<T>(argument: T): T[] { var arrayOfT: T[] = []; // Create empty array of type T. arrayOfT.push(argument); // Push, now arrayOfT = [argument]. return arrayOfT; } var arrayFromString = genericFunc<string>("beep"); console.log(arrayFromString[0]); // "beep" console.log(typeof arrayFromString[0]) // String var arrayFromNumber = genericFunc(42); console.log(arrayFromNumber[0]); // 42 console.log(typeof arrayFromNumber[0]) // number
The first time we have a tendency to known as the perform we have a tendency to manually set the kind to string. This is not needed because the compiler will see what argument has been passed and mechanically decide what kind suits it best, like within the second decision. Though it is not obligatory, providing the kind when is taken into account sensible follow because the compiler may fail to guess the proper type in additional complicated situations. The TypeScript docs include a couple of advanced examples including generics classes, combining them with interfaces, and more. You can find them
here
.
Modules
Modules
Another necessary thought once engaged on giant apps is modularity. Having your code split into several little reusable parts helps your project keep organized and perceivable, compared to having one 10000-line file for everything. TypeScript introduces a syntax for commercialism and mercantilism modules, however cannot handle the particular wiring between files. To change external modules TS depends on third-party libraries: need.js for browser apps and CommonJS for Node.js. Let's take a glance at a straightforward example of matter modules with need.js:We will have two files. One exports a function, the other imports and calls it.
exporter.ts
var sayHi = function(): void { console.log("Hello!"); } export = sayHi;
importer.ts
import sayHi = require('./exporter'); sayHi();
Now we need to download require.js and include it in a script tag - see how
here
. The last step is to compile our two .ts files. An extra parameter needs to be added to tell TypeScript that we are building modules for require.js (also referred to as AMD), as opposed to CommonJS ones.
tsc --module amd *.ts
Modules are quite complex and are out of the scope of this tutorial. If you want to continue reading about them head out to the TS docs -
here
.
Declaration files
Third-party Declaration Files
When employing a library that was originally designed for normal JavaScript, we'd like to use a declaration file to create that library compatible with matter. A declaration file has the extension .d.ts and contains varied data regarding the library and its API.  TypeScript declaration files are sometimes written by hand, however there is a high probability that the library you wish already includes a .d.ts. file created by someone else. DefinitelyTyped is that the biggest public repository, containing files for over cardinal libraries. there's additionally a preferred Node.js module for managing matter definitions referred to as Typings. If you still need to write a declaration file yourself, this
guide
will get you started.
Typescript 2.0 features.
Upcoming Features in TypeScript 2.0
TypeScript is still under active development and is evlolving constantly. At the time of the writing of this tutorial the LTS version is 1.8.10, but Microsoft have already released a Beta for TypeScript 2.0. It's available for public testing and you can try it out now:
npm install -g typescript@beta
It introduces some handy new concepts such as:
· Non-nullable types flag which prevents some variables from having their value set to null or undefined.· New improved system for getting declaration files directly with an npm install.· Control flow type analysis that catches errors previously missed by the compiler.· Some innovations in the module export/import syntax.
Another long-awaited feature is the ability to control the flow of asynchronous functions in an async/await block. This should be available in a future 2.1 update.
Conclusion
We hope you enjoyed this tutorial! Do you have any thoughts on matter and would you concentrate on victimization it in your projects? Be happy to depart a comment below!
We will be happy to answer your questions on designing, developing, and deploying comprehensive enterprise web, mobile apps and customized software solutions that best fit your organization needs. As a reputed Software Solutions Developer we have expertise in providing dedicated remote and outsourced technical resources for software services at very nominal cost. Besides experts in full stacks We also build web solutions, mobile apps and work on system integration, performance enhancement, cloud migrations and big data analytics. Don’t hesitate to
get in touch with us!
0 notes
hptposts · 6 years ago
Text
Day 2.
Hix hôm nay lại là ngày thứ 7 của tuần tiếp theo.
Mình quên mât viết post hằng ngày rồi @@.
Từ hôm nay sẽ chấn chỉnh lại nha...
Công việc của hôm nay:
+ Giải 10 round của atcoder 042 -> 052
+ Giải 2 round của topcoder
Một kỹ năng quan trọng mình thấy cần nữa là ghi nhớ, mình tạm sẽ ghi những thứ cần ghi nhớ ở đây, chiến thuật sẽ trình bày luôn. Cứ theo chiến thuật mà luyện tập:
+ Ngoài ra thì mình còn muốn học thêm kỹ năng software engineer từ A-Z, ko chỉ làm công việc ở cấp thấp nhất là code nữa...:
Thu thập requirement -> Phân tích -> Tìm giải pháp, hướng tiếp cận -> thiết kế usecase -> Thiết kế kiến trúc UML, quan hệ -> TDD viết test trước -> code theo bản thiết kế.
--> Để code ko có bug, cần tìm hiểu nhiều sách và thực hành code nhiều hơn: Sách mình sẽ đọc tiếp theo về code:
- Clean code
- Code complete
- Working with legacy code
- pattern of enterprise software
- concurrency in practice
Sách về ghi nhớ:
- Mega memory.
Quy trình đọc sách:
Tóm tắt mục lục trong 1 tờ giấy a4 sơ đồ tư duy, ghi nhớ sơ đồ và các ý chính, ngữ cảnh liên quan trong nó. Xong tập vẽ lại sơ đồ 10 lần (1 lần sau 30 phút, 1 lần sau 6h, 1 lần sau 1 ngày, 1 lần 1 tuần, 1 lần tháng)
Áp dụng trong công việc thường xuyên.
0---
Ok sáng giờ mình xem lời giải của 4 contest atcoder rồi, giờ xem tiếp để tý viết code giải thử.
Cảm nghĩ: Sao thấy bài A,B của 4 contest này cực dễ ak, bài C thì có lúc dễ lúc khó, bài D thì trung bình. Chắc mấy contest đầu cho thả cửa, mấy contest sau bích luôn.
Xem lại phim Baki thôi, muốn tập võ lại thật luôn :D.
OK Table of contents đây rồi
Sách đầu tiên về code sẽ là clean code:
Clean Code TOC
The table of contents of the book Clean Code: A Handbook of Agile Software Craftsmanship (Robert C. Martin, 1994). It is a good overview of the rules recommended by the book.
Contents
Clean Code
There Will Be Code
Bad Code
The Total Cost of Owning a Mess
Schools of Thought
We Are Authors
The Boy Scout Rule
Prequel and Principles
Conclusion
Bibliography
The Grand Redesign in the Sky
Attitude
The Primal Conundrum
The Art of Clean Code?
What Is Clean Code?
Meaningful Names
Introduction
Use Intention-Revealing Names
Avoid Disinformation
Make Meaningful Distinctions
Use Pronounceable Names
Use Searchable Names
Avoid Encodings
Avoid Mental Mapping
Class Names
Method Names
Don’t Be Cute
Pick One Word per Concept
Don’t Pun
Use Solution Domain Names
Use Problem Domain Names
Add Meaningful Context
Don’t Add Gratuitous Context
Final Words
Hungarian Notation
Member Prefixes
Interfaces and Implementations
Functions
Small!
Do One Thing
One Level of Abstraction per Function
Switch Statements
Use Descriptive Names
Function Arguments
Have No Side Effects
Command Query Separation
Prefer Exceptions to Returning Error Codes
Don’t Repeat Yourself
Structured Programming
How Do You Write Functions Like This?
Conclusion
SetupTeardownIncluder
Bibliography
Blocks and Indenting
Sections within Functions
Reading Code from Top to Bottom: The Stepdown Rule
Common Monadic Forms
Flag Arguments
Dyadic Functions
Triads
Argument Objects
Argument Lists
Verbs and Keywords
Output Arguments
Extract Try/Catch Blocks
Error Handling Is One Thing
The Error.java Dependency Magnet
Comments
Comments Do Not Make Up for Bad Code
Explain Yourself in Code
Good Comments
Bad Comments
Bibliography
Legal Comments
Informative Comments
Explanation of Intent
Clarification
Warning of Consequences
TODO Comments
Amplification
Javadocs in Public APIs
Mumbling
Redundant Comments
Misleading Comments
Mandated Comments
Journal Comments
Noise Comments
Scary Noise
Don’t Use a Comment When You Can Use a
Function or a Variable
Position Markers
Closing Brace Comments
Attributions and Bylines
Commented-Out Code
HTML Comments
Nonlocal Information
Too Much Information
Inobvious Connection
Function Headers
Javadocs in Nonpublic Code
Example
Formatting
The Purpose of Formatting
Vertical Formatting
Team Rules
Uncle Bob’s Formatting Rules
The Newspaper Metaphor
Vertical Openness Between Concepts
Vertical Density
Vertical Distance
Vertical Ordering
Horizontal Formatting
Horizontal Openness and Density
Horizontal Alignment
Indentation
Dummy Scopes
Objects and Data Structures
Data Abstraction
Data/Object Anti-Symmetry
The Law of Demeter
Data Transfer Objects
Conclusion
Bibliography
Train Wrecks
Hybrids
Hiding Structure
Active Record
Error Handling
Use Exceptions Rather Than Return Codes
Write Your Try-Catch-Finally Statement First
Use Unchecked Exceptions
Provide Context with Exceptions
Define Exception Classes in Terms of a Caller’s Needs
Define the Normal Flow
Don’t Return Null
Don’t Pass Null
Conclusion
Bibliography
Boundaries
Using Third-Party Code
Exploring and Learning Boundaries
Learning log4j
Learning Tests Are Better Than Free
Using Code That Does Not Yet Exist
Clean Boundaries
Bibliography
Unit Tests
The Three Laws of TDD
Keeping Tests Clean
Clean Tests
One Assert per Test
F.I.R.S.T
Conclusion
Bibliography
Tests Enable the -ilities
Domain-Specific Testing Language
A Dual Standard
Single Concept per Test
Classes
Class Organization
Classes Should Be Small!
Organizing for Change
Bibliography
Encapsulation
The Single Responsibility Principle
Cohesion
Maintaining Cohesion Results in Many Small Classes
Isolating from Change
Systems
How Would You Build a City?
Separate Constructing a System from Using It
Scaling Up
Java Proxies
Pure Java AOP Frameworks
AspectJ Aspects
Test Drive the System Architecture
Optimize Decision Making
Use Standards Wisely, When They Add DemonstrableValue
Systems Need Domain-Specific Languages
Conclusion
Bibliography
Separation of Main
Factories
Dependency Injection
Cross-Cutting Concerns
Emergence
Getting Clean via Emergent Design
Simple Design Rule 1: Runs All the Tests
Simple Design Rules 2–4: Refactoring
No Duplication
Expressive
Minimal Classes and Methods
Conclusion
Bibliography
Concurrency
Why Concurrency?
Myths and Misconceptions
Challenges
Concurrency Defense Principles
Know Your Library
Know Your Execution Models
Beware Dependencies Between Synchronized Methods
Keep Synchronized Sections Small
Writing Correct Shut-Down Code Is Hard
Testing Threaded Code
Conclusion
Bibliography
Single Responsibility Principle
Corollary: Limit the Scope of Data
Corollary: Use Copies of Data
Corollary: Threads Should Be as Independent as Possible
Thread-Safe Collections
Producer-Consumer
Readers-Writers
Dining Philosophers
Treat Spurious Failures as Candidate Threading Issues
Get Your Nonthreaded Code Working First
Make Your Threaded Code Pluggable
Make Your Threaded Code Tunable
Run with More Threads Than Processors
Run on Different Platforms
Instrument Your Code to Try and Force Failures
Hand-Coded
Automated
Successive Refinement
Args Implementation
Args: The Rough Draft
String Arguments
Conclusion
How Did I Do This?
So I Stopped
On Incrementalism
JUnit Internals
The JUnit Framework
Conclusion
Refactoring SerialDate
First, Make It Work
Then Make It Right
Conclusion
Bibliography
Smells and Heuristics
Comments
Environment
Functions
General
Java
Names
Tests
Conclusion
Bibliography
Inappropriate Information
Obsolete Comment
Redundant Comment
Poorly Written Comment
Commented-Out Code
Build Requires More Than One Step
Tests Require More Than One Step
Too Many Arguments
Output Arguments
Flag Arguments
Dead Function
Multiple Languages in One Source File
Obvious Behavior Is Unimplemented
Incorrect Behavior at the Boundaries
Overridden Safeties
Duplication
Code at Wrong Level of Abstraction
Base Classes Depending on Their Derivatives
Too Much Information
Dead Code
Vertical Separation
Inconsistency
Clutter
Artificial Coupling
Feature Envy
Selector Arguments
Obscured Intent
Misplaced Responsibility
Inappropriate Static
Use Explanatory Variables
Function Names Should Say What They Do
Understand the Algorithm
Make Logical Dependencies Physical
Prefer Polymorphism to If/Else or Switch/Case
Follow Standard Conventions
Replace Magic Numbers with Named Constants
Be Precise
Structure over Convention
Encapsulate Conditionals
Avoid Negative Conditionals
Functions Should Do One Thing
Hidden Temporal Couplings
Don’t Be Arbitrary
Encapsulate Boundary Conditions
Functions Should Descend Only One Level of Abstraction
Keep Configurable Data at High Levels
Avoid Transitive Navigation
Avoid Long Import Lists by Using Wildcards
Don’t Inherit Constants
Constants versus Enums
Choose Descriptive Names
Choose Names at the Appropriate Level of Abstraction
Use Standard Nomenclature Where Possible
Unambiguous Names
Use Long Names for Long Scopes
Avoid Encodings
Names Should Describe Side-Effects.
Insufficient Tests
Use a Coverage Tool!
Don’t Skip Trivial Tests
An Ignored Test Is a Question about an Ambiguity
Test Boundary Conditions
Exhaustively Test Near Bugs
Patterns of Failure Are Revealing
Test Coverage Patterns Can Be Revealing
Tests Should Be Fast
Appendix A: Concurrency II
Client/Server Example
Possible Paths of Execution
Knowing Your Library
Dependencies Between Methods
Can Break Concurrent Code
Increasing Throughput
Deadlock
Testing Multithreaded Code
Tool Support for Testing Thread-Based Code
Conclusion
Tutorial: Full Code Examples
The Server
Adding Threading
Server Observations
Conclusion
Number of Paths
Digging Deeper
Conclusion
Executor Framework
Nonblocking Solutions
Nonthread-Safe Classes
Tolerate the Failure
Client-Based Locking
Server-Based Locking
Single-Thread Calculation of Throughput
Multithread Calculation of Throughput
Mutual Exclusion
Lock & Wait
No Preemption
Circular Wait
Breaking Mutual Exclusion
Breaking Lock & Wait
Breaking Preemption
Breaking Circular Wait
Client/Server Nonthreaded
Client/Server Using Threads
Appendix B: org.jfree.date.SerialDate
Appendix C: Cross References of Heuristics
Epilogue
----
+Code complete TOC +Software Estimation: The Art
+Rapid Development: Taming Wild Software Schedules+Rapid Development: Taming Wild Software Schedules
0 notes
rafi1228 · 5 years ago
Link
Start Learning Java Programming Step By Step with 200+ code examples. 250 Amazing Steps For Absolute Java Beginners!
What you’ll learn
You will Learn Java the MODERN WAY – Step By Step – With 200 HANDS-ON Code Examples
You will Understand the BEST PRACTICES in Writing High Quality Java Code
You will Solve a Wide Range of Hands-on Programming EXERCISES with Java
You will Learn to Write AWESOME Object Oriented Programs with Java
You will Acquire ALL the SKILLS to demonstrate an EXPERTISE with Java Programming in Your Job Interviews
You will learn ADVANCED Object Oriented Programming Concepts – Abstraction, Inheritance, Encapsulation and Polymorphism
You will learn the Basics of Object Oriented Programming – Interfaces, Inheritance, Abstract Class and Constructors
You will learn the Basics of Programming – variables, choosing a data type, conditional execution, loops, writing great methods, breaking down problems into sub problems and implementing great Exception Handling
You will learn Basics of Functional Programming with Java
You will gain Expertise in using Eclipse IDE and JShell
You will learn the basics of MultiThreaded Programming – with Executor Service
You will learn about a wide variety of Java Collections – List, Map, Set and Queue Interfaces
Requirements
You have an attitude to learn while having fun 🙂
You have ZERO Programming Experience and Want to Learn Java
Description
Zero Java Programming Experience? No Problem.
Do you want to take the first steps to Become a Great Java Programmer? Do you want to Learn Java Step By Step in a Fail Safe in28Minutes Way? Do you want to Learn to Write Great Java Programs?
******* Some Amazing Reviews From Our Learners *******
★★★★★ it’s an awesome course , i was a complete beginner and it helped me a lot. One of the best courses i have every taken on Udemy.
★★★★★ This is the best Java course I’ve come across. It’s straight to the point without any missing details. You can get an idea of what you’re getting into working with Java fast with this course. I really like it.
★★★★★ The experienece was extremely amazing. The course was highly detailed and comprehensive and all the topic were covered properly with due examples to their credit. The instructor is passionateabout what he is doing and hence it makes the course much more worth to learn. Kudos to the instructor for such an amazing job.
★★★★★ Never thought taking an online course will be so helpful. The instructor is quite engaging, gives good amount of exercises.
★★★★★ This course is wonderful! I really enjoy it. It really is for beginners, so it’s very helpful for people which don’t know nothing about programming.
★★★★★ Very comprehensive and detail course the instructor takes the patience to explain everything and goes a step forward in thinking what kind of errors could happen to the students really good instructor!
★★★★★ It’s very well thought out. I enjoy the constant exercises and the challenge they present to make things happen.
******* Course Overview *******
Java is one of the most popular programming languages. Java offers both object oriented and functional programming features.
We take an hands-on approach using a combination of JShell and Eclipse as an IDE to illustrate more than 200 Java Coding Exercises, Puzzles and Code Examples. This course assumes no previous ( beginner ) programming or Java experience. If you’ve never programmed a computer before, or if you already have experience with another programming language and want to quickly learn Java, this is a perfect course for you.
In more than 250 Steps, we explore the most important Java Programming Language Features
Basics of Java Programming – Expressions, Variables and Printing Output
Java Operators – Java Assignment Operator, Relational and Logical Operators, Short Circuit Operators
Java Conditionals and If Statement
Methods – Parameters, Arguments and Return Values
Object Oriented Programming – Class, Object, State and Behavior
Basics of OOPS – Encapsulation, Abstraction, Inheritance and Polymorphism
Basics about Java Data Types – Casting, Operators and More
Java Built in Classes – BigDecimal, String, Java Wrapper Classes
Conditionals with Java – If Else Statement, Nested If Else, Java Switch Statement, Java Ternary Operator
Loops – For Loop, While Loop in Java, Do While Loop, Break and Continue
Immutablity of Java Wrapper Classes, String and BigDecimal
Java Dates – Introduction to LocalDate, LocalTime and LocalDateTime
Java Array and ArrayList – Java String Arrays, Arrays of Objects, Primitive Data Types, toString and Exceptions
Introduction to Variable Arguments
Basics of Designing a Class – Class, Object, State and Behavior. Deciding State and Constructors.
Understanding Object Composition and Inheritance
Java Abstract Class and Interfaces. Introduction to Polymorphism.
Java Collections – List Interface(ArrayList, LinkedList and Vector), Set Interface (HashSet, LinkedHashSet and TreeSet), Queue Interface (PriorityQueue) and Map Interface (HashMap, HashTable, LinkedHashMap and TreeMap() – Compare, Contrast and Choose
Generics – Why do we need Generics? Restrictions with extends and Generic Methods, WildCards – Upper Bound and Lower Bound.
Functional Programming – Lambda Expression, Stream and Operations on a Stream (Intermediate Operations – Sort, Distinct, Filter, Map and Terminal Operations – max, min, collect to List), Functional Interfaces – Predicate Interface,Consumer Interface, Function Inteface for Mapping, Method References – static and instance methods
Introduction to Threads and MultiThreading – Need for Threads
Implementing Threads – Extending Thread Class and Implementing Runnable Interface
States of a Thread and Communication between Threads
Introduction to Executor Service – Customizing number of Active Threads. Returning a Future, invokeAll and invokeAny
Introduction to Exception Handling – Your Thought Process during Exception Handling. try, catch and finally. Exception Hierarchy – Checked Exceptions vs Unchecked Exceptions. Throwing an Exception. Creating and Throwing a Custom Exception – CurrenciesDoNotMatchException. Try with Resources – New Feature in Java 7.
List files and folders in Directory with Files list method, File walk method and find methods. Read and write from a File.
******* What You Can Expect from Every in28Minutes Course *******
in28Minutes created 20 Best Selling Courses providing Amazing Learning Experiences to 250,000 Learners across the world.
Each of these courses come with
✔ Amazing Hands-on Step By Step Learning Experiences
✔ Real Project Experiences using the Best Tools and Frameworks
✔ Awesome Troubleshooting Guides with 200+ FAQs Answered
✔ Friendly Support in the Q&A section
✔ Free Udemy Certificate of Completion on Completion of Course
✔ 30 Day “No Questions Asked” Money Back Guarantee!
~~~ Here are a Few Reviews on The in28Minutes Way ~~~
★★★★★ Excellent, fabulous. The way he has prepared the material and the way he teaches is really awesome. What an effort .. Thanks a million
★★★★★ A lot of preparation work has taken place from the teacher and this is visible throughout the course.
★★★★★ This guy is fantastic. Really. Wonderful teaching skills, and goes well out of his way to make sure that everything he is doing is fully understood. This is the kind of tutorial that gets me excited to work with a framework that I may otherwise not be.
★★★★★ The best part of it is the hands-on approach which the author maintained throughout the course as he had promised at the beginning of the lecture. He explains the concepts really well and also makes sure that there is not a single line of code you type without understanding what it really does.
★★★★★ I also appreciate the mind and hands approach of teaching something and then having the student apply it. It makes everything a lot clearer for the student and uncovers issues that we will face in our project early.
★★★★★ Amazing course. Explained super difficult concepts (that I have spent hours on the internet finding a good explanation) in under 5 minutes.
Zero risk. 30 day money-back guarantee with every purchase of the course. You have nothing to lose!
Start Learning Now. Hit the Enroll Button!
******* Step By Step Details *******
Introduction to Java Programming with Jshell using Multiplication Table
Step 00 – Getting Started with Programming Step 01 – Introduction to Multiplication Table challenge Step 02 – Launch JShell Step 03 – Break Down Multiplication Table Challenge Step 04 – Java Expression – An Introduction Step 05 – Java Expression – Exercises Step 06 – Java Expression – Puzzles Step 07 – Printing output to console with Java Step 08 – Printing output to console with Java – Exercise Statements Step 09 – Printing output to console with Java – Exercise Solutions Step 10 – Printing output to console with Java – Puzzles Step 11 – Advanced Printing output to console with Java Step 12 – Advanced Printing output to console with Java – Exercises and Puzzles Step 13 – Introduction to Variables in Java Step 14 – Introduction to Variables in Java – Exercises and Puzzles Step 15 – 4 Important Things to Know about Variables in Java Step 16 – How are variables stored in memory? Step 17 – How to name a variable? Step 18 – Understanding Primitive Variable Types in Java Step 19 – Understanding Primitive Variable Types in Java – Choosing a Type Step 20 – Java Assignment Operator Step 21 – Java Assignment Operator – Puzzles on Increment, Decrement and Compound Assignment Step 23 – Java Conditionals and If Statement – Introduction Step 24 – Java Conditionals and If Statement – Exercise Statements Step 25 – Java Conditionals and If Statement – Exercise Solutions Step 26 – Java Conditionals and If Statement – Puzzles Step 27 – Java For Loop to Print Multiplication Table – Introduction Step 28 – Java For Loop to Print Multiplication Table – Exercise Statements Step 29 – Java For Loop to Print Multiplication Table – Exercise Solutions Step 30 – Java For Loop to Print Multiplication Table – Puzzles Step 31 – Programming Tips : JShell – Shortcuts, Multiple Lines and Variables TODO Move up Step 32 – Getting Started with Programming – Revise all Terminology
Introduction to Method with Multiplication Table
Step 00 – Section 02 – Methods – An Introduction Step 01 – Your First Java Method – Hello World Twice and Exercise Statements Step 02 – Introduction to Java Methods – Exercises and Puzzles Step 03 – Programming Tip – Editing Methods with JShell Step 04 – Introduction to Java Methods – Arguments and Parameters Step 05 – Introduction to Java Method Arguments – Exercises Step 06 – Introduction to Java Method Arguments – Puzzles and Tips Step 07 – Getting back to Multiplication Table – Creating a method Step 08 – Print Multiplication Table with a Parameter and Method Overloading Step 09 – Passing Multiple Parameters to a Java Method Step 10 – Returning from a Java Method – An Introduction Step 11 – Returning from a Java Method – Exercises Step 99 – Methods – Section Review
Introduction to Java Platform
Step 00 – Section 03 – Overview Of Java Platform – Section Overview Step 01 – Overview Of Java Platform – An Introduction – java, javac, bytecode and JVM Step 02 – Java Class and Object – First Look Step 03 – Create a method in a Java class Step 04 – Create and Compile Planet.java class Step 05 – Run Planet calss with Java – Using a main method Step 06 – Play and Learn with Planet Class Step 07 – JDK vs JRE vs JVM
Introduction to Eclipse – First Java Project
Step 01 – Creating a New Java Project with Eclipse Step 02 – Your first Java class with Eclipse Step 03 – Writing Multiplication Table Java Program with Eclipse Step 04 – Adding more methods for Multiplication Table Program Step 05 – Programming Tip 1 : Refactoring with Eclipse Step 06 – Programming Tip 2 : Debugging with Eclipse Step 07 – Programming Tip 3 : Eclipse vs JShell – How to choose?
Introduction To Object Oriented Programming
Step 00 – Introduction to Object Oriented Programming – Section Overview Step 01 – Introduction to Object Oriented Programming – Basics Step 02 – Introduction to Object Oriented Programming – Terminology – Class, Object, State and Behavior Step 03 – Introduction to Object Oriented Programming – Exercise – Online Shopping System and Person Step 04 – Create Motor Bike Java Class and a couple of objects Step 05 – Exercise Solutions – Book class and Three instances Step 06 – Introducing State of an object with speed variable Step 07 – Understanding basics of Encapsulation with Setter methods Step 08 – Exercises and Tips – Getters and Generating Getters and Setters with Eclipse Step 09 – Puzzles on this and initialization of member variables Step 10 – First Advantage of Encapsulation Step 11 – Introduction to Encapsulation – Level 2 Step 12 – Encapsulation Exercises – Better Validation and Book class Step 13 – Introdcution to Abstraction Step 14 – Introduction to Java Constructors Step 15 – Introduction to Java Constructors – Exercises and Puzzles Step 16 – Introduction to Object Oriented Programming – Conclusion
Primitive Data Types And Alternatives
Step 00 – Primitive Data Types in Depth – Section Overview Step 01 – Basics about Java Integer Data Types – Casting, Operators and More Step 02 – Java Integer Data Types – Puzzles – Octal, Hexadecimal, Post and Pre increment Step 03 – Java Integer Data Types – Exercises – BiNumber – add, multiply and double Step 04 – Java Floating Point Data Types – Casting , Conversion and Accuracy Step 05 – Introduction to BigDecimal Java Class Step 06 – BigDecimal Puzzles – Adding Integers Step 07 – BigDecimal Exercises – Simple Interest Calculation Step 08 – Java Boolean Data Type – Relational and Logical Operators Step 09 – Java Boolean Data Type – Puzzles – Short Circuit Operators Step 10 – Java Character Data Type char – Representation and Conversion Step 11 – Java char Data Type – Exercises 1 – isVowel Step 12 – Java char Data Type – Exercises 2 – isDigit Step 13 – Java char Data Type – Exercises 3 – isConsonant, List Upper Case and Lower Case Characters Step 14 – Primitive Data Types in Depth – Conclusion
Conditionals
Step 00 – Conditionals with Java – Section Overview Step 01 – Introduction to If Else Statement Step 02 – Introduction to Nested If Else Step 03 – If Else Statement – Puzzles Step 04 – If Else Problem – How to get User Input in Java? Step 05 – If Else Problem – How to get number 2 and choice from user? Step 06 – If Else Problem – Implementing with Nested If Else Step 07 – Java Switch Statement – An introduction Step 08 – Java Switch Statement – Puzzles – Default, Break and Fall Through Step 09 – Java Switch Statement – Exercises – isWeekDay, nameOfMonth, nameOfDay Step 10 – Java Ternary Operation – An Introduction Step 11 – Conditionals with Java – Conclusion
Loops
Step 00 – Java Loops – Section Introduction Step 01 – Java For Loop – Syntax and Puzzles Step 02 – Java For Loop – Exercises Overview and First Exercise Prime Numbers Step 03 – Java For Loop – Exercise – Sum Upto N Numbers and Sum of Divisors Step 04 – Java For Loop – Exercise – Print a Number Triangle Step 05 – While Loop in Java – An Introduction Step 06 – While Loop – Exericises – Cubes and Squares upto limit Step 07 – Do While Loop in Java – An Introduction Step 08 – Do While Loop in Java – An Example – Cube while user enters positive numbers Step 09 – Introduction to Break and Continue Step 10 – Selecting Loop in Java – For vs While vs Do While
Reference Types
Step 00 – Java Reference Types – Section Introduction Step 01 – Reference Types – How are they stored in Memory? Step 02 – Java Reference Types – Puzzles Step 03 – String class – Introduction and Exercise – Print each word and char on a new line Step 04 – String class – Exercise Solution and Some More Important Methods Step 05 – Understanding String is Immutable and String Concat, Upper Case, Lower Case, Trim methods Step 06 – String Concatenation and Join, Replace Methods Step 07 – Java String Alternatives – StringBuffer and StringBuilder Step 08 – Java Wrapper Classes – An Introduction – Why and What? Step 09 – Java Wrapper Classes – Creation – Constructor and valueOf Step 10 – Java Wrapper Classes – Auto Boxing and a Few Wrapper Constants – SIZE, BYTES, MAX_VALUE and MIN_VALUE Step 11 – Java Dates – Introduction to LocalDate, LocalTime and LocalDateTime Step 12 – Java Dates – Exploring LocalDate – Creation and Methods to play with Date Step 13 – Java Dates – Exploring LocalDate – Comparing Dates and Creating Specific Dates Step 14 – Java Reference Types – Conclusion
Arrays and ArrayLists
Step 00 – Introduction to Array and ArrayList – Section Introduction with a Challenge Step 01 – Understanding the need and Basics about an Array Step 02 – Java Arrays – Creating and Accessing Values – Introduction Step 03 – Java Arrays – Puzzles – Arrays of Objects, Primitive Data Types, toString and Exceptions Step 04 – Java Arrays – Compare, Sort and Fill Step 05 – Java Arrays – Exercise – Create Student Class – Part 1 – Total and Average Marks Step 06 – Java Arrays – Exercise – Create Student Class – Part 2 – Maximum and Minimum Mark Step 07 – Introduction to Variable Arguments – Need Step 08 – Introduction to Variable Arguments – Basics Step 09 – Introduction to Variable Arguments – Enhancing Student Class Step 10 – Java Arrays – Using Person Objects and String Elements with Exercises Step 11 – Java String Arrays – Exercise Solutions – Print Day of Week with Most number of letters and more Step 12 – Adding and Removing Marks – Problem with Arrays Step 13 – First Look at ArrayList – An Introduction Step 14 – First Look at ArrayList – Refactoring Student Class to use ArrayList Step 15 – First Look at ArrayList – Enhancing Student Class with Add and Remove Marks Step 16 – Introduction to Array and ArrayList – Conclusion
Object Oriented Programming Again
Step 00 – Object Oriented Programming – Level 2 – Section Introduction Step 01 – Basics of Designing a Class – Class, Object, State and Behavior Step 02 – OOPS Example – Fan Class – Deciding State and Constructors Step 03 – OOPS Example – Fan Class – Deciding Behavior with Methods Step 04 – OOPS Exercise – Rectangle Class Step 05 – Understanding Object Composition with Customer Address Example Step 06 – Understanding Object Composition – An Exercise – Books and Reviews Step 07 – Understanding Inheritance – Why do we need it? Step 08 – Object is at top of Inheritance Hierarchy Step 09 – Inheritance and Overriding – with toString() method Step 10 – Java Inheritance – Exercise – Student and Employee Classes Step 11 – Java Inheritance – Default Constructors and super() method call Step 12 – Java Inheritance – Puzzles – Multiple Inheritance, Reference Variables and instanceof Step 13 – Java Abstract Class – Introductio Step 14 – Java Abstract Class – First Example – Creating Recipes with Template Method Step 15 – Java Abstract Class – Puzzles Step 16 – Java Interface – Example 1 – Gaming Console – How to think about Intefaces? Step 17 – Java Interface – Example 2 – Complex Algorithm – API defined by external team Step 18 – Java Interface – Puzzles – Unimplemented methods, Abstract Classes, Variables, Default Methods and more Step 19 – Java Interface vs Abstract Class – A Comparison Step 20 – Java Interface Flyable and Abstract Class Animal – An Exercise Step 21 – Polymorphism – An introduction
Collections
Step 01 – Java Collections – Section Overview with Need For Collections Step 02 – List Interface – Introduction – Position is King Step 03 – List Inteface – Immutability and Introduction of Implementations – ArrayList, LinkedList and Vector Step 04 – List Inteface Implementations – ArrayList vs LinkedList Step 05 – List Inteface Implementations – ArrayList vs Vector Step 06 – List Inteface – Methods to add, remove and change elements and lists Step 07 – List and ArrayList – Iterating around elements Step 08 – List and ArrayList – Choosing iteration approach for printing and deleting elements Step 09 – List and ArrayList – Puzzles – Type Safety and Removing Integers Step 10 – List and ArrayList – Sorting – Introduction to Collections sort static method Step 11 – List and ArrayList – Sorting – Implementing Comparable Inteface in Student Class Step 12 – List and ArrayList – Sorting – Providing Flexibility by implementing Comparator interface Step 13 – List and ArrayList – A Summary Step 14 – Set Interface – Introduction – No Duplication Step 15 – Understanding Data Structures – Array, LinkedList and Hashing Step 16 – Understanding Data Structures – Tree – Sorted Order Step 17 – Set Interface – Hands on – HashSet, LinkedHashSet and TreeSet Step 18 – Set Interface – Exercise – Find Unique Characters in a List Step 19 – TreeSet – Methods from NavigableSet – floor,lower,upper, subSet, head and tailSet Step 20 – Queue Interface – Process Elements in Order Step 21 – Introduction to PriorityQueue – Basic Methods and Customized Priority Step 22 – Map Interface – An Introduction – Key and Value Step 23 – Map Interface – Implementations – HashMap, HashTable, LinkedHashMap and TreeMap Step 24 – Map Interface – Basic Operations Step 25 – Map Interface – Comparison – HashMap vs LinkedHashMap vs TreeMap Step 26 – Map Interface – Exercise – Count occurances of characters and words in a piece of text Step 27 – TreeMap – Methods from NavigableMap – floorKey, higherKey, firstEntry, subMap and more Step 28 – Java Collections – Conclusion with Three Tips
Generics
Step 01 – Introduction to Generics – Why do we need Generics? Step 02 – Implementing Generics for the Custom List Step 03 – Extending Custom List with a Generic Return Method Step 04 – Generics Puzzles – Restrictions with extends and Generic Methods Step 05 – Generics and WildCards – Upper Bound and Lower Bound
Introduction to Functional Programming
Step 01 – Introduction to Functional Programming – Functions are First Class Citizens Step 02 – Functional Programming – First Example with Function as Parameter Step 03 – Functional Programming – Exercise – Loop a List of Numbers Step 04 – Functional Programming – Filtering – Exercises to print odd and even numbers from List Step 05 – Functional Programming – Collect – Sum of Numbers in a List Step 06 – Functional Programming vs Structural Programming – A Quick Comparison Step 07 – Functional Programming Terminology – Lambda Expression, Stream and Operations on a Stream Step 08 – Stream Intermediate Operations – Sort, Distinct, Filter and Map Step 09 – Stream Intermediate Operations – Exercises – Squares of First 10, Map String List to LowerCase and Length of String Step 10 – Stream Terminal Operations – 1 – max operation with Comparator Step 11 – Stream Terminal Operations – 2 – min, collect to List, Step 12 – Optional class in Java – An Introduction Step 13 – Behind the Screens with Functional Interfaces – Implement Predicate Interface Step 14 – Behind the Screens with Functional Interfaces – Implement Consumer Interface Step 15 – Behind the Screens with Functional Interfaces – Implement Function Inteface for Mapping Step 16 – Simplify Functional Programming code with Method References – static and instance methods Step 17 – Functions are First Class Citizens Step 18 – Introduction to Functional Programming – Conclusion
Introduction to Threads And Concurrency
Step 01 – Introduction to Threads and MultiThreading – Need for Threads Step 02 – Creating a Thread for Task1 – Extending Thread Class Step 03 – Creating a Thread for Task2 – Implement Runnable Interface Step 04 – Theory – States of a Thread Step 05 – Placing Priority Requests for Threads Step 06 – Communication between Threads – join method Step 07 – Thread utility methods and synchronized keyword – sleep, yield Step 08 – Need for Controlling the Execution of Threads Step 09 – Introduction to Executor Service Step 10 – Executor Service – Customizing number of Threads Step 11 – Executor Service – Returning a Future from Thread using Callable Step 12 – Executor Service – Waiting for completion of multiple tasks using invokeAll Step 13 – Executor Service – Wait for only the fastest task using invokeAny Step 14 – Threads and MultiThreading – Conclusion
Introduction to Exception Handling
Step 01 – Introduction to Exception Handling – Your Thought Process during Exception Handling Step 02 – Basics of Exceptions – NullPointerException and StackTrace Step 03 – Basics of Handling Exceptions – try and catch Step 04 – Basics of Handling Exceptions – Exception Hierarchy, Matching and Catching Multiple Exceptions Step 05 – Basics of Handling Exceptions – Need for finally Step 06 – Basics of Handling Exceptions – Puzzles Step 07 – Checked Exceptions vs Unchecked Exceptions – An Example Step 08 – Hierarchy of Errors and Exceptions – Checked and Runtime Step 09 – Throwing an Exception – Currencies Do Not Match Runtime Exception Step 10 – Throwing a Checked Exception – Throws in method signature and handling Step 11 – Throwing a Custom Exception – CurrenciesDoNotMatchException Step 12 – Write less code with Try with Resources – New Feature in Java 7 Step 13 – Basics of Handling Exceptions – Puzzles 2 Step 14 – Exception Handling – Conclusion with Best Practices
Files and Directories
Step 01 – List files and folders in Directory with Files list method Step 02 – Recursively List and Filter all files and folders in Directory with Step Files walk method and Search with find method Step 03 – Read content from a File – Files readAllLines and lines methods Step 04 – Writing Content to a File – Files write method Step 05 – Files – Conclusion
More Concurrency with Concurrent Collections and Atomic Operations
Step 01 – Getting started with Synchronized Step 02 – Problem with Synchronized – Less Concurrency Step 03 – Enter Locks with ReEntrantLock Step 04 – Introduction to Atomic Classes – AtomicInteger Step 05 – Need for ConcurrentMap Step 06 – Implementing an example with ConcurrentHashMap Step 07 – ConcurrentHashMap uses different locks for diferrent regions Step 08 – CopyOnWrite Concurrent Collections – When reads are more than writes Step 09 – Conclusion
Java Tips
Java Tip 01 – Imports and Static Imports Java Tip 02 – Blocks Java Tip 03 – equals method Java Tip 04 – hashcode method Java Tip 05 – Class Access Modifiers – public and default Java Tip 06 – Method Access Modifiers – public, protected, private and default Java Tip 07 – Final classes and Final methods Java Tip 08 – Final Variables and Final Arguments Java Tip 09 – Why do we need static variables? Java Tip 09 – Why do we need static methods? Java Tip 10 – Static methods cannot use instance methods or variables Java Tip 11 – public static final – Constants Java Tip 12 – Nested Classes – Inner Class vs Static Nested Class Java Tip 13 – Anonymous Classes Java Tip 14 – Why Enum and Enum Basics – ordinal and values Java Tip 15 – Enum – Constructor, variables and methods Java Tip 16 – Quick look at inbuild Enums – Month, DayOfWeek
Zero risk. 30 day money-back guarantee with every purchase of the course. You have nothing to lose!
Start Learning Now. Hit the Enroll Button!
Who this course is for:
You have ZERO programming experience and want to learn Java Programming
You are a Beginner at Java Programming and want to Learn to write Great Java Programs
You want to learn the Basics of Object Oriented Programming with Java
You want to learn the Basics of Functional Programming with Java
Created by in28Minutes Official Last updated 1/2019 English English [Auto-generated]
Size: 2.80 GB
   Download Now
https://ift.tt/2A4bRbM.
The post Java Programming for Complete Beginners – Learn in 250 Steps appeared first on Free Course Lab.
0 notes
knoldus · 7 years ago
Link
In the first blog of the Scala Type System series, I  had put a lot of emphasis on the fact that “Type variables make a very powerful piece of type-level programming”. They appear in a variety of forms and variations. One of the important forms is “existential types”. In today’s blog, I would like to get you familiar with the existential types.
Given below is a typical way of defining a variable :
type F[A] = SomeClass[A]
Where A is said to be a type variable. Notice that A has appeared on both sides of the above equation. This implies that F is fully dependent on A. The type of A is essential for instantiation of the SomeClass. Let us take a few examples :
sealed trait F[A] final case class SomeClass[A](a: A) extends F[A] SomeClass("hello"): F[String]       SomeClass(1: Int): F[Int] SomeClass(true): F[Boolean] SomeClass("hello"): F[Int]
Notice that the last example would not compile as the Type A on the LHS and RHS of the equation conflict.
Let us understand the need for existential types, consider the following is defined:
def getLength(x : Array[Any]): Int = x.length val stringArray = Array[String]("foo", "bar", "baz") getLength(stringArray)
The above line gives us the following error:
error: type mismatch; found   : Array[String]  required: Array[Any]
We could fix the above error in the following manner:
def getLength[T](x: Array[T]): Int = x.length getLength(stringArray)
Do you realise the potential overhead of the above fix? We’ve parameterised the method. But now we have a superfluous type parameter in our method. Speaking precisely, I mean I want an Array, and I don’t care what type of things it contains. This verbosity of providing a type parameter is a hassle sometimes.
Having this basic understanding of the normal variable declaration, let us try to understand existential types. By Definition “Existential types are a way of abstracting over types. They let you “acknowledge” that there is a type involved without specifying exactly what it is, usually because you don’t know what it is and you don’t need that knowledge in the current context.” Existential types are normal type variables, except that the variable only shows up on the RHS of the declaration.
type F = SomeClass[A] forSome { type A }
Let us take an example:
sealed trait F final case class SomeClass[A](a: A) extends F case class User(name: String, age: Int, contact: String) SomeClass("SomeString"): F SomeClass(1: Int): F SomeClass(User): F
Notice that `A` appears only on the right in case of existential type. The advantage of this is that the final type, F, will not change regardless of the type of A.
Let us try to fit in the existential type in the getLength() method defined above as well.
def getLength(x : Array[T] forSome { type T}): Int = x.length
Let us expand a little more with another example:
sealed trait Existential {    type Inner    val value: Inner } final case class PrepareExistential[A](value: A) extends Existential {   type Inner = A } PrepareExistential("SomeText"): Existential PrepareExistential(1: Int): Existential PrepareExistential(User): Existential
Notice that the PrepareExistential is a type eraser. The fact is irrelevant to the data type we put into PrepareExistential, it will erase the type and always return Existential. Let us take a step further and the next logical question line is “If we have some function that returns and Existential then what shall be the type of inner? ”
The simplest answer would be “We Don’t know”. I would in my defence say that the original type defined in PrepareExistential has been erased from the compilation. But that is incorrect. This doesn’t imply that we have lost all the information. We know for a fact is exists. Hence this is called existential type.
Another inevitable question that follows is “Where should we use existential types then?” But before I answer this question, there is another question “What is the use of type erasures?” To answer that let me quote an answer from Martin Odersky himself “ Scala uses the erasure model of generics, just like Java, so we don’t see the type parameters anymore when programs are run. We have to do erasure because we need to interoperate with Java. But then what happens when we do reflection or want to express what goes on the in the VM? We need to be able to represent what the JVM does using the types we have in Scala, and existential types let us do that.”
Existential types have an important property of unifying different types into a single one with shared restrictions. These restrictions could be anything: from upper bounds to type classes or even a combination.  A very common use case is the creation of type-safe wrappers around unsafe libraries. Consider the following:
def write(objs: Object*): String
The signature of the above function is not special, it is very generic. Also since the object will probably take everything, the program shall crash at the runtime rather than failing at compile time. In the context of Scala specifically, a lot of these Java libraries have these generic methods and interfaces wherein certain scala types don’t work like BigInt, Int, List etc.
So if we can think of an Object as an existential type we could resolve the problem of the type being too wide of encompassing all types. Here in, we need to restrict the number of types that are workable with the write. Let us improvise
def safeWrite(columns: AnyAllowedType*): String = {  write(columns.map(_.toObject):_*) }
Let us extend the getLength example:
def getLength(x : Array[T] forSome { type T <: CharSequence}) = x.foreach(y => println(y.length))
Notice the additional restriction we have imposed. Here in we wanted to act on a more specific type, but did not care exactly what type it is.  The type arguments for an existential type can declare upper and lower bounds just like normal type declarations. By adding bounds, all we have done is to restrict the range of T. An Array[Int] is not an Array[T] forSome { type T <: CharSequence }
In generic definition, for a type T, M[T] is a type, but M is not itself a type. M could be List, Array, Class, etc. M[T] forSome { type T; } is the type of all things for which there is some T such that they are of type M[T]. So an Array[String] is of this type because we can choose T = String.
Before Concluding the blog, it is essential to address one last question “Are Existential types same as raw types”. A simple answer is NO.  Existential types are not raw types. Another important thing to understand is that Existentials are safe, raw types are not. In Scala, type arguments are always required. The common problem Scala developers often face is they are unable to implement some Java method with missing type arguments in its signature, e.g. one that takes a raw List as an argument.
Example: Consider using the following java code
import java.util.Arrays; import java.util.ArrayList; import java.util.List; abstract class TestExistential {    static List arrayOfWords() {        return new ArrayList<>(Arrays.asList("hi", "Welcome", "to", "Knoldus"));    } } class UnsafeTypes extends TestExistential {    public static final List wordsRaw = arrayOfWords(); } warning: [rawtypes] found raw type: List missing type arguments for generic class List where E is a type-variable: E extends Object declared in interface List class ExistentialTypes extends TestExistential {    public static final List<?> wordsExistentialType = arrayOfWords(); }
Notice the warning here in the UnsafeTypes, whereas while using the same in Scala, no warning for the equivalent to wordsRaw in Scala as types are inferred and are type safe. If you get a Java raw type, such as java.util.List, it is a list where you don’t know the element type. This can be represented in Scala by an existential type.
val stringArray: util.List[String] = TestExistential.arrayOfWords() val genericArray: util.List[_] = TestExistential.arrayOfWords()
In essence, the reason that existential is safe is that the rules in place for values of existential type are consistent with the rest of the generic system, whereas raw types contradict those rules, resulting in code that is not type check.
From a developer’s perspective, Existential types are quite powerful when mixed with the correct restrictions. They prove to be potent for the following scenarios :
We need to make some sense of Java’s wildcards, and existential types are the sense we make of them.
We need to make some sense of Java’s raw types because they are also still in the libraries, the un-generic types
We need existential types as a way to explain what goes on in the VM at the high level of Scala
  References –
https://www.cakesolutions.net/teamblogs/existential-types-in-scala
https://www.drmaciver.com/2008/03/existential-types-in-scala/
https://typelevel.org/blog/2015/02/26/rawtypes.html
http://www.scala-lang.org/node/2320
http://scalada.blogspot.com/2008/01/existential-types.html
0 notes
eurekakinginc · 8 years ago
Photo
Tumblr media
"[P] Sigma – Creating a machine learning framework from scratch (Update on high school thesis advice thread)"- Detail: TLDR: Asked this subreddit for advice in deciding on ML topic for high school thesis 2 years ago (see original thread), ended up writing a machine learning framework from (almost) scratch in C#/F#. It can’t do as much as all the others, isn’t as fast or as pretty, but we still think it’s kind of cool. Here it is: our github repo and a short UI demo.ResultsUpfront the current feature set of our framework Sigma, to give you an idea of what the next few paragraphs are about:Input, Output, Dense, Dropout, Recurrent, SoftmaxCE / SquaredDiff cost layersGradient descent, Momentum, Adadelta, Adagrad optimisersHooks for storing / restoring checkpoints, timekeeping, stopping (or doing other things) on certain criteria, computing and reporting runtime metricsEasy addition of new layers with functional automatic differentiationLinear and non-linear networks with arbitrarily connected constructsDistributed multi- and single- CPU and GPU (CUDA) backendsNative graphical interface where parameters can be interacted with and monitored in real-time  1. IntroductionThis is the story of us writing a machine learning framework for our high school thesis, of what we learned and how we went about writing one from scratch. The story starts about 3 years ago: we saw a video of MarI/O, a Super Mario AI that could learn to play Super Mario levels. We thought that was about the coolest thing of all time and wanted to do something at least kind of similar for our high school thesis. 1.1 The Original PlanFast forward, over 2 years ago we asked for help in deciding what kind of machine learning project we could feasibly do for our senior year high school thesis (see original thread). Quite ambitiously, we proposed a time investment of about 1000 hours total (as in 500 hours each over the course of 8 months) – for what project, we didn’t know yet. In that thread, we were generously met with a lot of help, advice ranged from reproducing existing papers to implementing specific things to getting to understand the material and then seeing what peaked our interest. After some consideration, we figured we would implement something along the lines of DeepMinds arcade game AI and then make it more general, figuring that would be easy for some reason. When planning our project in more detail we however quickly realised thatwe had no idea what we were doing andit would be a shame to do all that work from scratch and have it be so arbitrarily specific. 1.2 PivotingBefore doing anything very productive, we had to properly study machine learning. We figured this might take a while and allocated that part of our time to writing the theoretical part of our thesis, which conveniently overlapped. But because around that time we had to hand in an official target definition for our thesis, we set the most generic “goals” we could get away with. For reference, for a concerning number of months our project was officially named “Software framework for diverse machine learning tasks” with an even longer and even less specific subtitle. During further study and first attempts to draft the actual target definition for our project, our plans gradually shifted from a machine learning framework for playing specific types of games pivoted to an “any kind of visual input” learning framework and then finally to an “anything” machine learning framework – because why not, it seemed like an interesting challenge and we were curious to see how far we would get.  2. Research and PlanningAlright, so we've decided to write a machine learning framework. How does one create a machine learning framework? It takes many weeks to get reasonably proficient in just using a given framework, and that with proper guides, video tutorials and forums to ask for help. Creating a machine learning framework is a whole other story, with no 12 step guidelines to follow. For a considerable amount of time, we were at a loss at what we actually needed to implement – constantly encountering new and conflicting terms, definitions and not-so-obvious-“but the actual conclusion is obvious”-articles. After a little over a month we slowly got a very basic grasp of how this whole machine learning thing worked – something with functions that are approximated at certain points in steps typically using differentiation to make some metric go down – still magic, but a bit less so (until we read about CNNs, LSTMs and then GANs, each of which confused the heck out of us for some time). 2.1 Sketching our FrameworkAs soon as we knew a bit about the art of machine learning we got more serious about the writing a new framework part. Because there are no guides for that, we resorted to reading the source code of established frameworks – all to us relevant parts, many times, until it made some sense. In the meantime, we had decided to use C# as our primary language – mostly because we were already very familiar with it and didn’t want to also have to learn a new language, but officially also because there were no other proper neural network frameworks for .NET. Alongside reading the source code of machine learning libraries (mainly Deeplearning4J, Brainstorm and Tensorflow) we sketched out how we wanted our own framework to be used. After some time, we felt like there was some unnecessary confusion in getting to know machine learning frameworks as an outsider and we set out to design our API to avoid that. Note that because our design makes sense to us doesn’t mean that it makes more sense than the existing ones to other people, nor do we recommend everyone wishing to use machine learning to write their own framework, just to spare their own sanity.Our naïve ideas on how a machine learning should look like was clearly inspired by our C#/Java based programming experience, as is evident from the code example we drafted a few weeks in:Sigma sigma = Sigma.Create("minsttest"); GUIMonitor gui = (GUIMonitor) sigma.AddMonitor(new GUIMonitor("Sigma GUI Demo")); gui.AddTabs({"Overview", "Data", "Tests"}); sigma.Prepare(); DataSetSource inputSource = new MultiDataSetSource(new FileSource("mnist.inputs"), new CompressedFileSource(new FileSource("mnist.inputs.tar.gz"), new URLSource("http://....url...../mnist.inputs.targ.gz"))); DataSetSource targetSource = new MultiDataSetSource(new FileSource("mnist.targets"), new CompressedFileSource(new FileSource("mnist.targets.tar.gz"), new URLSource("http://....url...../mnist.targets.targ.gz" [, output: "otherthandefault"]) [, compression: new TarGZUnpacker(), output: "mnist.inputs" , forceUpdate: false])); DataSet data = new DataSet(new ImageRecordReader(inputSource, {28, 28}).Extractor({ALL} => {inputs: {Extractor.BatchSize, 1, 28, 28}}).Preprocess(Normalisor()), new StringRecordReader(targetSource).Extractor({0} => {targets: {Extractor.BatchSize, 1}} [, blockSize: auto/all/1024^3]); Network network = new Network("mynetwork"); network.Architecture = Input(inputShape: {28, 28}) + 2 * FullyConnected(size: 1024) + SoftmaxCE() + Loss(); Trainer trainer = sigma.CreateTrainer("mytrainer"); trainer.SetNetwork(network); trainer.SetInitialiser(new GaussianInitialiser(mean: 0.0, standardDeviation: 0.05)); trainer.SetTrainingDataIterator(MinibatchIterator(batchSize: 50, data["inputs"], data["targets"]); trainer.SetOptimiser(new SGDOptimiser(learningRate: 0.01); trainer.AddActiveHook(EarlyStopper(patience: 3)); trainer.AddActiveHook(StopAfterEpoch(epoch: 2000)); gui.AccentColor["trainer1"] = Colors.DeepOrange; gui.tabs["overview"].AddSubWindow(new LineChartWindow(name: "Error", sources: {"*.Training.Error"}) [, x: 1, y: 0, width: 2, height: 1]); gui.tabs["overview"].AddSubWindow(new LineChartWindow(name: "Accuracy", sources: {"*.Training.Accuracy"})); sigma.Run(); And skipping ahead a bit, it should be noted that the final framework is extremely similar to what we envisioned here: merely changing around a few syntax things and names, the above example from about a year ago can be used 1:1 in our current framework. The jury is still out on whether that’s a sign of really good or really bad design. Also note the python-style kwargs notation for layer constructor arguments, which was soon discarded in favour of something that actually compiles in C#. But back to the timeline. 2.2 The Sigma ArchitectureAfter defining the code examples and sketching out the rough parts we felt a machine learning framework needed, we arrived at this general architecture for “Sigma.Core”, divided into core components (which translate almost 1:1 to namespace in our project):Util: Mostly boring, well, utility stuff, but also registries, a key part of our architecture. Because we wanted to be able to inspect and visualise everything we needed a global way to access things by identifier – a registry. Our registry is essentially a dictionary with a string key which may contain more registries. Nested registries can be resolved using registry resolvers in dot notation with some fancy wildcards and tags in angel brackets (e.g. “network.layers.*.weights”).Data: Datasets, the records that make them up in various formats, the pipeline to load, extract, prepare and cache them from disk, web, or wherever they come from and make them available as “blocks”. These blocks are parts of an extracted dataset, consist of many individual records, and are used to avoid loading all of a potentially very large dataset into memory at once. Also, data iterators, which slices larger blocks from datasets into pieces that are then fed to the model.Architecture: Abstract definitions for machine learning models, consisting of layer “constructs”, which are lightweight placeholder layers defining what a layer will look like before its fully instantiated. These layers may be in any order and connected with however many other layers they would like.Layers: Unfortunately named since we started out with just neural networks, but these are the individual layers of our machine learning networks – they store meta-parameters (e.g. size) and actual trainable parameters (e.g. the actual weights).Math: Everything that has directly to do with math and low-level computations. All the automatic differentiation logic (which is very much required for doing proper machine learning) and everything that modifies our data is processed here in various backends (e.g. distributed CPU / GPU). To support calculating derivatives with respect to anything we opted for an approach with symbolic objects – essentially an object for a number or an array where the actual data was hidden (it can be fetched, but only via copies). These symbolic objects are passed around through a handler which does the actual data modification. This abstraction proved to be useful when implementing CUDA support where, due to the asynchronous execution of the CUDA stream, the raw data could not exposed to the user anyway, at least not without major performance hits (host-device synchronisation is very slow).Training: The largest component with many subcomponents, all revolving around the actual training process. A training process is defined in a “trainer”, which specifies the following:Initialisers, that define how a models parameters are initialised, which can be configured with registry identifiers. For example, trainer.addInitialiser(“layers.*.biases”, new GaussianInitialiser(0.1, 0.0)); would initialise all parameters named “biases” with a Gaussian distribution of 0.1 (mean 0).Modifiers, that would modify parameters at runtime, for example to clip weights to a certain range.Optimisers, that define how a model learns (e.g. gradient descent). Because we mainly considered neural networks we only implemented gradient based optimisers, but the interface theoretically supports any kind of optimisation.Hooks, that “hook” into the training process at certain time steps and can do whatever you want (e.g. update visualisations, store / restore checkpoints, compute and log metrics, do something (e.g. stop) when some criteria are satisfied).Operators, that delegate work to workers which execute it with a certain backend computation handler according to some parameters. Notable is our differentiation of “global” and “local” processing, where global is the most recent global state. This global state is fetched by local workers that then do the actual work, publish their results to the operator which merges it back into the global scope. A global timestep event is only ejected when all local workers have submitted their work for that timestep, enabling more fine control in distributed learning, at least in theory.Sigma: The root namespace that can create Sigma environments and trainers. An environment may contain multiple trainers, which are all run and, if specified, visualised simultaneously (which was supposed to be helpful in hyperparameter search).Monitors: Technically outside of the core project, but still a component. These monitors can be attached to a Sigma environment and can then, well, monitor almost everything about the trainers of that environment using the aforementioned registry entries. Behaviour can be injected using commands, a special form of hooks that are only invoked once. This way monitors can be used almost independently of the core Sigma project and can be pretty much anything, like a graphical interface or a live, locally hosted website.  3. ImplementationAnd that’s what we implemented, step by step. We started out with me mainly working on Sigma.Core and my partner on our visualisation interface, working to a common interface for months until we could finally combine our individual parts and have it miraculously work in a live graphical interface. The specifics of implementation were very interesting and quite challenging to us, but most of the particulars are probably rather dull to read – after all, most of the time things didn’t work and when we fixed something, we moved on to the next something that didn’t. 3.1 Low-level Data and Mathematical ProcessingThe very first thing we did was getting the data “ETL” (extract transform load) pipeline up and running, mainly fetching data from a variety of sources, loading them into a dataset and extracting them as blocks. I then focused on the mathematical processing part – everything that had to do with using math and calculating derivatives in our framework. I based our functional automatic differentiation, aptly named “SigmaDiff”, on an F# library for autodiff named “DiffSharp”, which I modified heavily to support n-dimensional arrays, improve performance significantly, fix a few bugs, support multiple simultaneous non-global backends, variable data types, and some more stuff that I’m forgetting. The specific details of getting that to work aren’t very interesting – a lot of glue code, refactoring and late-night bug-chasing because the backpropagation didn’t work as it should with some specific combination of operations. One memorable bug was that when remapping backend operations to my own OpenBLAS-based backend I forgot that matrix transposition did more than just change its shape – a mistake that cost me weeks in debugging efforts down the line, because things just didn’t work properly with large layers or more than 1 record per minibatch (duh). 3.2 Performance OptimisationsCompared to all the backend work, the “middleware” of layers and optimisers was rather trivial to implement, as there are hundreds of tutorials and papers on how to create certain layers and optimisers, where I only had to map them to our own solution. Really, that part should have taken a few weeks at most, but took that much longer because we only then discovered dozens of bugs and stability issues. Skipping over a lot of uninteresting details here, it should be noted that at this point performance of the framework was quite bad. I’m talking 300ms/iteration of 100 MNIST records with just a few dense layers on a high-end computer bad. This bad performance not only slowed training but also actual development down by quite a lot, hiding a few critical bugs and never letting us test the entire framework in a real-world use case within a reasonable time. You might wonder why we didn’t just fix the performance from the get-go, but we wanted to make the actual training work first so we would have something to show for our thesis. In hindsight not the ideal choice, but it still worked out quite well and otherwise we wouldn’t have been able to demonstrate our project adequately in time for the final presentation. 3.2.1 A Self-Adjusting BufferIt took many months before we finally got around to addressing the performance issues, but there was no single fix in sight, rather a collection of hundreds of small to medium sized improvements. A major issue was the way our SigmaDiff math processor handled operations: for every operation, a copy was created for the resulting data. That added up. The copying was necessary because backwards differentiation requires all intermediate values, so we couldn’t just not copy things. We couldn’t even create all required buffers in a static way ahead of time because there was (and still is) no way to traverse the operations that will be executed – the computation graph is constructed anew every time, and we can’t completely rely on them to remain constant. To introduce a reliable way of buffering anyway, we introduced the concept of sessions: A session was meant to be a set of operations that would be repeated many times. Iterations, essentially. When a session is started we would start storing all created arrays in our own store and when an array of the same dimensions was requested in the next session we could return the one from last session, all without allocating any new memory. If more memory was required than last time, we could still allocate it, if less was used, we could discard it for the next session, rendering this neatly self-adjusting. To not overwrite data that was created within a session but was needed for the next one (e.g. parameters) we added an explicit “limbo” buffer, which was basically just a flag that could be set at runtime for a certain array that marked it as “do not reuse”. 3.2.2 SIMD and Avoiding Intermediate AllocationOther significant performance improvements were adding SIMD instructions (which enables processing of typically 8 values at the same time for CPU-bound arithmetic operations) wherever possible and reducing other memory allocation to a minimum by adding some in-place operations wherever intermediate values weren't strictly needed. For example, copying results when accumulating gradients during backpropoagation on nodes with multiple operands is unnecessary because the intermediate values aren't used. By analysing profilers to death, I eventually got the iteration time for my MNIST sample down to an acceptable 18ms in release configuration (speedup of about 17x). Incidentally, the core was now so fast that our visualiser sometimes crashed because it couldn’t keep up with all the incoming data.3.3 Monitoring with Sigma 3.3.1 The monitoring SystemWhen developing Sigma, we not only focused on the “mathematical” backend but also implemented a feature rich monitoring system which allows any application to be built on top of Sigma (or better said Sigma.Core). Every parameter can be observed, every change hooked, every parameter managed. With this monitoring system, we built a monitor (i.e. application) that can be used to learn Sigma and machine learning in general. 3.3.2 The WPF MonitorUsers should be able to not only use Sigma, but also learn with Sigma. To address this issue, we built a feature-rich application (with WPF) that allows users to interact with Sigma. plot learning graphs, manage parameters and control the AI like controlling a music player. This monitor, as every other component of Sigma, is fully customisable and extensible. All components were designed with reusability in mind, which allows users to build their own complex application on top of the default monitor. But why describe a graphical user interface? See it for yourself, here is the UI (and Sigma) in action. (Example builds of Sigma can be downloaded on GitHub).Learn to learn at the press of a buttonDirect interaction during the learning processSave, restore and share checkpoints3.4 CUDA Support and Finishing TouchesOnly 2 months ago we started finalising and polishing our framework: adding CUDA support, fixing many stability issues and rounding off a few rough spots that annoyed us. The CUDA support part was particularly tricky as I could only use CuBLAS, not CuDNN, because our backend doesn’t, by design, understand individual layers but just raw computation graphs. A problematic side effect of the previously described session-logic was that there was no guarantee when buffers would be freed, as that was the job of the indeterministic GC. To not leak CUDA device memory I added my own bare-bones reference counter to the device memory allocator, which would be updated when buffers were created / finalised, which works surprisingly well. With CuBLAS, many custom optimised kernels and many nights of my time we achieved around 5ms/iteration for the same sample on a single GTX 1080, which we deemed acceptable for our envisioned use cases.  4. ConclusionApproximately 3000 combined hours, tens of thousands of lines of code and many long nights later we are proud to finally present something we deem reasonably usable for what it is: Sigma, a machine learning framework that might help you understand a little bit more about machine learning. As of now, we probably won’t be adding many new features to Sigma, mainly because we’re working on a new project related to it that’s now taking up most of our available time. Even though it lacks a lot of default features (most importantly the host of default layer types other frameworks offer), we’re quite happy with how far we got with our project and hope that it’s an adequate update to our original question 2 years ago. We would be happy if some of you could check it out and give us some feedback. 4.1 The Cost of Creating a Machine Learning FrameworkExcluding time, it’s quite cheap. Honestly, with some solid prior programming experience (so that the low-level programming part doesn't become an issue), the whole thing isn't terribly difficult and is probably something most people could do, given enough time. A lot of time. Overall, we it took us approximately:Some 600 hours of researchSome 2400 hours of development2 tortured souls, preferably sold to the devil in exchange for less bugsWe have long since stopped properly counting, so take these numbers with a grain of salt, but they should be in the right ballpark. 4.2 Final remarksAll in all, an undertaking like this is extremely time intensive. It was very much overkill for a high school thesis from the get-go, and we knew that, but it just kept getting more and more elaborate, essentially taking up all of our available time and then some. It was definitely worth it though, for now we have a solid understanding how things work on a lower level and, most importantly, we can say we’ve actually written a machine learning framework, which grants us additional bragging rights :). Caption by flotothemoon. Posted By: www.eurekaking.com
0 notes
rlxtechoff · 3 years ago
Text
0 notes
javatutorialcorner · 8 years ago
Text
find Linux Command
find
find [pathnames] [conditions]
An extremely useful command for finding particular groups of files (numerous examples follow this description). find descends the directory tree beginning at each pathname and locates files that meet the specified conditions. The default pathname is the current directory. The most useful conditions include -name and -type (for general use), -exec and -size (for advanced use), and -mtime and -user (for administrators). Conditions may be grouped by enclosing them in \( \) (escaped parentheses), negated with !, given as alternatives by separating them with -o, or repeated (adding restrictions to the match; usually only for -name, -type, or -perm). Note that "modification" refers to editing of a file's contents, whereas "change" means a modification, or permission or ownership changes. In other words, -ctime is more inclusive than -atime or -mtime.
Conditions and actions
-amin +n| -n| n Find files last accessed more than n (+n), less than n (-n), or exactly n minutes ago. -anewer file Find files that were accessed after file was last modified. Affected by -follow when after -follow on the command line. -atime +n| -n| n Find files that were last accessed more than n (+n), less than n (-n), or exactly n days ago. Note that find changes the access time of directories supplied as pathnames. -cmin +n| -n| n Find files last changed more than n (+n), less than n (-n), or exactly n minutes ago. -cnewer file Find files that were changed after they were last modified. Affected by -follow when after -follow on the command line. -ctime +n| -n| n Find files that were changed more than n (+n), less than n (-n), or exactly n days ago. A change is anything that changes the directory entry for the file, such as a chmod. -daystart Calculate times from the start of the day today, not 24 hours ago. -depth Descend the directory tree, skipping directories and working on actual files first, and then the parent directories. Useful when files reside in unwritable directories (e.g., when using find with cpio). -empty Continue if file is empty. Applies to regular files and directories. -exec command{ } \ ; Run the Linux command, from the starting directory on each file matched by find (provided command executes successfully on that file—i.e., returns a 0 exit status). When command runs, the argument { } substitutes the current file. Follow the entire sequence with an escaped semicolon (\;). In some shells, the braces may need to be escaped as well. -false Return false value for each file encountered. -follow Follow symbolic links and track the directories visited (don't use with -type l). -fstype type Match files only on type filesystems. Acceptable types include minix, ext, ext2, xia, msdos, umsdos, vfat, proc, nfs, iso9660, hpfs, sysv, smb, and ncpfs. -gid num Find files with numeric group ID of num. -group gname Find files belonging to group gname. gname can be a group name or a group ID number. -ilname pattern A case-insensitive version of -lname. -iname pattern A case-insensitive version of -name. -inum n Find files whose inode number is n. -ipath pattern A case-insensitive version of -path. -iregex pattern A case-insensitive version of -regex. -links n Find files having n links. -lname pattern Search for files that are symbolic links, pointing to files named pattern. pattern can include shell metacharacters and does not treat / or . specially. The match is case-insensitive. -maxdepth num Do not descend more than num levels of directories. -mindepth num Begin applying tests and actions only at levels deeper than num levels. -mmin +n| -n| n Find files last modified more than n (+n), less than n (-n), or exactly n minutes ago. -mount, -xdev Search only for files that reside on the same filesystem as pathname. -mtime +n| -n| n Find files that were last modified more than n (+n), less than n (-n), or exactly n days ago. A modification is a change to a file's data. -name pattern Find files whose names match pattern. Filename metacharacters may be used but should be escaped or quoted. -newer file Find files that were modified more recently than file; similar to -mtime. Affected by -follow only if it occurs after -follow on the command line. -nogroup The file's group ID does not correspond to any group. -noleaf Normally, find assumes that each directory has at least two hard links that should be ignored (a hard link for its name and one for "."--i.e., two fewer "real" directories than its hard link count indicates). -noleaf turns off this assumption, a useful practice when find runs on non-Unix-style filesystems. This forces find to examine all entries, assuming that some might prove to be directories into which it must descend (a time-waster on Unix). -nouser The file's user ID does not correspond to any user. -ok command { }\; Same as -exec, but prompts user to respond with y before command is executed. -path pattern Find files whose names match pattern. Expect full pathnames relative to the starting pathname (i.e., do not treat / or . specially). -perm nnn Find files whose permission flags (e.g., rwx) match octal number nnn exactly (e.g., 664 matches -rw-rw-r--). Use a minus sign before nnn to make a "wildcard" match of any unspecified octal digit (e.g., -perm -600 matches -rw-******, where * can be any mode). -print Print the matching files and directories, using their full pathnames. Return true. This is the default behavior. -regex pattern Like -path, but uses grep-style regular expressions instead of the shell-like globbing used in -name and -path. -size n[c] Find files containing n blocks, or if c is specified, n characters long. -type c Find files whose type is c. c can be b (block special file), c (character special file), d (directory), p (fifo or named pipe), l (symbolic link), s (socket), or f (plain file). -user user Find files belonging to user (name or ID).
Examples
List all files (and subdirectories) in your home directory: find $HOME -print List all files named chapter1 in the /work directory: find /work -name chapter1 List all files beginning with memo owned by ann: find /work -name 'memo*' -user ann -print Search the filesystem (begin at root) for manpage directories: find / -type d -name 'man*' -print Search the current directory, look for filenames that don't begin with a capital letter, and send them to the printer: find . \! -name '[A-Z] *' -exec lpr { }\; Find and compress files whose names don't end with .gz: gzip `find . \! -name '*.gz' -print` Remove all empty files on the system (prompting first): find / -size 0 -ok rm { } \; Search the system for files that were modified within the last two days (good candidates for backing up): find / -mtime -2 -print Recursively grep for a pattern down a directory tree: find /book -print | xargs grep '[Nn] utshell' If the files kt1 and kt2 exist in the current directory, their names can be printed with the command: $ find . -name 'kt[0-9] ' ./kt1 ./kt2 Since the command prints these names with an initial ./ path, you need to specify the ./ when using the -path option: $ find . -path './kt[0-9] ' ./kt1 ./kt2 The -regex option uses a complete pathname, like -path, but treats the following argument as a regular expression rather than a glob pattern (although in this case the result is the same): $ find . -regex './kt[0-9] ' ./kt1 ./kt2
from Java Tutorials Corner http://ift.tt/2w9k32V via IFTTT
0 notes