Tutorial by Examples: l

Apart from LF the only allowed white space character is Space (ASCII value 32). Note that this implies that other white space characters (in, for instance, string and character literals) must be written in escaped form. \', \", \\, \t, \b, \r, \f, and \n should be preferred over corres...
package com.example.my.package; The package declaration should not be line wrapped, regardless of whether it exceeds the recommended maximum length of a line.
Order of class members Class members should be ordered as follows: Fields (in order of public, protected and private) Constructors Factory methods Other Methods (in order of public, protected and private) Ordering fields and methods primarily by their access modifiers or identifier is not ...
int someMethod(String aString, List<Integer> aList, Map<String, String> aMap, int anInt, long aLong, Set<Number> aSet, double aDouble) { … } int someMethod(String aString, List&...
One variable per declaration (and at most one declaration per line) Square brackets of arrays should be at the type (String[] args) and not on the variable (String args[]). Declare a local variable right before it is first used, and initialize it as close to the declaration as possible.
Runnable r = () -> System.out.println("Hello World"); Supplier<String> c = () -> "Hello World"; // Collection::contains is a simple unary method and its behavior is // clear from the context. A method reference is preferred here. appendFilter(goodStrings::cont...
long l = 5432L; int i = 0x123 + 0xABC; byte b = 0b1010; float f1 = 1 / 5432f; float f2 = 0.123e4f; double d1 = 1 / 5432d; // or 1 / 5432.0 double d2 = 0x1.3p2; long literals should use the upper case letter L suffix. Hexadecimal literals should use upper case letters A-F. All other num...
You can also use line-height to center vertically a single line of text inside a container : CSS div { height: 200px; line-height: 200px; } That's quite ugly, but can be useful inside an <input /> element. The line-height property works only when the text to be centered spans ...
Note the use of {{.}} to output the item within the template. package main import ( "fmt" "os" "text/template" ) func main() { const ( letter = `Dear {{.}}, How are you?` ) tmpl, err := template.New("letter").Pa...
Note the use of {{range .}} and {{end}} to cycle over the collection. package main import ( "fmt" "os" "text/template" ) func main() { const ( letter = `Dear {{range .}}{{.}}, {{end}} How are you?` ) tmpl, err := template...
In this example, a function map named funcMap is supplied to the template via the Funcs() method and then invoked inside the template. Here, the function increment() is used to get around the lack of a less than or equal function in the templating language. Note in the output how the final item in t...
Note how field values are obtained using {{.FieldName}}. package main import ( "fmt" "os" "text/template" ) type Person struct { FirstName string LastName string Street string City string State string Zip...
Note the different package import. package main import ( "fmt" "html/template" "os" ) type Person struct { FirstName string LastName string Street string City string State string Zip string Ava...
First, here's what can happen when text/template is used for HTML. Note Harry's FirstName property). package main import ( "fmt" "html/template" "os" ) type Person struct { FirstName string LastName string Street string Cit...
Using regular recursion, each recursive call pushes another entry onto the call stack. When the recursion is completed, the application has to pop each entry off all the way back down. If there are much recursive function calls it can end up with a huge stack. Scala automatically removes the recurs...
It is possible to specify log destination with something that statisfies io.Writer interface. With that we can log to file: package main import ( "log" "os" ) func main() { logfile, err := os.OpenFile("test.log", os.O_RDWR|os.O_CREATE|os.O_APPEND,...
It is also possible to log to syslog with log/syslog like this: package main import ( "log" "log/syslog" ) func main() { syslogger, err := syslog.New(syslog.LOG_INFO, "syslog_example") if err != nil { log.Fatalln(err) } l...
context.lineCap=capStyle // butt (default), round, square Sets the cap style of line starting points and ending points. butt, the default lineCap style, shows squared caps that do not extend beyond the line's starting and ending points. round, shows rounded caps that extend beyond the ...
context.lineJoin=joinStyle // miter (default), round, bevel Sets the style used to connect adjoining line segments. miter, the default, joins line segments with a sharp joint. round, joins line segments with a rounded joint. bevel, joins line segments with a blunted joint. <!doctype...
context.strokeStyle=color Sets the color that will be used to stroke the outline of the current path. These are color options (these must be quoted): A CSS named color, for example context.strokeStyle='red' A hex color, for example context.strokeStyle='#FF0000' An RGB color, for e...

Page 328 of 861