Articles on Trending Technologies

Technical articles with clear explanations and examples

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

raja
raja
Updated on 19-Mar-2020 487 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 646 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 458 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 715 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

Java program to calculate the GCD of a given number using recursion

karthikeya Boyini
karthikeya Boyini
Updated on 13-Mar-2020 3K+ Views

You can calculate the GCD of given two numbers, using recursion as shown in the following program.Exampleimport java.util.Scanner; public class GCDUsingRecursion { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter first number :: "); int firstNum = sc.nextInt(); System.out.println("Enter second number :: "); int secondNum = sc.nextInt(); System.out.println("GCD of given two numbers is ::"+gcd(firstNum, secondNum)); } public static int gcd(int num1, int num2) { if (num2 != 0){ return gcd(num2, num1 % num2); } else{ return num1; } } }OutputEnter first number :: 625 Enter second number :: 125 GCD of given two numbers is ::125

Read More

What is the importance of the ProcessHandle interface in Java 9?

raja
raja
Updated on 13-Mar-2020 710 Views

ProcessHandle interface introduced in Java 9. It allows us to perform actions and check the state of a process that relates. This interface provides the process’s native process ID (pid), start time, accumulated CPU time, arguments, command, user, parent process, and descendants.ProcessHandle interface allows us to perform the following actions.It returns a ProcessHandle.Info containing further information about a processThe Pid of a processIf it is aliveRetrieve a snapshot of the direct children of a processRetrieve a snapshot of all descents of a processRetrieve a snapshot of all currently running processesAllow the process to be destroyedIt returns a CompletableFuture with a ProcessHandle for when the ...

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