Found 34484 Articles for Programming

LinkedList in Java

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

346 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

398 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

468 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

8K+ 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

Java program to convert float decimal to Octal number

Ankith Reddy
Updated on 25-Jun-2020 14:25:17

264 Views

We can convert any decimal number to its equivalent octal by following program.In this we reserve the reminder we get after divide the given number by 8 as it is the base of Octal and then reverse the order of reminders we have stored by multiplying each reminder by 10.Let understand by following example.Example Live Demopublic class DecimalToOctal {    public static void main(String[] args) {       int decimal = 84;       int octalNumber = 0, i = 1;       while (decimal != 0) {          octalNumber += (decimal % 8) * i;          decimal /= 8;          i *= 10;       }       System.out.println("Octal of given decimal is " + octalNumber);    } }OutputOctal of given decimal is 124

Java Program to convert first character uppercase in a sentence

Arjun Thakur
Updated on 25-Jun-2020 14:25:48

532 Views

In order to convert first character as upper case in a sentence we have to first separate each word of sentence and then make first character of each word in upper case.After which we have to again join each word separated by space to make again sentence.Now let take each task one by one.First in order to get each word of the sentence separately we would use Scanner class of Java and implement its hasnext method to check whether our sentence has any more word or not, in case word is present then we would get that word by using ... Read More

Java program to accept the strings which contain all vowels

George John
Updated on 25-Jun-2020 14:11:08

319 Views

In order to find that a given string contains all vowels we have to first convert given string into character array so that we can simplify the comparison of each character of given string.After this put each character into a hash map so that we can check whether our map created from given string contain all vowels or not.We took help of hash map here because there is no concrete method in character array class which could check that it contains all vowels or not.Only way to check is to iterate whole array and compare each character with each vowel ... Read More

Writing a CSV file in Java using OpenCSV

Chandu yadav
Updated on 25-Jun-2020 14:11:46

642 Views

In Java there is no delegate library or API in order to write or read comma separated value(csv) file.So a 3rd party APIs are available for such requirements.Most popular 3rd party API is OpenCSV which is provide methods to deal with CSV file such as read csv file, write csv file, parse values of csv file, mapping of csv file values to java beans and java beans to csv file etc.In order to use/import this tool in Java project there are following approaches −Download the binaries/jars from http://sourceforge.net/projects/opencsv/Download through maven by updating pom.xml as    net.sf.opencsv    opencsv    2.3 ... Read More

Advertisements