Do local variables in Java have default values?

Ali
Ali
Published on 03-Jan-2018 15:41:48
No, local variables do not have default values. Once we create a local variable we must initialize it before using it. Since the local variables in Java are stored in stack in JVM there is a chance of getting the previous value as default value. Therefore, In Java default values ... Read More

What is the scope of local variables in Java?

Rahul Sharma
Published on 03-Jan-2018 15:39:51
Scope of a variable denotes span of a variable. The scope of a local variable is within that method i.e. when we create a variable with in a method, it cannot be accessed outside that method. Example If you observe the following example here, we have created a variable named ... Read More

How to match whitespace but not newlines using Python regular expressions?

Rajendra Dharmkar
Published on 10-Jan-2018 10:39:55
The following code matches only the whitespaces but not newlines in the given stringExampleimport re print re.findall(r"(\s){1,}","""I find     Tutorialspoint useful""")OutputThis gives the output[' ', ' ', ' ']

What is the difference between class variables and instance variables in Java?

Johar Ali
Published on 03-Jan-2018 14:47:44
Following are the notable differences between Class (static) and instance variables. Instance variables Static (class) variables Instance variables are declared in a class, but outside a method, constructor or any block. Class variables also known as static variables are declared with the static keyword in a ... Read More

Is String a primitive data type or an object in Java?

Amit Sharma
Published on 03-Jan-2018 12:38:03
String is not a primitive data type. Java.lang package provides the String class therefore, it is an object type. You can create a string variable directly like any other variables as −String s = "myString";(or)By instantiating the string class using the new keyword as −String s = new String("myString");Example Live Demoimport ... Read More

What is autoboxing in Java?

Ali
Ali
Published on 03-Jan-2018 12:35:06
Autoboxing refers to the automatic conversion of a primitive type variable to its corresponding wrapper class object. The compiler automatically handles the conversion when a primitive value is − Passed as an argument to a function which is expecting a wrapper class object. assigned to a variable of the type ... Read More

What are tokens in Java?

Johar Ali
Published on 03-Jan-2018 12:29:35
Java tokens are smallest elements of a program which are identified by the compiler. Tokens in java include identifiers, keywords, literals, operators and, separators.

What are Boolean literals in Java?

Amit Sharma
Published on 03-Jan-2018 11:56:17
Boolean literals represent only two values true or false. And in Java the value of 1 is assumed as true and the value of 0 is assumed as false. Example Live Demo public class Test{ public static void main(String args[]) throws Exception{ ... Read More

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

Ali
Ali
Published on 03-Jan-2018 11:53:50
Character literals represents alphabets (both cases), numbers (0 to 9), special characters (@, ?, & etc.) and escape sequences like \n, \b etc. Whereas, the String literal represents objects of String class. Example Live Demo public class LiteralsExample { public static void main(String args[]){ ... Read More

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

Rahul Sharma
Published on 03-Jan-2018 11:40:15
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 ... Read More
Advertisements