Java Queries Here..

furious_gamer

Excessive happiness
I face a lot of issues while i m running java when i started to learn it... And i think the same issues will still alive.. If anyone find such kinda issue then please post it here instead of creating a new thread..

Yes this thread is dedicatedto Java(if u like J2EE toooo....:D)

So please drop ur queries here...
 
OP
furious_gamer

furious_gamer

Excessive happiness
No Java Queries..:!:...Thats so bad...
Instead of starting a new thread for ur java doubts plz try 2 post here.. This will help for newcomers to search their queries in one stop place...:D
 

Plasma_Snake

Indidiot
Check this code out:
Code:
import java.io.*;

public class FileOps {
public static void main(String args[])
{
    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();
    }
}
}
Now I'm getting this error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at FileOps.main(FileOps.java:13)
Java Result: 1
"
What's the solution? :confused:
 

amit_at_stg

Broken In
Just run the programme by giving the input file name at the command prompt. Syntax java classname inputfilename . Remember that input file should exist in same directory and should preferably be a text file.
 

chandru.in

In the zone
Just run the programme by giving the input file name at the command prompt. Syntax java classname inputfilename . Remember that input file should exist in same directory and should preferably be a text file.
Just a small note. The file need not exist in the same directory from which the program is executed. In that case, the complete path (absolute path) of the files should be specified.
 

Bandu

Journeyman
+1 for the above 2 comments. I think you are not using the command prompt to run your java prog. Seems that you've configured some tool - like EditPlus or such. In that case, make sure that you chose the option that allows you to input parameters (just like command line parameters) to the program being run ("Prompt for Arguments" option in Editplus).

And yes, the file need not be in the same directory, but if the file or directory contains spaces, do enclose the entire path/name in double quotes.

- Bandu.
 

Bandu

Journeyman
I've never used Netbeans. Lookup for some help online for you to allow Netbeans to provide you a dialog for input parameters when you run FileOps.
 

chandru.in

In the zone
Right click on your project in the Projects window and select properties.

Then select "Run" from the left and in the Arguments field type the absolute path to the file. Now whenever you run that will be passed to the program.
 

aniket.awati

I am the Legend.........
I am trying to use keylistener in java. Please expalain this error....

Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class sudoku1 extends Frame implements ActionListener,KeyListener {
    int i,j;
    int x,y;
    Button b;
    Graphics g;
    sudoku1(String s)
    {
            super(s);
            setTitle("Sudoku");
            setSize(1000,700);
            addKeyListener(this);           
            b=new Button("New Game");
            setLayout(new BorderLayout());
            b.addActionListener(this);
            add(b,BorderLayout.SOUTH);                     
            addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});
            setVisible(true);
            g=getGraphics();        
    }
    /*public void control(KeyEvent e)
    {
            if(e.getKeyCode()==VK_ENTER)
                JOptionPane.showMessageDialog(null,"right");
    }*/
    public void keyPressed(KeyEvent e)
    {
        if(e.getKeyCode()==VK_RIGHT)
                JOptionPane.showMessageDialog(null,"right");
    }
    public void keyReleased(KeyEvent e){}
    public void keyTyped(KeyEvent e){}
    public void draw()
    {                
       g.setColor(Color.BLUE);
       x=500;
       y=350;
       i=j=0;
        while(i<10) //platform of the game is printed on screen.
	{
		g.drawLine(x-270+60*i,y-270,x-270+60*i,y+270);
		g.drawLine(x-270,y-270+60*i,x+270,y-270+60*i);
		if(i==3||i==6)
		{
			g.drawLine(x-270+60*i+2,y-270,x-270+60*i+2,y+270);
			g.drawLine(x-270,y-270+60*i+2,x+270,y-270+60*i+2);
		}
		i++;
	}
   
    }       
    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource()==b)
            draw();
    }
    public static void main(String[] args) {
        // TODO code application logic here
        sudoku1 m=new sudoku1("Sudoku");
        
    }

}

error is:

can't find symbol
symbol : variable VK_RIGHT

if(e.getKeyCode()==VK_RIGHT
 

Bandu

Journeyman
There's an error in the code. Use KeyEvent.VK_RIGHT instead of VK_RIGHT. Change your if condition as follows:

Code:
if(e.getKeyCode()==KeyEvent.VK_RIGHT)
 

Plasma_Snake

Indidiot
this not a programming query but a simple JAVA related query. My friends have been asked lot of times during Viva and Placement interview that, Why the symbol of Java is cup of Coffee? AFAIK and tell 'em cause Java is also a name for a type of coffee and is also synonymous to Coffee in some countries that's why its Java and earlier Javabeans(now Netbeans). If I'm wrong then please do correct me.
102.png
 

Bandu

Journeyman
Me too thinks the same.

I've heard of a couple of theories:
(1) James Gosling thought of it while having a cup of coffee.
(2) They had earlier thought of the name (and possibly the symbol) Oak, but that had some copyright issues. They then hired a consultant who interviewed the team and came up with a list of names (Silk, Java, etc.). Java was chosen as it sounds refreshing.
(3) And this, to me seems the most reasonable answer to your question:

"The letters spell out the names of the three key developers: James Gosling, Arthur Van Hoff and Andy Bechtolsheim."
 

Bandu

Journeyman
Get IntelliJ IDEA if you / your company can affort it. Its the best one out there.
Eclipse is one of the freely available ones and is quite good too.

- Bandu.
 

aniruddhc

Right off the assembly line
Well could you guys WAP in java to print the following pattern?? (Just give the base logic using the for loop)

*
**
***
****
***
**
*

the pattern is in the center with 1 star, next line two stars then next line 3 stars ..... 4 stars then decreasing to 1 star...

thanks
 
Last edited:
Top Bottom