- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 2617 Articles for Java
![Mahesh Parahar](https://www.tutorialspoint.com/assets/profiles/127878/profile/60_2277600-1655382864.jpg)
422 Views
Problem StatementWith a given long integer n, write a program to find the difference between sum of the odd digits and even digits to be 0 or not. Index starts from 0.Examplen = 1212112 Sum of odd position elements = 2 + 2 + 1 = 5 Sum of even position elements = 1 + 1 + 1 + 2 = 5 Difference = 5 - 5 = 0 Output = YesExample Live DemoFollowing is the program in Java to find the required output.class JavaTester { public static int difference(int n){ return (n % ... Read More
![Mahesh Parahar](https://www.tutorialspoint.com/assets/profiles/127878/profile/60_2277600-1655382864.jpg)
729 Views
Problem StatementWith a given number n, write a program to find the difference between sum of the squares of and square of sum first n natural numbers.Examplen = 3 Squares of first three numbers = 3x3 + 2x2 + 1x1 = 9 + 4 + 1 = 14 Squares of sum of first three numbers = (3 + 2 + 1)x(3 + 2 + 1) = 6x6 = 36 Difference = 36 - 14 = 22Example Live DemoFollowing is the program in Java to find the required difference.public class JavaTester { public static int difference(int n){ ... Read More
![raja](https://www.tutorialspoint.com/assets/profiles/107595/profile/60_161286-1564642329.jpg)
171 Views
JShell is a command-line tool introduced in Java 9 that evaluates declarations, statements, and expressions without the main() method. JShell can set up a text editor called JShell Edit Pad, which allows us to modify the code very easily, and it can be launched using the "/edit" command.Below are the different "/edit" commands used in Jshell./edit /edit [ID] /edit [Code_Name]/edit: This command can be used without an argument, the "/edit" command displays all the active code in the text editor./edit [ID]: This command displays in the text editor the code corresponding to the ID entered./edit [Code_Name]: This comamnd displays in the ... Read More
![raja](https://www.tutorialspoint.com/assets/profiles/107595/profile/60_161286-1564642329.jpg)
252 Views
Java 9 introduced a new interactive tool called JShell. This tool can be used to execute expressions, classes, interfaces, enums, and etc.The detailed documentation can be available in JShell with full information, as well as the use of its internal commands with the various options. This documentation can be accessed using two commands: "/help" and "/?". JShell's documentation is not only limited to information regarding its internal controls, and also includes Javadoc.In the below code snippet, the result can be obtained by using the "/help" command.jshell> /help | Type a Java language expression, statement, or declaration. | Or ... Read More
![raja](https://www.tutorialspoint.com/assets/profiles/107595/profile/60_161286-1564642329.jpg)
224 Views
Flow API in Java 9 corresponds to Reactive Streams specification, which is a defacto standard. It contains a minimal set of interfaces that capture the heart of asynchronous publication and subscription.Below are the key interfaces of Flow API:1) Flow.Publisher: It produces items for subscribers to consume, and it contains only method: subscribe(Subscriber), whose purpose should be obvious.Syntaxvoid subscribe(Flow.Subscriber
![raja](https://www.tutorialspoint.com/assets/profiles/107595/profile/60_161286-1564642329.jpg)
1K+ Views
Flow API (java.util.concurrent.Flow) has introduced in Java 9. It helps to understand different ways in which the Publisher and Subscriber interfaces interact to perform desired operations.Flow API consists of Publisher, Subscriber, Subscription, and Processor interfaces, which can be based on reactive stream specification.In the below example, we can implement Flow API by using Publisher-Subscriber interfaces.Exampleimport java.util.concurrent.Flow.Publisher; import java.util.concurrent.Flow.Subscriber; import java.util.concurrent.Flow.Subscription; public class FlowAPITest { public static void main(String args[]) { Publisher publisherSync = new Publisher() { // Create publisher @Override public void subscribe(Subscriber
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
229 Views
In addition to the local coordinate system for positioning its nodes, JavaFX provides an additional coordinate system for the text node.The textOrigin property specifies the origin of the coordinates of the text node in the parent coordinate system. You can set values to this property using the setTextOrigin() method. This method accepts one of the constants of the enum named VPos. This enum contains 4 constants namely: BASELINE, BOTTOM, CENTER and, TOP.Exampleimport java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Scanner; import javafx.application.Application; import javafx.geometry.VPos; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.text.Text; public class TextOriginExample extends Application { ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
3K+ Views
In JavaFX, the text node is represented by the Javafx.scene.text.Text class. To insert/display text in JavaFx window you need to −Instantiate the Text class.Set the basic properties like position and text string, using the setter methods or, bypassing them as arguments to the constructor.Add the created node to the Group object.The strikethrough property of the javafx.scene.text.Text class determines whether each line of the text should have a straight line passing through the middle of it. You can set the value to this property using the setStrikeThrough() method. It accepts a boolean value. You can strike though the text (node) by ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
1K+ Views
The line spacing property of the javafx.scene.text.The text class specifies the line spacing between the lines of the text (node) vertically.You can set the value to this property using the setLineSpacing() method. This method accepts a boolean value as a parameter and sets the specified space between the lines (vertically).Exampleimport java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Scanner; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.text.Text; import javafx.scene.text.TextAlignment; public class TextSpacing extends Application { public void start(Stage stage) throws FileNotFoundException { //Reading the contents of a text file. InputStream inputStream ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
6K+ Views
You can set a fixed width for the text in user space by setting the value to the wrappingWidth property. Once you do so, given width is considered as the boundary of the text in user coordinates and, the text is arranged width in the given width.If you haven’t given any value for this property, by default, the length longest line in the text is considered as the width of the bounding box.Text alignment is the arrangement of the text horizontally within the bounding box. You can adjust the alignment of the text using the setTextAlignment() method. This method accepts ... Read More