Code Snippets in JAVA Programming and their OUTPUTS-Day 1
CODE SNIPPETS OUTPUT
GENERAL
Concepts: Command Line Arguments
public class Test
{
public static void main(String[] args)
{
System.
out.
println("args[0] = "+args[0]);
}
}
“java Test abc”
args[0] =...
More
Code Snippets in JAVA Programming and their OUTPUTS-Day 1
CODE SNIPPETS OUTPUT
GENERAL
Concepts: Command Line Arguments
public class Test
{
public static void main(String[] args)
{
System.
out.
println("args[0] = "+args[0]);
}
}
“java Test abc”
args[0] = abc
“java Test”
Exception in thread
"main" java.
lang.
ArrayIndexOutOfBounds
Exception: 0
at
Test.
main(Test.
java:5)
Question: What happens when a local variable is used without initializing? Answer: Error
class Test
{
public static void main (String [] args)
{
int count;
System.
out.
println(count);
}
}
COMPILE TIME ERROR
variable count might
not have been
initialized
System.
out.
println(count);
Concept: Variable of smaller capacity can be assigned to another variable of bigger capacity
without any explicit typecasting
class Test
{
public static void main (String [] args)
{
int i = 10;
d = 10.
0 , i = 10
Less