Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!

steven gerrard

Ranch Hand
+ Follow
since Jan 21, 2006
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 steven gerrard

hi
is there nyway that i can convert jar file to an exe
i want to do it cause i think the product becomes more sellable and attractive for windows users if u have icons and stuff

is there nyway i can convert my jar file to an exe
15 years ago
mushtang also has a smart card i/o api though no documentation for it is available as yet
similar q was recently asked in Microsft code 4 bills contest held in india

the q there was to find the minimum length of string that makes all permutations of first 9 letters of english alphabet(taking 9 at a time) : a,b,c,d,e,f,g,h,i

eg abbaa is the minimum length of string that makes all possible pairs of alphabets(a,b) taking 2 at a time(aa,ab,ba,bb)

i thought a lot a lot abt this q but couldnt get the soln
15 years ago
i just compiled it its coming false in both the cases
i think its a very gud query . i m frm India and will be apperaing in i guess 2-3 weeks time
even at the prometric centre is there ny way to make sure that u r not giving any simulated test .
dont u think that answer to the q shd be 10 and not compier error?
hmm thanks a lot i didnt compile it earlier
its not compiling
clears my doubt
i guess ans given in mock(http://www.danchisholm.net) is not correct
in the second code start is associated with a object unlike the code in 1 where non static method start() is not associated with any object

to call a non static method frm a static method it must have a objkect associated with it
class A {
private static int counter;
public static int getCounter(){return counter++;}
private static int innerCounter;
public static int getInnerCounter(){return innerCounter++;}
private String name;
A() {name = "A" + getCounter();}
class B {
private String name;
B() {
name = "B" + getInnerCounter();
System.out.print(A.this.name + name); // 1
}}
static void m1() {new A().new B();} // 2
static void m2() {this.new B();} // 3
static void m3() {new B();} // 4
public static void main(String[] args) {
m1(); m2(); m3();
}}

What are the results of attempting to compile and run the program?
a. Prints: A0B0A1B1A1B2
b. Prints: A0B0A1B1A2B2
c. Prints: A1B0A0B1A0B2
d. Compile-time error at line 1
e. Compile-time error at line 2
f. Compile-time error at line 3
g. Compile-time error at line 4

answer:: a

i have a query why does 3 compile wat is 'this' in 3 since method is static
i think there is a difference between a gud programmer and SCJP exam certification . For instance its considered a very bad design pattern to hide the fields in an inherited method but it is an impt concept for SCJP exam

I think (if u have no experience with programming) u shd start with the java tutorial at the sun site or u can start with java 2 the complete reference by herbert schield . if u have some C++ experience then u shd try thinking in java later u can try SCJP specific books .
if sa hadnt been a string but a simple Object , then i guess output be different cause Strings are immutable hence only 1 object created .
someone pls confirm
class A extends Thread {
String[] sa;
public A(String[] sa) {this.sa = sa;}
public void run() {
synchronized (sa) {System.out.print(sa[0] + sa[1] + sa[2]);}
}}
class B {
private static String[] sa = new String[]{"X","Y","Z"};
public static void main (String[] args) {
synchronized (sa) {
Thread t1 = new A(sa); t1.start();
sa[0] = "A"; sa[1] = "B"; sa[2] = "C"; //1
}}}


acc to the answer given output is ABC. explanation given is that since lock on object sa is only released by main after executing 1.
i have a query . Arent 2 objects (sa in B and sa in A) different and hence locks are different and hence output shd be XYZ. someone kindly reply
okk thnks fr ur reply
i still have 1 query though . why shd sf1 be referred as St.sf1 and not sf1
hi thnks for ur explanation

but kindly explain when class is loaded static initializer is loaded first . when the static initializer is loaded compiler does not knw wat sf1 is so it shd give compiler error , but it does not.

now even if it does not give compiler error in the second line when sf1 is used to declare another variable why does it give error cause sf1 has already been initialized in line 1
i got this example frm khalid mughal s book on java certification

i have one more doubt::

static {
sf1 = 10; //1

int a = 2 * sf1; //2

}

static int sf1 = sf2 = 30;

how can above piece of code work . how can 1 work when during static initilizer block in this case is executed first and compiler does not knw wat is sf1 . and if 1 works why doesent 2 work.

i m confused to say the least