Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 2543 of 3363
959 Views
Java provides various datatypes to store various data values. It provides 7 primitive datatypes (stores single values) namely, boolean, byte, char, short, int, long, float, double and, reference datatypes (arrays and objects).Casting in JavaConverting one primitive data type into another is known as type casting. There are two types of casting −Widening− Converting a lower datatype to a higher datatype is known as widening. It is done implicitly.Narrowing− Converting a higher datatype to a lower datatype is known as narrowing. You need to do it explicitly using the cast operator (“( )”).For every primitive variable a wrapper class is available, ... Read More
4K+ Views
While reading the contents of a file in certain scenarios the end of the file will be reached in such scenarios a EOFException is thrown.Especially, this exception is thrown while reading data using the Input stream objects. In other scenarios a specific value will be thrown when the end of file reached.Let us consider the DataInputStream class, it provides various methods such as readboolean(), readByte(), readChar() etc.. to read primitive values. While reading data from a file using these methods when the end of file is reached an EOFException is thrown.ExampleFollowing program demonstrates how to handle the EOFException in Java. Live ... Read More
1K+ Views
The read() method of the input stream classes reads the contents of the given file byte by byte and returns the ASCII value of the read byte in integer form. While reading the file if it reaches the end of the file this method returns -1.ExampleAssume we have a text file (sample.txt) in the current directory with a simple text saying “Hello welcome”. Following Java program reads the contents of the file byte by byte using the read() method and prints the integer value returned for each byte.Since we are not checking for end of the file, the read() method ... Read More
9K+ Views
When a class has two or more methods by the same name but different parameters, at the time of calling based on the parameters passed respective method is called (or respective method body will be bonded with the calling line dynamically). This mechanism is known as method overloading.Exampleclass Test{ public int division(int a, int b){ int result = a/b; return result; } public double division (float a, float b){ double result = a/b; ... Read More
1K+ Views
When a class has two or more methods by the same name but different parameters, at the time of calling based on the parameters passed respective method is called (or respective method body will be bonded with the calling line dynamically). This mechanism is known as method overloading.Example Live Democlass Test{ public int division(int a, int b){ int result = a/b; return result; } public double division (float a, float b){ double result = ... Read More
13K+ Views
When a class has two or more methods by the same name but different parameters, at the time of calling based on the parameters passed respective method is called (or respective method body will be bonded with the calling line dynamically). This mechanism is known as method overloading.Operator overloadingOperator overloading is the ability to redefine the functionality of the operators. Programming languages like c++ supports operator overloading.you can redefine or overload most of the built-in operators available in C++. Thus, a programmer can use operators with user-defined types as well.Overloaded operators are functions with special names: the keyword "operator" followed ... Read More
9K+ Views
In Java you can copy an object in several ways, among them, copy constructor and the clone method are the mostly used.Using copy constructorGenerally, the copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. Java does support for copy constructors but you need to define them yourself.ExampleIn the following Java example, we a have a class with two instance variables name and age and a parameterized constructor initializing these variables.Then, we have another constructor which accepts an object of the current class and initializes the ... Read More
4K+ Views
In Java, a JComboBox is a component that displays a drop-down list and gives users options that we can select one and only one item at a time whereas a JList shows multiple items (rows) to the user and also gives an option to let the user select multiple items. JComboBox A JComboBox can be editable or read-only. An ActionListener, ChangeListener, or ItemListener interface can be used to handle the user actions on a JComboBox. Syntax The following is the syntax for JComboBox initialization: String[] fruits = {"Apple", "Banana", "Orange", "Mango"}; JComboBox comboBox = new JComboBox(fruits); We can create a ... Read More
701 Views
The zip() function in Python is used to map elements from multiple iterables at corresponding index positions. It returns an iterator of tuples, where each tuple contains elements from the input iterables at the same index. Suppose the lengths of the input iterables are not the same. In that case, the zip() function will stop pairing once the shortest iterable is exhausted, ignoring any extra elements from the longer iterables. Following is the syntax of the zip() function in Python − zip(iterable1, iterable2) It accepts iterables as a parameter and returns a single iterable. Using zip() with list list ... Read More
833 Views
Let's see how can we implement custom len() function in Python. Try it by yourself first using the following steps.StepsGet the iterator from the user string/list/tuple.Define a function with a custom name as you like and invoke it by passing the iterator.Initialize the count to 0.Run a loop until it reaches the end.Increment the count by 1Return the count.Example Live Demo## function to calculate lenght of the iterator def length(iterator): ## initializing the count to 0 count = 0 ## iterating through the iterator for item in iterator: ## incrementing count ... Read More