Found 9326 Articles for Object Oriented Programming

Multithreading in Java

Arjun Thakur
Updated on 25-Jun-2020 14:32:18

431 Views

Java is a multi-threaded programming language which means we can develop multi-threaded program using Java. A multi-threaded program contains two or more parts that can run concurrently and each part can handle a different task at the same time making optimal use of the available resources specially when your computer has multiple CPUs.By definition, multitasking is when multiple processes share common processing resources such as a CPU. Multi-threading extends the idea of multitasking into applications where you can subdivide specific operations within a single application into individual threads. Each of the threads can run in parallel. The OS divides processing ... Read More

Moving a file from one directory to another using Java

George John
Updated on 25-Jun-2020 14:32:50

5K+ Views

We can use Files.move() API to move file from one directory to another. Following is the syntax of the move method.public static Path move(Path source, Path target, CopyOption... options) throws IOExceptionWheresource − Source path of file to be movedtarget − Target path of file to be movedoptions − options like REPLACE_EXISTING, ATOMIC_MOVEExampleimport java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Tester {    public static void main(String[] args) {       //move file from D:/temp/test.txt to D:/temp1/test.txt       //make sure that temp1 folder exists       moveFile("D:/temp/test.txt", "D:/temp1/test.txt");    }    private static void moveFile(String ... Read More

Local inner class in Java

Arjun Thakur
Updated on 25-Jun-2020 14:38:35

2K+ Views

In Java, just like methods, variables of a class too can have another class as its member. Writing a class within another is allowed in Java. The class written within is called the nested class, and the class that holds the inner class is called the outer class.SyntaxFollowing is the syntax to write a nested class. Here, the class Outer_Demo is the outer class and the class Inner_Demo is the nested class.class Outer_Demo {    class Inner_Demo {    } }Nested classes are divided into two types.Non-static nested classes − These are the non-static members of a class.Static nested classes ... Read More

Literals in Java programming

George John
Updated on 30-Jul-2019 22:30:23

296 Views

A literal is a source code representation of a fixed value. They are represented directly in the code without any computation. Literals can be assigned to any primitive type variable. For example. byte a = 68; char a = 'A'; byte, int, long, and short can be expressed in decimal(base 10), hexadecimal(base 16) or octal(base 8) number systems as well. Prefix 0 is used to indicate octal, and prefix 0x indicates hexadecimal when using these number systems for literals. For example − int decimal = 100; int octal = 0144; int hexa = 0x64; String ... Read More

LinkedList in Java

Chandu yadav
Updated on 25-Jun-2020 14:40:33

344 Views

The LinkedList class extends AbstractSequentialList and implements the List interface. It provides a linked-list data structure.Following are the constructors supported by the LinkedList class.Sr.No.Constructor & Description1LinkedList( )This constructor builds an empty linked list.2LinkedList(Collection c)This constructor builds a linked list that is initialized with the elements of the collection c.Apart from the methods inherited from its parent classes, LinkedList defines following methods.Sr.No.Method & Description1void add(int index, Object element)Inserts the specified element at the specified position index in this list. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index > size()).2boolean add(Object o)Appends the specified element ... Read More

Lambda expression in Java 8

Arjun Thakur
Updated on 25-Jun-2020 14:17:55

392 Views

Lambda expressions are introduced in Java 8 and are touted to be the biggest feature of Java 8. Lambda expression facilitates functional programming, and simplifies the development a lot.SyntaxA lambda expression is characterized by the following syntax.parameter -> expression bodyFollowing are the important characteristics of a lambda expression.Optional type declaration − No need to declare the type of a parameter. The compiler can inference the same from the value of the parameter.Optional parenthesis around parameter − No need to declare a single parameter in parenthesis. For multiple parameters, parentheses are required.Optional curly braces − No need to use curly braces ... Read More

JavaBean class in Java

Ankith Reddy
Updated on 25-Jun-2020 14:22:20

4K+ Views

A JavaBean is a specially constructed Java class written in the Java and coded according to the JavaBeans API specifications.Following are the unique characteristics that distinguish a JavaBean from other Java classes −It provides a default, no-argument constructor.It should be serializable and that which can implement the Serializable interface.It may have a number of properties which can be read or written.It may have a number of "getter" and "setter" methods for the properties.JavaBeans PropertiesA JavaBean property is a named attribute that can be accessed by the user of the object. The attribute can be of any Java data type, including ... Read More

Java program without making class

Arjun Thakur
Updated on 25-Jun-2020 14:23:05

453 Views

Is it possible to create and run a Java program without any class? The answer is Yes. Trick is to use enum instead of Class. Although enum is used to represent public static constant. It can have static main method as well. See the example below −Example Live Demopublic enum Tester {    C, Java, PHP;    public static void main(String[] args) {       System.out.println("Programming in " + Tester.C.toString());       System.out.println("Programming in " + Tester.Java.toString());       System.out.println("Programming in " + Tester.PHP.toString());    } }OutputProgramming in C Programming in Java Programming in PHP

Java program to print duplicates from a list of integers

George John
Updated on 25-Jun-2020 14:23:39

4K+ Views

In order to find duplicates we can utilize the property of Set in Java that in Java duplicates are not allowed when going to be added in a Set.Add method of set returns true for the adding value which is not added previously to it while it would return false in case the adding value is already present in the Set.For our agenda we would iterate out list or collection of integer and try to add each integer in a set of type integer.Now if integer gets added than this means that it is occurring for first time and not ... Read More

Java program to count upper and lower case characters in a given string

Chandu yadav
Updated on 24-Jun-2024 17:07:04

7K+ Views

In order to count upper and lower case character we have to first find weather a given character is in upper case or in lower case. For this we would take concept of ASCII value of each character in Java. In Java as we know for each character has corresponding ASCII value so we would compare each character that it lies in the range of upper case or in lower case. Counting upper and lower case characters in a string in Java In below example first convert string to a character array for easy transverse, then find weather it lies ... Read More

Advertisements