0% found this document useful (0 votes)
12 views7 pages

Whats The Difference Between: Int Length 5 Int Breadth 10 Int Area Length Breadth

1) In the first snippet, the variables length, breadth are not final and can be reassigned, while in the second snippet they are final and cannot be reassigned. 2) In the second snippet, the multiplication is done at compile time using a technique called constant folding, while in the first it is done at runtime. 3) Declaring variables as final allows them to be treated as compile-time constants when they are initialized with constant values, allowing optimizations like constant folding.

Uploaded by

omkareshwari_27
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views7 pages

Whats The Difference Between: Int Length 5 Int Breadth 10 Int Area Length Breadth

1) In the first snippet, the variables length, breadth are not final and can be reassigned, while in the second snippet they are final and cannot be reassigned. 2) In the second snippet, the multiplication is done at compile time using a technique called constant folding, while in the first it is done at runtime. 3) Declaring variables as final allows them to be treated as compile-time constants when they are initialized with constant values, allowing optimizations like constant folding.

Uploaded by

omkareshwari_27
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Question1

Whats the difference between


int length = 5;
int breadth = 10;
int area = length * breadth;

and
final int length = 5;
final int breadth = 10;
int area = length * breadth;

dont scroll down until you have thought over the answer
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
gave it a thought ?
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
sure ?
.
.
.
.
.
.
.
.
.
.
.
Ok then heres the answer...
In the second code snippet multiplication is done at compile time.
In first multiplication is done at Runtime.
Reason
Java compiler uses something known as Constant Folding. Constant folding refers to the
compiler precalculating constant expressions.
QUESTION2
Difference between Vector and ArrayList?

A: Vector is synchronized whereas arraylist is not.

QUESTION3
Difference between Swing and Awt?

A: AWT are heavy-weight componenets. Swings are light-weight components. Hence swing
works faster than AWT.

QUESTION4

class IncDemo
{
public static void main(String args[])
{
int a=1;
int b=++a++;
System.out.println(b);
}
}
C:\jdk1.5.0\bin>javac IncDemo.java
IncDemo.java:6: unexpected type
required: variable
found : value
int b=++a++;
^
1 error

QUESTION5
class P
{

public static void main(String pavan[])


{
System.out.println("P IZ BACK");
}

Exception in thread "main" java.lang.NoSuchMethodError: main


QUESTION6
public class NMM

static

System.out.print("Great ");

NMM.main(null);

System.out.print("Programmer ");

System.exit(0);

public static void main(String []args)

System.out.print("Java ");

Output: Great java programmer.

QUESTION7:
From where the main() method in java??
Ans: Java Virtual machine.
QUESTION8

class Min
{
public static void main(String args[])
{
int min = 50;
min(min, 40, 20);
System.out.println("Minimum of 20,40 and 50 is"+min);
}

static void min(int min, int a, int b)


{
if(a>b)
min = b;
else
min = a;
}
}

Ans: 50(because pass by value)


QUESTION9
class Position
{
public static void main(String args[])
{

String s="pavan";

char c = s.charAt(3);

System.out.println(c);
}
}

Output: a

QUESTION 10

You might also like