Articles on Trending Technologies

Technical articles with clear explanations and examples

How to print the pattern of stars in JShell in Java 9?

raja
raja
Updated on 19-Mar-2020 382 Views

JShell is a REPL tool introduced in Java 9 that allows us to execute Java code and getting results immediately. We can evaluate expressions or simple algorithms without creating a new project, compile or build it by using JShell. We can also execute expressions, use imports, define classes, methods, and variables. It is a part of Java 9 JDK but not JRE.We can start JShell session in command-prompt by simply typing jshell. We can use different commands: /exit to quit the JShell session, reset/reload JShell anytime by typing /reset, and /reload, /import to list the imports, etc.In the below example, ...

Read More

What are Compact Strings in Java 9?

raja
raja
Updated on 19-Mar-2020 511 Views

Since Java 9, the JVM optimizes strings by using a new feature called Compact Strings. Instead of having a char[] array, a string can be represented as a byte[] array. We can use either UTF-16 or Latin-1 to produce either one or two bytes per character. If JVM detects the string contains only ISO-8859-1/Latin-1 characters, then string uses one byte per character internally.The string can be represented with a compact string or not is detected when the string is created. This feature has enabled by default and switches off using the -XX:-CompactStrings. It doesn't revert to a char[] implementation and ...

Read More

How to display all stack frames of the current thread in Java 9?

raja
raja
Updated on 19-Mar-2020 536 Views

Stack Walking API can provide a flexible mechanism to traverse and extract information from call stacks that allow us to filter and access frames in a lazy manner. StackWalker class is an entry point to Stack Walking API. The stack trace is a representation of a call stack at a certain point of time in which each element represents a method invocation. It contains all invocations from the start of a thread until the point it’s generated.In the below example, we can print/display all stack frames of the current thread by using StackWalker API.Exampleimport java.lang.StackWalker.StackFrame; import java.lang.reflect.Method; import java.util.List; import java.util.stream.Collectors; public ...

Read More

How to convert the content of the file into uppercase or lowercase?

Chirag Nagrekar
Chirag Nagrekar
Updated on 16-Mar-2020 3K+ Views

To convert the content of the file into the upper case, you need to use the method ToUpper() and to convert into lower case, you need to use ToLower() method.Upper case example(Get-Content D:\Temp\PowerShellaliases.txt).ToUpper()OutputPS C:\WINDOWS\system32> (Get-Content D:\Temp\PowerShellaliases.txt).ToUpper() COMMANDTYPE     NAME                                               VERSION    SOURCE -----------     ----                                               -------    ------ ALIAS         ...

Read More

How to search in the file using PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 16-Mar-2020 14K+ Views

To search the content in the file in PowerShell, you need to first get the content from the file using Get-Content command and then you need to add Select-String pipeline command. In the below example, we need to search the lines which contain the Get word.PS C:\WINDOWS\system32> Get-Content D:\Temp\PowerShellaliases.txt | Select-String -Pattern Get Alias           cat -> Get-Content Alias           dir -> Get-ChildItem Alias           gal -> Get-Alias Alias           gbp -> Get-PSBreakpoint Alias           gc -> Get-Content Alias   ...

Read More

How to retrieve a specific number of lines from files in PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 16-Mar-2020 2K+ Views

To retrieve the specific number of lines from the beginning or the end of the file, you first need to get the content of the file using Get-Content and then need to pipeline the -First for retrieving the number of files from the beginning and -Last to retrieve the number of lines from the bottom.Check the below example of retrieving the content of the first 10 lines.ExampleGet-Content D:\Temp\PowerShellaliases.txt -First 10OutputPS C:\WINDOWS\system32> Get-Content D:\Temp\PowerShellaliases.txt -First 10 CommandType     Name                                               Version ...

Read More

How to retrieve the content of the file in PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 16-Mar-2020 685 Views

To retrieve the content of the file in PowerShell, you need to use Get-Content cmdlet. For example, we are going to retrieve the content of the text file called Aliases.txt from a specific location.ExampleGet-Content D:\Temp\aliases.txtOutputPS C:\WINDOWS\system32> Get-Content D:\Temp\aliases.txt # Alias File # Exported by : admin # Date/Time : 26 January 2020 19:20:24 # Computer : DESKTOP-9435KM9 "foreach", "ForEach-Object", "", "ReadOnly,  AllScope" "%", "ForEach-Object", "", "ReadOnly,  AllScope" "where", "Where-Object", "", "ReadOnly,  AllScope" "?", "Where-Object", "", "ReadOnly,  AllScope" "ac", "Add-Content", "", "ReadOnly,  AllScope" "clc", "Clear-Content", "", "ReadOnly,  AllScope" "cli", "Clear-Item", "", "ReadOnly,  AllScope" "clp", "Clear-ItemProperty", "", "ReadOnly,  AllScope" "clv", "Clear-Variable", "", "ReadOnly,  AllScope" "compare", "Compare-Object", "", "ReadOnly,  AllScope" "cpi", "Copy-Item", "", "ReadOnly,  AllScope" "cpp", "Copy-ItemProperty", "", "ReadOnly,  AllScope" "cvpa", "Convert-Path", ...

Read More

What is Get-Content in PowerShell used for?

Chirag Nagrekar
Chirag Nagrekar
Updated on 16-Mar-2020 493 Views

Get-Content cmdlet in PowerShell is useful for retrieving the contents of the file or the function. This cmdlet is introduced in PowerShell 3.0. When a file is read by this cmdlet, it reads one line at a time and finally returns the whole content as a collection of objects.SyntaxGet-Content    [-ReadCount ]    [-TotalCount ]    [-Tail ]    [-Path]    [-LiteralPath]    [-Filter ]    [-Include ]    [-Exclude ]    [-Force]    [-Credential ]    [-Delimiter ]    [-Wait]    [-Raw]    [-Encoding ]    [-AsByteStream]    [-Stream ]    []

Read More

How to clear the content of the recycle bin in PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 16-Mar-2020 3K+ Views

Recycle bin in Windows operating system is to store the soft-deleted data. Soft deleted data means, data that is not deleted with (SHIFT + DEL) button but simply deleted with DEL button. Each local disk has its own configured recycle bin space.To delete the recycle bin data using GUI, you can simply right click and delete the content.It is also possible to delete the recycle bin content with the PowerShell command with the Clear-Recyclebin cmdlet. This command is introduced in PowerShell 5 and available in newer versions as well.ExampleClear-RecycleBinOutputPS C:\WINDOWS\system32> Clear-RecycleBin Confirm Are you sure you want to perform this action? Performing the operation "Clear-RecycleBin" on target "All of the contents of the Recycle Bin". [Y] Yes  [A] Yes to All ...

Read More

What is Variable Handle in Java 9?

raja
raja
Updated on 13-Mar-2020 813 Views

Variable Handle is a variable or reference to a set of variables, including other components of a static field, non-static fields, and outer array elements in the heap data structure. It means that Variable Handle is similar to the existing Method Handle. It can be represented by using java.lang.invoke.VarHandle class. We can use java.lang.invoke.MethodHandles.Lookup static factory method to create Variable Handle objects. It can also be used to access a single element in the array, and byte[] array.Syntaxpublic abstract class VarHandle extends ObjectExampleimport java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.Arrays; public class VarHandleTest { public static void main(String ...

Read More
Showing 54481–54490 of 61,299 articles
Advertisements