Results 1 to 6 of 6

Thread: Query in java classes

  1. #1
    Join Date
    Dec 2009
    Posts
    213

    Query in java classes

    Hello,
    I am currently developing a small application that downloads images from a site. To begin, I coded everything in the main class using functions. I just tested by separating the class into several classes, but I wonder if I am doing well. I have the main class with the main function, a class tools with different functions and a class for personal exemptions. The program works as before but with more classes, but there is no inheritance between them. I use them as I did before with includes in C.
    Code:
    class Bug extends Exception{...}
    class Tools{...}
    class ImageDownloader extends Tools{....} / / main class
    i think I have not understood the concept of classes properly, so if you guys can help me then it would be great. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    333

    Re: Query in java classes

    Hi,
    If your class is Tools Utility, you can put the methods in static and so in ImagesDownloader you use something like:
    Code:
    ... Tools.doAction(...);
    Alternatively, your class ImagesDownloader could be an instance of class Tools so you can remove the extends. Without seeing the code of your classes, I can not advise you more If all your methods in Tools are independent of each other, then I would take the first option. Hope this is going to help you.

  3. #3
    Join Date
    Dec 2009
    Posts
    296

    Re: Query in java classes

    Hello,
    I am a new bee in java and even I would like to understand the concept of java. Here is what I have tried till now
    Code:
    Public static void crtfold(String fldnm){
    		try{
    			File f = new File(fldnm);
    			if (!(f.exists())){
    				if (!(f.mkdir()))
    					throw new Bug("Can not create the new folder!");
    			}
     
    			/ / Change current folder
    			System.setProperty("user.dir"F.getAbsolutePath());
    		}
    		catch(Exception e){
    			System.err.System.out.println("Error in urlToFile"+ e.getMessage());
    		}
    	}
    }

  4. #4
    Join Date
    Dec 2009
    Posts
    213

    Re: Query in java classes

    Hello,
    This is my updated code, if see in problem in the code then please correct me with the same
    Here is the code:
    Code:
    Public class ImgDown extends Tools{
    	Public static void hand(String args[]){
    		try{
    			/ / Reads the url from the keyboard 
    			System.out.System.out.println("Enter an url:);
    InputStream in = new InputStream(System.in);
    BufferedReader BufferedReader = new BufferedReader(in);
    String str = BufferedReader.readLine();
    URL url = new URL(str);  / / convert string into URL format
    			
    			/ / Create a new folder
    			createFolder(url.getHost());
    		}
    		catch(Exception e){
    			System.err.System.out.println("Error in hand"+ e.getMessage());
    		}
    	}
    }

  5. #5
    Join Date
    Nov 2009
    Posts
    583

    Re: Query in java classes

    Hello,
    For ImagesDownloader your class does not need to expand Tools. You can do the following.
    Code:
    Tools.createFolder("XXFolder");
    In ImagesDownloader since your method is in Tools static. Then, for the javadoc in Eclipse, you can generate it on an entire project. (Project> Generate Javadoc ... and you follow the wizard). Hope this information will help you.

  6. #6
    Join Date
    Nov 2009
    Posts
    347

    Re: Query in java classes

    Hello,
    I would like to mention two points here.

    - When you program in Java, gradually tries to "think object" at the start, not thinking "functions". Before thinking about the functionality of your program and cut it well (as is done in C), think rather what are the actors, the entities in my system, what would characterize them, what they are able to do so.

    - One of the greatest strengths of Java is its exception that mean that when used well debugging is much much much easier (and others) through the stack. From the outset, said although an exception is an object, not a single string (the message). It's a shame to lose the information from the stack. In addition, the try / catch not needed especially with catch Exception that is not really recommended to use only knowingly.

Similar Threads

  1. get classes and object in java
    By preeti makkar in forum Software Development
    Replies: 1
    Last Post: 07-05-2012, 11:08 AM
  2. Automatic generation of classes UML.java
    By TechGate in forum Software Development
    Replies: 5
    Last Post: 04-03-2010, 11:10 AM
  3. Error with Java Classes
    By csolci in forum Software Development
    Replies: 2
    Last Post: 07-02-2010, 03:39 AM
  4. What are the different collection classes of java
    By Sacchidananda in forum Software Development
    Replies: 3
    Last Post: 24-11-2009, 03:01 PM
  5. Query regarding use of ActionListener in java
    By beelow in forum Software Development
    Replies: 3
    Last Post: 16-11-2009, 10:56 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,508,163.91735 seconds with 17 queries