Java Articles

Page 314 of 450

Create a simple calculator using Java Swing

karthikeya Boyini
karthikeya Boyini
Updated on 19-Jun-2020 24K+ Views

Swing API is a set of extensible GUI Components to ease the developer's life to create JAVA based Front End/GUI Applications. It is built on top of AWT API and acts as a replacement of AWT API since it has almost every control corresponding to AWT controls.Following example showcases a simple calculator application.import java.awt.BorderLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; public class Calculator implements ActionListener {    private static JTextField inputBox;    Calculator(){}    public static void main(String[] args) {       createWindow();    } ...

Read More

Create a simple calculator using Java Swing

karthikeya Boyini
karthikeya Boyini
Updated on 19-Jun-2020 24K+ Views

Swing API is a set of extensible GUI Components to ease the developer's life to create JAVA based Front End/GUI Applications. It is built on top of AWT API and acts as a replacement of AWT API since it has almost every control corresponding to AWT controls.Following example showcases a simple calculator application.import java.awt.BorderLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; public class Calculator implements ActionListener {    private static JTextField inputBox;    Calculator(){}    public static void main(String[] args) {       createWindow();    } ...

Read More

Conversion of Set To Stream in Java

Samual Sam
Samual Sam
Updated on 18-Jun-2020 997 Views

Being a type of Collection, we can convert a set to Stream using its stream() method. Example import java.util.HashSet; import java.util.Set; import java.util.stream.Stream; public class Tester {     public static void main(String args[]) {         Set<String> set = new HashSet<String>();         set.add("a");         set.add("b");         set.add("c");         set.add("d");         set.add("e");         set.add("f");         Stream<String> stream = set.stream();         stream.forEach(data->System.out.print(data+" "));     } } Output a b c d e f

Read More

Conversion of Set To Stream in Java

Samual Sam
Samual Sam
Updated on 18-Jun-2020 997 Views

Being a type of Collection, we can convert a set to Stream using its stream() method. Example import java.util.HashSet; import java.util.Set; import java.util.stream.Stream; public class Tester {     public static void main(String args[]) {         Set<String> set = new HashSet<String>();         set.add("a");         set.add("b");         set.add("c");         set.add("d");         set.add("e");         set.add("f");         Stream<String> stream = set.stream();         stream.forEach(data->System.out.print(data+" "));     } } Output a b c d e f

Read More

Character Stream vs Byte Stream in Java

Samual Sam
Samual Sam
Updated on 18-Jun-2020 11K+ Views

Byte StreamsJava byte streams are used to perform input and output of 8-bit bytes. Though there are many classes related to byte streams but the most frequently used classes are, FileInputStream and FileOutputStream. Following is an example which makes use of these two classes to copy an input file into an output file −Exampleimport java.io.*; public class CopyFile {    public static void main(String args[]) throws IOException {               FileInputStream in = null;       FileOutputStream out = null;       try {          in = new ...

Read More

Character Stream vs Byte Stream in Java

Samual Sam
Samual Sam
Updated on 18-Jun-2020 11K+ Views

Byte StreamsJava byte streams are used to perform input and output of 8-bit bytes. Though there are many classes related to byte streams but the most frequently used classes are, FileInputStream and FileOutputStream. Following is an example which makes use of these two classes to copy an input file into an output file −Exampleimport java.io.*; public class CopyFile {    public static void main(String args[]) throws IOException {               FileInputStream in = null;       FileOutputStream out = null;       try {          in = new ...

Read More

Checking internet connectivity in Java

Samual Sam
Samual Sam
Updated on 18-Jun-2020 6K+ Views

Internet connectivity can be checked using java.net.URL and java.net.URLConnection class. Following are the required steps.Create a URL object and pass it the URL say GoogleCall URL.openConnection() method to get a URLConnection object.Call URLConnection.connect() method to check the internet connectivity. connect() method opens a communications link to the resource referenced by the passed URL if a connection has not already been established.Exampleimport java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; public class Tester {    public static void main(String[] args) {       try {          URL url = new URL("http://www.google.com");          URLConnection connection ...

Read More

Checking internet connectivity in Java

Samual Sam
Samual Sam
Updated on 18-Jun-2020 6K+ Views

Internet connectivity can be checked using java.net.URL and java.net.URLConnection class. Following are the required steps.Create a URL object and pass it the URL say GoogleCall URL.openConnection() method to get a URLConnection object.Call URLConnection.connect() method to check the internet connectivity. connect() method opens a communications link to the resource referenced by the passed URL if a connection has not already been established.Exampleimport java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; public class Tester {    public static void main(String[] args) {       try {          URL url = new URL("http://www.google.com");          URLConnection connection ...

Read More

Automatic resource management in Java

Samual Sam
Samual Sam
Updated on 18-Jun-2020 976 Views

automatic resource management or try-with-resources is a new exception handling mechanism that was introduced in Java 7, which automatically closes the resources used within the try-catch block.ResourceA resource is an object which is required to be closed once our program finishes. For example, a file is read, database connection and so on.UsageTo use the try-with-resources statement, you simply need to declare the required resources within the parenthesis, and the created resource will be closed automatically at the end of the block. Following is the syntax of the try-with-resources statement.Syntaxtry(FileReader fr = new FileReader("file path")) {        // use the resource ...

Read More

Automatic resource management in Java

Samual Sam
Samual Sam
Updated on 18-Jun-2020 976 Views

automatic resource management or try-with-resources is a new exception handling mechanism that was introduced in Java 7, which automatically closes the resources used within the try-catch block.ResourceA resource is an object which is required to be closed once our program finishes. For example, a file is read, database connection and so on.UsageTo use the try-with-resources statement, you simply need to declare the required resources within the parenthesis, and the created resource will be closed automatically at the end of the block. Following is the syntax of the try-with-resources statement.Syntaxtry(FileReader fr = new FileReader("file path")) {        // use the resource ...

Read More
Showing 3131–3140 of 4,498 articles
« Prev 1 312 313 314 315 316 450 Next »
Advertisements