Object Oriented Programming Articles - Page 246 of 579

JavaScript Basic Array Methods

Alshifa Hasnain
Updated on 24-Feb-2025 18:27:46

831 Views

In this article, we will learn about different basic array methods in JavaScript. Adding and Removing Elements Some basic JavaScript array methods for adding and removing elements − Method Description ... Read More

JavaScript WebAPI File File.type Property

AmitDiwan
Updated on 06-May-2020 11:58:12

136 Views

The JavaScript File WebAPI file.type property indicated the media type of the file.Following is the code for the File WebApi File.type property −Example Live Demo Document body {    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result {    font-size: 18px;    font-weight: 500;    color: red; } JavaScript file.type property Upload a file using the above input type to get its file type let resultEle = document.querySelector(".result"); document .querySelector(".fileInput") .addEventListener("change", (event) => {    resultEle.innerHTML +=    "File name = " + event.target.files[0].name + "";    resultEle.innerHTML += "File type = " + event.target.files[0].type; }); OutputOn clicking the “Choose file” button −

JavaScript WebAPI File File.size Property

AmitDiwan
Updated on 06-May-2020 11:55:32

122 Views

The JavaScript File WebAPI file.size property returns the size of file in bytes.Following is the code for the File WebApi File.size property −Example Live Demo Document body {    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result {    font-size: 18px;    font-weight: 500;    color: red; } JavaScript file.size property Upload a file using the above input type to get its file size let resultEle = document.querySelector(".result"); document .querySelector(".fileInput") .addEventListener("change", (event) => {    resultEle.innerHTML += "File name = " + event.target.files[0].name + ‘;    resultEle.innerHTML ... Read More

JavaScript Detecting a mobile browser

AmitDiwan
Updated on 06-May-2020 11:46:18

238 Views

Following is the code for detecting a mobile browser in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample {    font-size: 18px;    font-weight: 500; } Detecting a mobile browser CLICK HERE Click on the above button to see if it is a mobile device or not let fillEle = document.querySelector(".sample"); let date = new Date(); let primitiveDef = date[Symbol.toPrimitive]("default"); let primitiveNum = date[Symbol.toPrimitive]("number"); document.querySelector(".Btn").addEventListener("click", () => {    var checkMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);    if (checkMobile) {       fillEle.innerHTML = "This ... Read More

Mobile

JavaScript date.@@toPrimitive() function

AmitDiwan
Updated on 06-May-2020 11:59:40

109 Views

The JavaScript date.@@toPrimitive() function converts the date object into a primitive value.Following is the code for date formats in JavaScript −Example Live Demo Document body {    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample {    font-size: 18px;    font-weight: 500; } JavaScript date.@@toPrimitive() functiont CLICK HERE Click on the above button to see the date as primitive value let fillEle = document.querySelector(".sample"); let date = new Date(); let primitiveDef = date[Symbol.toPrimitive]("default"); let primitiveNum = date[Symbol.toPrimitive]("number"); document.querySelector(".Btn").addEventListener("click", () => {    fillEle.innerHTML += "Hint = default :" + primitiveDef + "";    fillEle.innerHTML += "Hint = number :" + primitiveNum; }); OutputOn clicking the “CLICK HERE” button −

How to print pid, info, children, and destroy processes in JShell in Java 9?

raja
Updated on 03-May-2020 09:53:31

182 Views

JShell is a Java Shell tool used to execute simple java statements like classes, methods, interfaces, enums,  and etc.. evaluates it, and prints the result in a command-line prompt.Java has improved Process API to manage and control operating system processes. ProcessHandle interface identifies and provides control of native processes, methods to check processes liveness, and destroy the process. ProcessHandle.Info interface gives an Information snapshot of a process.In the below code snippet, we can print pid, info, children,  and destroy processes of Process API.in JShell tool.Snippetjshell> ProcessHandle currentProcess = ProcessHandle.current(); currentProcess ==> 3960 jshell> System.out.println("Current Process Id: = " + currentProcess.pid()); Current Process Id: = 3960 jshell> ... Read More

How to get system properties in JShell in Java 9?

raja
Updated on 02-May-2020 11:09:29

532 Views

JShell is a REPL (Read-Evaluate-Print-Loop) tool used to execute simple statements, evaluates it, and displays the result without a main() method. We can start it by simply type "jshell" in command-line prompt.We need to get the system properties by using System.getProperty() and System.getProperties() methods.In the below code snippet, we can able to display the system properties in the JShell tool by using static method property() of System class.Snippet-1jshell> System.getProperty("java.class.path") $1 ==> "C:\Program Files\Java\jdk-9.0.4\lib;C:\json-jars\json.jar;.;C:\json-jars\json-simple.jar;.;C:\json-jars\gson.jar;.;C:\json-jars\commons-io.jar;.;C:\json-jars\jackson-core.jar;.;C:\json-jars\jackson-databind.jar;.;C:\json-jars\jackson-annotations.jar;.;C:\json jars\flexjson.jar;.;C:\json-jars\jackson-dataformat-xml.jar;.;C:\json-jars\stax2-api.jar;.;C:\json-jars\jackson-dataformat-csv.jar;.;C:\json-jars\javax.json.jar;.;C:\json jars\javax.json-api.jar;.;C:\json-jars\jackson-module-jsonSchema.jar;.;C:\json-jars\json-lib.jar;.;C:\json-jars\commons-lang.jar;.;C:\json-jars\commons-logging.jar;.;"In the below code snippet, we have to use the “properties” object that extends Hashtable. So all properties can be listed as key/value pairs in the JShell tool by using ... Read More

How to implement JShell using JavaFX in Java 9?

raja
Updated on 02-May-2020 09:45:07

332 Views

JShell is an interactive tool used to implement sample expressions. We can implement JShell programmatically using JavaFX application then we need to import a few packages in the java program listed belowimport jdk.jshell.JShell; import jdk.jshell.SnippetEvent; import jdk.jshell.VarSnippet;In the below example, implemented a sample Java FX application. We will enter different values in the text field and press the "eval" button. It will display values with corresponding data types in a list.Exampleimport javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.Stage; import java.util.List; import jdk.jshell.JShell; import jdk.jshell.SnippetEvent; import jdk.jshell.VarSnippet; public class JShellFXTest extends Application {    @Override    public void start(Stage primaryStage) ... Read More

How to implement HashMap, LinkedHashMap, and TreeMap in JShell in Java 9?

raja
Updated on 01-May-2020 17:24:58

252 Views

JShell is a command-line prompt tool introduced in Java 9, and it is also called a REPL tool to evaluate simple statements, executes it, and print the output immediately.A Map interface specifies a contract to implement collections of elements in the form of key/value pairs. Java collection classes that implement the Map interface are HashMap, LinkedHashMap, and TreeMap.In the below code snippet, the elements of HashMap are not guaranteed to store either in an insertion order or in the sorted order of keys.Snippet-1jshell> HashMap hashMap = new HashMap(); hashMap ==> {} jshell> hashMap.put("Adithya", 101); $2 ==> null jshell> hashMap.put("Jai", 102); $3 ==> null ... Read More

Differences between CompletableFuture and Future in Java 9?

raja
Updated on 01-May-2020 11:45:14

6K+ Views

CompletableFuture class implements Future interface in Java. CompletableFuture can be used as a Future that has explicitly completed. The Future interface doesn’t provide a lot of features, we need to get the result of asynchronous computation using the get() method, which is blocked, so there is no scope to run multiple dependent tasks in a non-blocking fashion whereas CompleteFuture class can provide the functionality to chain multiple dependent tasks that run asynchronously, so we can create a chain of tasks where the next task is triggered when the result of the current task is available.Syntaxpublic class CompletableFuture extends Object implements Future, CompletionStageExampleimport java.util.function.Supplier; import java.util.concurrent.CompletableFuture; ... Read More

Advertisements