This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type Student struct { | |
Name string | |
Address string | |
Class string | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
students := make(map[int]string) | |
students[0] = "Harsh" | |
students[1] = "Yash" | |
fmt.Println(students) | |
delete(students, 1) | |
fmt.Println(students) | |
students[1] = "Jain" | |
for roll, name := range students{ | |
fmt.Printf("Roll number of %s is %d \n",name, roll) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
cricketer := []string{1:"Sachin", 2:"Ponting", 3: "Waugh", 4: "Zaheer", 5: "Waqar", 6:"Lee"} | |
batsman := cricketer[1:4] | |
bowler := cricketer[4:7] | |
fmt.Println(batsman) | |
fmt.Println(bowler) | |
cricketer = append(cricketer, "McGrath") | |
fmt.Println(bowler) | |
fmt.Println(cricketer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
var a [3]int = [3]int{1,2,3} | |
fmt.Println("Element at index is",a[1]) | |
fmt.Println("Length of array is",len(a)) | |
for i, v := range(a){ | |
fmt.Printf("Index is %d, and value is %d \n",i,v) | |
} | |
q := [...]int{1, 2, 3} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main(){ | |
var x complex128 = complex(1, 2) | |
var y complex128 = complex(3, 4) | |
fmt.Println(x*y) | |
fmt.Println(real(x*y)) | |
fmt.Println(imag(x*y)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main(){ | |
f := 100 | |
x := &f | |
fmt.Printf(" value of f is %d and the address where f is stored %x \n", f, x); | |
*x = *x * 2 | |
fmt.Printf(" value of f is %d and the address where f is stored %x \n", f, x); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
const boilingF = 212.0 | |
func main(){ | |
var f = boilingF | |
var c = (f - 32) * 5/9; | |
fmt.Printf(" boiling point in Centigrade %g and in Fahrenheit %g \n", c, f); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
import java.util.concurrent.*; | |
public class Main { | |
/** | |
* To book a parking, we need customer details and parking details. | |
* And we don't need any booking return object for the client, in other word, | |
* we can make booking process async/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void demoCancel() throws InterruptedException, ExecutionException { | |
CompletableFuture<String> completableFutureFirst = CompletableFuture.supplyAsync(() -> { | |
System.out.println("Task Running inside completable Future"); | |
try { | |
Thread.sleep(500); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
return "result"; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void demoCompleteExceptionally() throws InterruptedException, ExecutionException { | |
CompletableFuture<String> completableFutureFirst = CompletableFuture.supplyAsync(() -> { | |
System.out.println("Task Running inside completable Future"); | |
try { | |
Thread.sleep(500); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
return "oops"; | |
}); |