Knowledge in Java Collection

Collection of data science resources.

This file containing the great resources to learn data science and with the help of these resources you will learn the Data science for free.

Java assignment for BCA student

Check out my other content

Java notes for bit student

Check out my other content

All about JavaScript from basic to advanced.

This file contains about JavaScript definition, Introduction, History, How to run JavaScript?, Advantages, etc.

COLLECTION FRAMEWORKS IN JAVA

detailed information of collection frames is here guys.

Thread life cycle, synchronization, race condition, strings, hierarchy, binary stream, file input, and output stream.buffered stream(Bachelor of engineering).

Thread life cycle, synchronization, race condition, strings, hierarchy, binary stream, file input, and output stream.buffered stream

Arrays in Java

An array is a container object that holds a fixed number of values of a single type. An item in an array is called an element. Every element can be accessed via an index. The first element in an array is addressed via the 0 index, the second via 1, etc.Try your Self:package com.vogella.javaintro.array;public class TestMain { public static void main(String[] args) { // declares an array of integers int[] array; // allocates memory for 10 integers array = new int[10]; // initialize values array[0] = 10; // initialize second element array[1] = 20; array[2] = 30; array[3] = 40; array[4] = 50; array[5] = 60; array[6] = 70; array[7] = 80; array[8] = 90; array[9] = 100; }}

Strings in Java

The String class represents character strings. All string literals, for example, "hello", are implemented as instances of this class. An instance of this class is an object. Strings are immutable, e.g., an assignment of a new value to aString object creates a new object.To concatenate Strings use a StringBuilder.Try Your Self:StringBuilder sb =new StringBuilder("Hello ");sb.append("Eclipse");String s = sb.toString();Avoid using StringBuffer and prefer StringBuilder. StringBuffer is synchronized and this is almost never useful, it is just slower.

Working With Strings

The following lists the most common string operations. Command Description"Testing".equals(text1);                Return true if text1 is equal to "Testing". The check is case-sensitive."Testing".equalsIgnoreCase(text1);       Return true if text1 is equal to "Testing". The check is not case-sensitive. For example, it would also be true for"testing".StringBuilder str1 = new StringBuilder();    Define a new StringBuilder which allows to efficiently add "Strings".str.charat(1);                  Return the character at position 1. (Note: strings are arrays of chars starting with 0)str.substring(1);                       Removes the first characters.str.substring(1, 5);          Gets the substring from the second to the fifth character.str.indexOf("Test")            Look for the String "Test" in String str. Returns the index of the first occurrence of the specified string.str.lastIndexOf("ing")                  Returns the index of the last occurrence of the specifiedString "ing" in the String str.str.endsWith("ing")            Returns true if str ends with String "ing"str.startsWith("Test")      Returns true if String str starts with String"Test".str.trim()                               Removes leading and trailing spaces.str.replace(str1, str2)                  Replaces all occurrences of str1 by str2str2.concat(str1);                         Concatenates str1 at the end of str2.str.toLowerCase() / str.toUpperCase()      Converts the string to lower- or uppercasestr1 + str2                                   Concatenate str1 and str2

Lambdas in Java

What is Lambdas?The Java programming language supports lambdas as of Java 8. A lambda expression is a block of code with parameters. Lambdas allows to specify a block of code which should be executed later. If a method expects afunctional interface as parameter it is possible to pass in the lambda expression instead.The type of a lambda expression in Java is a functional interface.Purpose of lambdas expressions.Using lambdas allows to use a condensed syntax compared to other Java programming constructs. For example theCollection interfaces has forEach method which accepts a lambda expression.List<String> list = Arrays.asList("vogella.com","google.com","heise.de" ) list.forEach(s-> System.out.println(s)); Using method references.You can use method references in a lambda expression. Method reference define the method to be called viaCalledFrom::method. CalledFrom can be * instance::instanceMethod * SomeClass::staticMethod * SomeClass::instanceMethodList<String> list = new ArrayList<>(); list.add("vogella.com"); list.add("google.com"); list.add("heise.de"); list.forEach(System.out::println); Difference between a lambda expression and a closure.The Java programming language supports lambdas but not closures. A lambda is an anonymous function, e.g., it can be defined as parameter. Closures are code fragments or code blocks which can be used without being a method or a class. This means that a closure can access variables not defined in its parameter list and that it can also be assigned to a variable.

Streams

What is streams?A stream from the java.util.stream package is a sequence of elements from a source that supports aggregate operations.IntstreamsAllow to create a stream of sequence of primitive int-valued elements supporting sequential and parallel aggregate operations.package com.vogella.java.streams; import java.util.ArrayList; import java.util.List; import java.util.stream.IntStream; public class IntStreamExample { public static void main(String[] args) { // printout the numbers from 1 to 100 IntStream.range(1, 101).forEach(s -> System.out.println(s)); // create a list of integers for 1 to 100 List<Integer> list = new ArrayList<>(); IntStream.range(1, 101).forEach(it -> list.add(it)); System.out.println("Size " + list.size()); } }

Reduction operations

Reduction operations with streams and lambdas.Allow to create a stream of sequence of primitive int-valued elements supporting sequential and parallel aggregate operations.Try your self:1St package com.vogella.java.streams;public class Task { private String summary; private int duration; public Task(String summary, int duration) { this.summary = summary; this.duration = duration; } public String getSummary() { return summary; } public void setSummary(String summary) { this.summary = summary; } public int getDuration() { return duration; } public void setDuration(int duration) { this.duration = duration; }}2nd:package com.vogella.java.streams;import java.util.ArrayList;import java.util.List;import java.util.Random;import java.util.stream.Collectors;import java.util.stream.IntStream;public class StreamTester { public static void main(String[] args) { Random random = new Random(); // Generate a list of random task List<Task> values = new ArrayList<>(); IntStream.range(1, 20).forEach(i -> values.add(new Task("Task" + random.nextInt(10), random.nextInt(10)))); // get a list of the distinct task summary field List<String> resultList = values.stream().filter( t -> t.getDuration() > 5).map( t -> t.getSummary()).distinct().collect(Collectors.toList()); System.out.println(resultList); // get a concatenated string of Task with a duration longer than 5 hours String collect = values.stream().filter( t -> t.getDuration() > 5).map( t -> t.getSummary()).distinct().collect(Collectors.joining("-")); System.out.println(collect); }}