Programming Articles

Page 1586 of 2547

What is the difference between simple name, canonical name and class name in a Java class?

vanithasree
vanithasree
Updated on 11-Mar-2026 3K+ Views

Canonical name of a Java class is the name of the class along with the package. For example, the canonical name of the class File is java.io.File. You can also get the canonical name of a particular class using Java method. The class named Class provides a method getCanonicalName(), this method returns canonical name of the current class. Example import java.lang.*; public class ClassDemo { public static void main(String[] args) { ClassDemo c = new ClassDemo(); Class cls = c.getClass(); ...

Read More

How to declare, define and call a method in Java?

Prabhas
Prabhas
Updated on 11-Mar-2026 2K+ Views

Following is the syntax to declare a method in Java. Syntax modifier return_type method_name(parameters_list){ //method body } Where, modifier − It defines the access type of the method and it is optional to use. return_type − Method may return a value. method_name − This is the method name. The method signature consists of the method name and the parameter list. parameters_list − The list of parameters, it is the type, order, and a number of parameters of a method. These are optional, method may contain zero parameters. method body − The method body defines ...

Read More

What are static members of a Java class?

varun
varun
Updated on 11-Mar-2026 31K+ Views

In Java, static members are those which belongs to the class and you can access these members without instantiating the class. The static keyword can be used with methods, fields, classes (inner/nested), blocks. Static Methods − You can create a static method by using the keyword static. Static methods can access only static fields, methods. To access static methods there is no need to instantiate the class, you can do it just using the class name as − Example public class MyClass { public static void sample(){ System.out.println("Hello"); ...

Read More

What is the difference between integer and floating point literals in Java?

Rahul Sharma
Rahul Sharma
Updated on 11-Mar-2026 1K+ Views

Integer literals represent fixed integer values like 900, 12, 400, -222 etc. (with in the integer range). Whereas, floating point literals represents fractional values i.e. numbers with decimal values like 25.53, 45.66, 58.66 etc. while writing these literals we should use the notation f or F as 25.53. Example public class StringExample { public static void main(String args[]){ int num1 = 100; float num2 = 30.0f; System.out.println("Value of integer:"+num1); System.out.println("Value of integer:"+num2); } } Output Value of integer:100 Value of integer:30.0

Read More

What is the difference between character literals and string literals in Java?

Ali
Ali
Updated on 11-Mar-2026 1K+ Views

Character literals represents alphabets (both cases), numbers (0 to 9), special characters (@, ?, & etc.) and escape sequences like , \b etc. Whereas, the String literal represents objects of String class. Example public class LiteralsExample { public static void main(String args[]){ char ch = 'H'; String str = "Hello"; System.out.println("Value of character: "+ch); System.out.println("Value of string: "+str); } } Output Value of character: H Value of string: Hello

Read More

How can I put a Java arrays inside an array?

Abhinanda Shri
Abhinanda Shri
Updated on 11-Mar-2026 2K+ Views

Exampleimport java.util.Arrays; public class ArrayWithinAnArray{    public static void main(String args[]) {       int[] myArray1 = {23, 56, 78, 91};       int[] myArray2 = {123, 156, 178, 191};       int[] myArray3 = {223, 256, 278, 291};       int[] myArray4 = {323, 356, 378, 391};       int [][] arrayOfArrays = {myArray1, myArray2, myArray3, myArray4};       System.out.println(Arrays.deepToString(arrayOfArrays));    } }Output[[23, 56, 78, 91], [123, 156, 178, 191], [223, 256, 278, 291], [323, 356, 378, 391]]

Read More

What is the lambda expression to convert array/List of String to array/List of Integers in java?

Srinivas Gorla
Srinivas Gorla
Updated on 11-Mar-2026 910 Views

You can convert an array list of strings to an array list of integers as:Exampleimport java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; public class LamdaExpressions {    public static void main(String args[]) {       ArrayList list = new ArrayList();       list.add("123");       list.add("223");       list.add("323");       list.add("334");       List listInteger =          list.stream().map(s -> Integer.parseInt(s)).collect(Collectors.toList());       System.out.println(listInteger);    } }Output[123, 223, 323, 334]

Read More

What are the default values of instance variables whether primitive or reference type in Java?

Amit Sharma
Amit Sharma
Updated on 11-Mar-2026 3K+ Views

When we haven’t initialized the instance variables compiler initializes them with default values.For boolean type, the default value is false, for float and double types default values are 0.0 and for remaining primitive types default value is 0.Examplepublic class Sample {    int varInt;    float varFloat;    boolean varBool;    long varLong;    byte varByte;    short varShort;    double varDouble;    public static void main(String args[]){       Sample obj = new Sample();       System.out.println("Default int value ::"+obj.varInt);       System.out.println("Default float value ::"+obj.varFloat);       System.out.println("Default boolean value ::"+obj.varBool);       ...

Read More

What is a method signature in Java?

Swarali Sree
Swarali Sree
Updated on 11-Mar-2026 8K+ Views

The method signature consists of the method name and the parameter list. Example public class MethodSignature { public int add(int a, int b){ int c = a+b; return c; } public static void main(String args[]){ MethodSignature obj = new MethodSignature(); int result = obj.add(56, 34); System.out.println(result); } } Output 90 Method signature does not ...

Read More

Can static variables be called using className.variableName in Java?

Rahul Sharma
Rahul Sharma
Updated on 11-Mar-2026 2K+ Views

Class variables also known as static variables are declared with the static keyword There would only be one copy of each class variable per class, regardless of how many objects are created from it. You can access a class variable without instantiation using the class name as className.variableName. Example public class Test{ static int num = 92; public static void main(String args[]) throws Exception { System.out.println(Test.num); } } Output 92

Read More
Showing 15851–15860 of 25,466 articles
Advertisements