Set Only Numeric Value for EditText in Android

Azhar
Updated on 02-Aug-2019 06:08:36

819 Views

This example demonstrates how do I set only numeric value for editText in Android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.InputType; import android.view.View; import android.widget.Button; import android.widget.EditText; public class MainActivity extends AppCompatActivity {    Button button;    EditText editText;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main); ... Read More

Read Data from Keyboard in Java

Maruthi Krishna
Updated on 01-Aug-2019 14:27:57

5K+ Views

The java.io package provides various classes to read write data from various sources and destinations.You can read data from user (keyboard) using various classes such as, Scanner, BufferedReader, InputStreamReader, Console etc.Using Scanner classFrom Java 1.5 Scanner class was introduced. This class accepts a File, InputStream, Path and, String objects, reads all the primitive data types and Strings (from the given source) token by token using regular expressions. By default, whitespace is considered as the delimiter (to break the data into tokens).To read data from keyboard you need to use standard input as source (System.in). For each datatype a nextXXX() is ... Read More

Set File Permissions in Java

Maruthi Krishna
Updated on 01-Aug-2019 14:22:20

8K+ Views

In general, whenever you create a file you can restrict/permit certain users from reading/writing/executing a file.In Java files (their abstract paths) are represented by the Files class of the java.io package. This class provides various methods to perform various operations on files such as read, write, delete, rename etc.In addition, this class also provides the following methods −setExecutble() − This method is sued to set the execute permissions to the file represented by the current (File) object.setWritable() − This method is used to set the write permissions to the file represented by the current (File) object.setReadable() − This method is ... Read More

Change Directory Using File Object in Java

Maruthi Krishna
Updated on 01-Aug-2019 14:18:13

2K+ Views

The File classThe class named File of the java.io package represents a file or directory (path names) in the system. This class provides various methods to perform various operations on files/directories.This class provides various methods to manipulate files, The renameTo() method of the File class accepts a String representing a destination file and, renames the abstract file path of the current file to the given one.This method actually moves the file from source path to the destination path.Exampleimport java.io.File; public class MovingFile {    public static void main(String args[]) {       //Creating a source file object       ... Read More

Access 'this' Keyword Inside an Arrow Function in JavaScript

vineeth.mariserla
Updated on 01-Aug-2019 14:12:25

578 Views

"this" keyword in an arrow functionThe JavaScript 'this' keyword refers to the object it belongs to. In an arrow function, 'this' belongs to a global object. Inside a simple function, there might be chances that 'this' keyword can result in undefined but in an arrow function it results in an exact value.ExampleLive Demo    function Student(fname, grade) {       this.fname = fname;       this.grade = grade;       this.details = function() {          return () => {             document.write(`Hi, I'm ${this.fname} from ${this.grade} grade`);          };       }    } let info = new Student('picaso', 'seventh'); let printInfo = info.details(); printInfo(); OutputHi, I'm picaso from seventh grade

Read Contents of a File Using Scanner Class

Maruthi Krishna
Updated on 01-Aug-2019 14:08:57

15K+ Views

From Java 1.5 Scanner class was introduced. This class accepts a File, InputStream, Path and, String objects, reads all the primitive data types and Strings (from the given source) token by token using regular expressions. By default, whitespace is considered as the delimiter (to break the data into tokens).To read various datatypes from the source using the nextXXX() methods provided by this class.Reading the contents of a file −To read the contents of a file, Scanner class provides various constructors.Sr.NoConstructors and Description1Scanner(File source)Used to read data from the file represented by the given File object.2Scanner(InputStream source)Used to read data from ... Read More

What is Scanner Class in Java?

Maruthi Krishna
Updated on 01-Aug-2019 14:03:58

547 Views

Until Java 1.5 to read data from the user programmers used to depend on the character stream classes and byte stream classes.From Java 1.5 Scanner class was introduced. This class accepts a File, InputStream, Path and, String objects, reads all the primitive data types and Strings (from the given source) token by token using regular expressions.By default, whitespace is considered as the delimiter (to break the data into tokens).To read various datatypes from the source using the nextXXX() methods provided by this class namely, nextInt(), nextShort(), nextFloat(), nextLong(), nextBigDecimal(), nextBigInteger(), nextLong(), nextShort(), nextDouble(), nextByte(), nextFloat(), next().Example − Reading data from ... Read More

Necessity of Byte Streams and Character Streams in Java

Maruthi Krishna
Updated on 01-Aug-2019 14:00:08

785 Views

Java provides I/O Streams to read and write data where, a Stream represents an input source or an output destination which could be a file, i/o devise, other program etc.Based on the data they handle there are two types of streams −Byte StreamsThese handle data in bytes (8 bits) i.e., the byte stream classes read/write data of 8 bits. Using these you can store characters, videos, audios, images etc.The InputStream and OutputStream classes (abstract) are the super classes of all the input/output stream classes: classes that are used to read/write a stream of bytes. Following are the byte array stream ... Read More

Create New Directory Using File Object in Java

Maruthi Krishna
Updated on 01-Aug-2019 13:54:30

6K+ Views

The class named File of the java.io package represents a file or directory (path names) in the system. This class provides various methods to perform various operations on files/directories.Creating a new directoryThe mkdir() method of this class creates a directory with the path represented by the current object.Therefore, to create a directory −Instantiate the File class by passing the path of the directory you need to create, as a parameter (String).Invoke the mkdir() method using the above created file object.ExampleFollowing Java example reads the path and name of the directory to be created, from the user, and creates it.import java.io.File; ... Read More

Read Data from a File Using FileInputStream

Maruthi Krishna
Updated on 01-Aug-2019 13:48:45

4K+ Views

The FileInputStream class reads the data from a specific file (byte by byte). It is usually used to read the contents of a file with raw bytes, such as images.To read the contents of a file using this class −First of all, you need to instantiate this class by passing a String variable or a File object, representing the path of the file to be read.FileInputStream inputStream = new FileInputStream("file_path"); or, File file = new File("file_path"); FileInputStream inputStream = new FileInputStream(file);Then read the contents of the specified file using either of the variants of read() method −int read() − This ... Read More

Advertisements