Rajat Sarkar

Greenhorn
+ Follow
since Sep 07, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rajat Sarkar

import java.util.Calendar;

public class CalendarMethods
{
public static void main(String[] args)
{
Calendar c = Calendar.getInstance();
c.set(2009,1,24,10,2);
long day1 = c.getTimeInMillis();
day1+=1000*60*60;
c.setTimeInMillis(day1);
System.out.println("new hour : "+(c.HOUR_OF_DAY));
c.add(c.DATE,35);
System.out.println("add 35 days : "+c.getTime());
c.roll(c.DATE,35);
System.out.println("roll 35 days : "+c.getTime());
c.set(c.DATE,1);
System.out.println("set to 1 : "+c.getTime());
}
}


Output :
new hour : 11
add 35 days : Tue Mar 31 11:02:43 BST 2009
roll 35 days : Wed Mar 04 11:02:43 GMT 2009
set to 1 : Sun Mar 01 11:02:43 GMT 2009

why the first getTime() method shows BST while the other two shows GMT?
12 years ago
import static java.lang.System.out; /* imports static 'out' variable */
import static java.lang.Math.*; /* imports all the static methods of 'Math' class */

public class ImportStatic
{
public static void main(String[] args)
{
out.println("sqrt "+sqrt(2.0));
out.println("tan "+tan(60));
}
}


while we import 'static' members, is there any possibility of naming confliction?
If there any,then how the compiler resolves it?
12 years ago
import javax.sound.midi.*;

public class MiniMiniMusicApp
{
public static void main(String[] arsg)
{
MiniMiniMusicApp mini = new MiniMiniMusicApp();
mini.play();
}

public void play()
{ try
{
Sequencer player = MidiSystem.getSequencer();
player.open();

Sequence seq = new Sequence(Sequence.PPQ,4);

Track track = seq.createTrack();

ShortMessage a = new ShortMessage();
a.setMessage(144,1,44,100);
MidiEvent noteOn = new MidiEvent(a,1);
track.add(noteOn);

ShortMessage b = new ShortMessage();
b.setMessage(128,1,44,100);
MidiEvent noteOff = new MidiEvent(b,4);
track.add(noteOff);

player.setSequence(seq);

player.start();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}


when i run this by :
javac MiniMiniMusicApp.java
java MiniMiniMusicApp

Command prompt disappears,after playing a sound.why the command prompt disappears? Is there anything wrong?
12 years ago
public class inttoObject
{
public static void main(String[] args)
{
int x=90;
Object o;
o=90;
System.out.println(o);
}
}


How a primitive like 'int' can be assigned to a 'Object' reference?
12 years ago
ArrayList list =new ArrayList(); & ArrayList<Object> list = new ArrayList<Object>();
is both statement works same?is there any difference between them?
12 years ago

Mehar Simhadri wrote:looks like you dont have type parameters for Arraylist, it will lead to a warning in java 5



in that case , ArrayList list =new ArrayList(); & ArrayList<Object> list = new ArrayList<Object>(); is both statement works same.
12 years ago
class Dog
{
private int teeth_number;
private boolean isMad;
private String name;
private int size;

public Dog(String s,boolean ad,int si)
{
name=s;
isMad=ad;
size=si;
}

public String showName()
{
return name;
}

public int showteeth()
{
return teeth_number;
}
}

public class TestDog
{
public static void main(String[] args)
{
Dog mydog=new Dog("Rocky",false,50);
System.out.println("name : "+mydog.showName()+" teeth number : "+mydog.showteeth());
}
}

In the Dog's constructor we don't initialise teeth_number.Then how we get the value 0 for it when we create Dog object?
12 years ago
import java.util.*;

class V2Radiator
{
V2Radiator(ArrayList list)
{
for(int x=0;x<5;x++)
list.add(new SimUnit("V2Radiator"));
}
}

class V3Radiator extends V2Radiator
{
V3Radiator(ArrayList list)
{
super(list);
for(int x=0;x<10;x++)
list.add(new SimUnit("V3Radiator"));
}
}

class RetentionBot
{
RetentionBot(ArrayList list)
{
list.add(new SimUnit("Retention"));
}
}

public class TestLifeSupportSim
{
public static void main(String[] args)
{
ArrayList aList = new ArrayList();
V2Radiator v2 = new V2Radiator(aList);
V3Radiator v3 = new V3Radiator(aList);
for(int z=0; z<20 ; z++)
{
RetentionBot ret = new RetentionBot(aList);
}
}
}

class SimUnit
{
String botType;

SimUnit(String type)
{
botType=type;
System.out.println(type);
}

int powerUse()
{
if("Retetention".equals(botType))
{
return 2;
}
else
{
return 4;
}
}
}

whenever i try to compile this, some type of compilation error comes.it tells

"Note: TestLifeSupportSim.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details. "

what does it mean by that?
12 years ago
public abstract class Animal
{
private int teeth_number;

public Animal(int x)
{
teeth_number=x;
}

public Animal()
{
this(10);
System.out.println("These do not execute"); // this line does not execute }

public int showTeeth()
{
return teeth_number;
}

public abstract void roam();
}

Why the underlined line does not execute while creating subclasses of Animal?

12 years ago
Abstract classes can have instance variables.But abstract classes can't never be instantiated.So where do the instance variables live in?
12 years ago
Can interfaces implement another interface or extend another class?
12 years ago
Java is platform-independent.Why my written Java programs do not run in my mobile.I've created a .jar file of my application.How to run this jar in my mobile? I use Java SE 6.
12 years ago



In this program 'turnOn()' method is overridden.turnOn() method in 'Heater', returns different type.But in the main method where the turnOn() is called of Heater class, if the returned value is assigned to type Heater it gives error,whereas the return type is declared as Heater in the second turnOn() method.

Can anyone explain this?
[edit]Add code tags. CR[/edit]
[ October 19, 2008: Message edited by: Campbell Ritchie ]
12 years ago
Can we declare arrays of arrays of ArrayList?

i.e. ArrayList<String> myList=new ArrayList<String>[5]; // is this valid ??
13 years ago
when we use any class from the Java API in our code, is that imported class get compiled?
13 years ago