Found 7442 Articles for Java

Local inner class in Java

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

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

545 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

484 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

667 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 16-Oct-2024 16:29:26

1K+ Views

Is it possible to create and run a Java program without any class? The answer is Yes. The trick is to use an enum instead of a Class.Enums are similar to classes, but instead of using the class keyword, we use enum to define them. An enum is used to represent a public static constant. It can have a static main method as well.  Steps to write Java program without making classFollowing are the steps to write a Java program without making class −We will start by defining an enum instead of a class. An enum typically represents constants, but it can also ... Read More

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

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

361 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

Alshifa Hasnain
Updated on 31-Dec-2024 22:01:37

705 Views

In this article, we will learn to convert the first character to uppercase in a sentence in Java, converting the first character of each word or sentence to uppercase is a common text manipulation task. It ensures proper formatting, which is particularly useful in text processing, string parsing, and user interface applications. Approaches to convert first character uppercase in a sentence Following are the two approaches to converting the first character of a sentence to uppercase − Using String Manipulation and Character Methods Using Regular Expressions with the Matcher() Method Using ... Read More

Advertisements