• CONTEST ALERT - Experience the power of DDR5 memory with Kingston Click for details

Java Queries Here..

Could someone explain the loop structure in an array? (both single and double dimensional)
Even link would do (or a page no./chapter no. on Shildt's Java Reference book :|)
 

ambika

learnhardy
A really good thread i encounter in programming subforum for C and C++ started by Gigacore .....
Can any one provide me similar thread for java .....or a external links .....
I am really new to java .
Please help me guys .
 

vamsi360

Always confused
Could someone explain the loop structure in an array? (both single and double dimensional)
Even link would do (or a page no./chapter no. on Shildt's Java Reference book :|)

loop structure ? please be more clear

Using for each loop :

Code:
int x[][]=new int[4][4];
for(int i: x[]) {
   for(int j :x) {
        ------
        ------
   }
}
 
Last edited:

subhransu123

Journeyman
the modified program is........
import java.io.*;
public class FileOps {
public static void main(String args[])throws IOException
{
File file = new File(args[0]);
try
{
BufferedReader in = new BufferedReader(new

FileReader(file));
String s;
s = in.readLine();
while(s!=null)
{
System.out.println("Read " + s);
s = in.readLine();
}
in.close();
}
catch(FileNotFoundException e1)
{
System.err.println("File Not Found" + file);
}
catch(IOException e2)
{
e2.printStackTrace();
}
}
}
 

aniket.awati

I am the Legend.........
I want to control a 16 bit program's input output through java. i.e. the actual processing is to be done by the 16 bit program itself, but its input and output are to be controlled by the gui developed in java. can it be done? if yes how? please provide an example if possible.
 
Could someone explain this line to me?
The body of a "while" loop can be empty. This is because the null statement, consisting of a semicolon, is valid in Java.
How can a while loop not have a body? I couldnt get that. :|
 

Liverpool_fan

Sami Hyypiä, LFC legend
^ ^ ^
(Assuming the while loop in Java is similar to C/C++)

You generally have while loop like this:
while(condition)
{
//your code
}

But without a body you can as well:
while(condition);

See the semicolon in bold, it acts as the null character and the while loop doesn't require a body (i.e. the single line below while loop or the code in braces)
You should however wait for confirmation from Java experts whether I'm right or wrong.
 
^ ^ ^
(Assuming the while loop in Java is similar to C/C++)

You generally have while loop like this:
while(condition)
{
//your code
}

But without a body you can as well:
while(condition);

See the semicolon in bold, it acts as the null character and the while loop doesn't require a body (i.e. the single line below while loop or the code in braces)
You should however wait for confirmation from Java experts whether I'm right or wrong.
Agreed
But if there is nothing in the body, what will be executed in the loop?
Or more importantly, how can the loop exist without the body?
 

vamsi360

Always confused
Could someone explain this line to me?

How can a while loop not have a body? I couldnt get that. :|

it means that body for a loop is not necessary. The loop will iterate itself for the specified no of times without executing any statements. These are mostly used for infinite loops, time delay loops.
Code:
//infinite for loop
for( ; ; );
 

aniket.awati

I am the Legend.........
now, i successfully executed programs as i wanted to, but if try to execute 16 bit programs it gives error as 'error in setting up environment' in message box. What does it mean? how can this error be overcome? I didn't find conclusive answer to this after googling. so please help me..
 

Liverpool_fan

Sami Hyypiä, LFC legend
Agreed
But if there is nothing in the body, what will be executed in the loop?
Or more importantly, how can the loop exist without the body?
Well actually "nothing" is executed for each iteration of the loop...:mrgreen:
No I am not joking...
As for the use...I don't really know..The post above mine suggests something worthwhile but I'll rather use a library function for time delay...
I guess it's importance is iits semantics in these languages rather than any functionality...
 

nitish_mythology

OSS Enthusiast!
Earlier I had posted a ques regarding hashCode n' equals..
But the code was incorrect...
So here is the correct code n the question follows...

[/QUOTE]
/* Testing some ambiguous equals n' hashcode concepts
@Author Nitish Upreti
*/

class Car
{

private String model;
private char type;
private int carno; //The core attribute for deciding if two car objects are equal

public Car()
{
model="Merc";
type='S';
carno=95361;
}

public Car(int no)
{
model="Merc";
type='M';
carno=95361;
}

public boolean equals(Object o)
{
Car c=new Car();

if(o instanceof Car)
c=(Car)o;

/*
System.out.println("c hashCode()--- "+c.hashCode());
System.out.println("Current Object's hashCode()--- "+this.hashCode());
*/

if(c.carno==this.carno)
return true;
else
return false;
}

public int hashcode()
{
return type;
}

public static void main(String args[])
{

Car c=new Car();
Car c2=new Car(13458);

System.out.println("In main() c hashCode()--- "+c.hashCode());
System.out.println("In main() c hashCode()--- "+c2.hashCode());

if(c.equals(c2))
System.out.println("Same Car---Number is same dude :p");
else
System.out.println("Different Cars----Nameplate check kar :p");

}
}

[/QUOTE]

The hashCodes() are reported to b unequal...still the objects are equals!!
Why is it so??
I read in books that for two objects to b equal they must be logically equal n' also have the same hashcode
 

srbharadwaj

Broken In
Re: DefaultTableModel doubt

In a DefaultTableModel after doing an addrow …how to make certain texts within the rows BOLD?
I need to make only certain texts within a cell to be bold
Example:
If the text at 'x'th row and 'y'th column contains the word "abc def" then make ONLY the letters "abc def" in that cell BOLD rest all will remain default
 

multicoder

Right off the assembly line
hi,
I have installed jdek6 and i was quite happy with it,after few days i installed netbeans latest version!And then the problem started.I could only compile my files when using with command prompt and could not run.But could run applets.
I tried alot and then later I to solve this i unstalled netbeans and uninstalled jdk too.
But now nothing is giving me the result.I can only compile the file .when trying to run the file I am getting class not found exception at java.lang.classloader, at ...,at .. an d so on...
Even whn applets running show in their status window 'Applet not started'.
What is the reason behind this.Please help me to sort out this.
Thnaks.
 

vamsi360

Always confused
hi,
I have installed jdek6 and i was quite happy with it,after few days i installed netbeans latest version!And then the problem started.I could only compile my files when using with command prompt and could not run.But could run applets.
I tried alot and then later I to solve this i unstalled netbeans and uninstalled jdk too.
But now nothing is giving me the result.I can only compile the file .when trying to run the file I am getting class not found exception at java.lang.classloader, at ...,at .. an d so on...
Even whn applets running show in their status window 'Applet not started'.
What is the reason behind this.Please help me to sort out this.
Thnaks.
remove multiple path variables to jdks and update the only path variable to newer jdk 1.6 update version
 
Top Bottom