Example java programs to learn from?

Hi. I just finished the Head First Book and I am about to start on the 1.5 certification book. In the mean time, I was wondering what open source projects might be good for me to download and start reading the code for? I thought it might be a good idea to download one and go through the code, marking it up with what I think it is doing and looking up things I don't understand. Any pointers to good software to do that on, would be great!
Sorry if this is the wrong forum.
Mark

hey eko291!
I found that the easiest way to learn java was to do something with it. I set up a sourceforge site, and set about making widgets for swing that were non standard in java but found in other languages/operating systems. Looking at code to learn is a two-edged sword. On the one hand it can be great for ideas, but on the other, some people really write cruddy obfuscated code that is a nightmare to follow, let alone learn from.
Write some of your own stuff first to get really familiar with it. If you get stuck, look at some examples from Java Almanac (blood good site that one). Look for some examples from O'Reilly books etc.
I wrote some code to help me learn java. While looking at it to learn Java is not something I would recommend, you may find getting ideas from it to help out with your own projects is something useful.
Feel free. www.sf.net/projects/avianfs
Also, I got a lot of good ideas from a particular guy's blog. Romain Guy. He posts up some really super code for people interested in UI design. Looking through his code, you will be amazed at some of the things you can do with Java. You will get heaps of ideas from there.
hope that helps!
Jason Barraclough.
Message was edited by:
fireman.sparkey
because he realised that a word he used was a naughty one...

Similar Messages

  • How can i  use  this  java program to access from  a jsp page?

    import java.io.*;
    import java.util.*;
    public class FileProcessing
      //create a vector container  for the input variables
         Vector variables = new Vector();
      //create a vector container for the constants
         Vector constants = new Vector();
      /*create a string expression container for the equation
         as read from the file */
         String expression = " ";
      //create double result container for the final result
         double result = 0;
         public boolean processFile(String filename,String delim)
          //index for values vector
              int num_values = 0;
          //index for constants vector
              int num_constants = 0;
          //current line being read from the external file.
              String curline = " ";
          //start reading from the external file
              try
                   FileReader fr = new FileReader(filename);
                   BufferedReader br = new BufferedReader(fr);
                   while(true)
                        curline = br.readLine();
                        if(curline == null)
                             break;
                    //determine the type of current interaction
                        boolean variable = curline.startsWith("input");
                        boolean constant = curline.startsWith("constant");
                        boolean equation = curline.startsWith("equation");
                        boolean output = curline.startsWith("result");
                   //on input variables
                        if(variable)
                          StringTokenizer st = new StringTokenizer(curline,delim);
                          int num = st.countTokens();
                          int count=0;
                          while(st.hasMoreTokens())
                               String temp = st.nextToken();
                               if(count==1)
                                    byte b[]= new byte[100];
                                    System.out.println(temp);
                                    System.in.read(b);
                                    String inputval = (new String(b)).trim();
                                    variables.add(num_values,inputval);
                                    num_values++;
                               count++;
                        // on constant values
                        if(constant)
                             StringTokenizer st = new StringTokenizer(curline,delim);
                             int num = st.countTokens();
                             int count = 0;
                             while(st.hasMoreTokens())
                                  String temp = st.nextToken();
                                  if(count==1)
                                       byte b[]= new byte[100];
                                       System.out.println(temp);
                                       System.in.read(b);
                                       String cons = (new String(b)).trim();
                                       constants.add(num_constants,cons);
                                       num_constants++;
                                  count++;
                        // on equation
                        if(equation)
                             StringTokenizer st = new StringTokenizer(curline,delim);
                             int num = st.countTokens();
                             int count = 0;
                             while(st.hasMoreTokens())
                                  String temp = st.nextToken();
                                  if(count==2)
                                       this.expression = temp;
                                  count++;
              // now we are ready to evaluate the expression
                       if(output)
                          org.nfunk.jep.JEP  myparser= new org.nfunk.jep.JEP();
                          myparser.setAllowAssignment(true);
                          for(int i=1;i<variables.size()+1;i++)
                             String name = "arg"+Integer.toString(i);
                             myparser.addVariable(name,new Double(variables.get(i-1)
                                                .toString()).doubleValue());
                          for(int i=1;i<constants.size()+1;i++)
                               String name = "arg" +Integer.
                                         toString(i+variables.size());
                               myparser.addConstant(name,new Double(constants.get(i-1).toString()));
                   //output is obtained as follows
                          myparser.parseExpression(expression);
                          result = myparser.getValue();
                          System.out.println("Assay value: "+result);
              catch(Exception e)
                   System.out.println(e.toString());
              return true;
         public static void main(String[] args)
              FileProcessing fp = new FileProcessing();
              fp.processFile("input.eqn",":");
    }here i need to generate the strings like 'enter value1' and respective text boxes dynamically . i should use this java program as business logic and a jsp page for view.
    following given is my text file input.eqn
    input:enter value1:arg1
    input:enter value2:arg2
    input:enter value3:arg3
    constant:enter constant1:arg4
    constant:enter constant2:arg5
    equation:enter equation:(arg1+arg2)*(arg3+arg4)*arg5
    result:

    Why do you double post ? http://forum.java.sun.com/thread.jspa?threadID=646988&tstart=0
    Why dint that answer satisfy you ? And why dint you say so in that thread rather than posting the same question again ?
    ram.

  • Sample JAVA program: generate PDF from xsf:fo File

    Hi everybody,
    we already have an xsl that converts an xml into an xsl:fo file.
    I am now looking for a very simple sample that converts this xsl:fo into a PDF.
    It would be profitable if the java-sample would read the xsl:fo file as an input-stream.
    Thanks
    Regards
    Mario

    Hi,
    as I am not a JAVA expert.
    Do you know how to reuse the generated PDF in the java sample not as a fileOutputStream.
    I need to attach the generated PDF to a mail-xml-document.
    (I know haw to generate a mail structure in java-mappping)
    What kind of object is the generated PDF within the java?
    Any ideas
    Regards Mario

  • How to run java programs from a master java program?

    Hello,
    I have several java programs which run from the command prompt. I am seeking help with code for starting java programs from within a java program. For example, a program called master.java works something like this:
    import java.*;
    create connection pool
    create variables and result sets
    start/run slave1.java (var1, var2);
    start/run slave2.java (var3, var4, var5);
    start/run slave3.java (var1, var4);
    end of program master.java
    Each of the slave.java programs will run for up to an hour. I do not want the master.java program to pause for each slave program to stop. Instead, the master program will keep running and multiple slave programs will be running simultaneously with the master program. When a slave program starts, it is on its own. Also, if possible, I would like to have each of these slave.java programs open in a new separate command window, so I can observe each slave program running in separate windows.
    Any suggestions for code or helpful documentation are greatly appreciated.
    Thank you,
    Logan

    Thank you all.
    At the bottom of master.java I have successfully started a batch file with these lines:
    String jcmd = "cmd.exe /c start c:/data/simulations/MsgViewCount2.bat";
    Process proc = Runtime.getRuntime().exec(jcmd);
    But I still cannot get a java program to start. Here is one variation I have tried:
    String [] cmdArray = new String[2];
    cmdArray[0] = "java";
    cmdArray[1] = "slave1";
    Runtime runtime = Runtime.getRuntime();
    Process process = runtime.exec(cmdArray);
    This compiles, and no errors occur, but nothing happens.
    Regarding this comment:
    Why Runtime.exec? Either make the slaves Runnable or
    just call their main() methods.
    Oh, I see. Sepearate output. :PNone of the slave.java programs have any output.
    Thanks again.

  • Where to place    text file in  Jdeveloper9irc  to read from Java program

    For ex.
    package mypackage;
    import java.io.*;
    public class ReadData
    public ReadData()
    public static void main(String[] args)
    new ReadData();
    try{
    File fin = new File("test.txt");
    if (fin.canRead())
    System.out.println("Can read file");
    I am geting a error message of file not found. Please advise
    in which directory should I place the text file "test.txt" so that the java program can read from it.
    Thanks,
    agsp

    The test.txt file should be in the 'Run Directory" of your Project. Select Project.jpr and invoke Project settings dialog.
    Click on the Runner. You will see the "Run Directory" edit field.
    For ex.
    package mypackage;
    import java.io.*;
    public class ReadData
    public ReadData()
    public static void main(String[] args)
    new ReadData();
    try{
    File fin = new File("test.txt");
    if (fin.canRead())
    System.out.println("Can read file");
    I am geting a error message of file not found. Please advise
    in which directory should I place the text file "test.txt" so that the java program can read from it.
    Thanks,
    agsp

  • Executing UD32 from a Java program

    Hi I have Clarify application istalled with Tuxedo6.4. I was able to use UD32 utility
    from commandline and execute services in tuxedo. On the Unix (Sun Solaris 2.6)
    I am using the following to execute the UD32
    $ud32 -U sa<NL>
    SRVCNM<TAB>CB_EXESUB<NL>
    CLFY_SUB<TAB>ExternalMsg<NL>
    EQUIP_ID<TAB>1<NL>
    <NL>
    however if I use a java program to execute from the same directory, it is not
    working. I am obtaining a process from the runtime and writting to the process
    to get the above. My code is as follows
    import java.io.*;
    public class udexec {
    public static void main(String args[]) {
    try{
    Runtime rt = Runtime.getRuntime();
    System.out.println("Before");
    Process prcs = rt.exec("ud32 -U sa\n");
    System.out.println("After: " + prcs);
    InputStreamReader isr = new InputStreamReader(prcs.getInputStream());
    PrintWriter out = new PrintWriter(prcs.getOutputStream());
    out.println("SRVCNM CB_EXESUB");
    out.println("CLFY_SUB ExternalMsg");
    out.println("EQUIPID 1");
    out.println("");
    int ret = isr.read();
    String line;
    System.out.println("Before Print");
    System.out.println(ret);
    catch (Exception e) { System.out.println(e); }
    Any help will be greatly appreciated.
    Thank You
    Raju

    No actually I am not getting any error messages. If I use from Command line, I
    can see the output in one of the stdout files. In tha case of java I am not getting
    any. I think after the first line (ud32 -U sa), writing to the process in java
    is not working. Atleast thats what I am thinking.
    --Raju
    Peter Holditch <[email protected]> wrote:
    Raju,
    In what way is it failing? Is there any error writtem to stderr of the
    ud process, or to
    the ULOG?
    Regards,
    Peter.
    Raju Vatsavayi wrote:
    Hi I have Clarify application istalled with Tuxedo6.4. I was able touse UD32 utility
    from commandline and execute services in tuxedo. On the Unix (Sun Solaris2.6)
    I am using the following to execute the UD32
    $ud32 -U sa<NL>
    SRVCNM<TAB>CB_EXESUB<NL>
    CLFY_SUB<TAB>ExternalMsg<NL>
    EQUIP_ID<TAB>1<NL>
    <NL>
    however if I use a java program to execute from the same directory,it is not
    working. I am obtaining a process from the runtime and writting tothe process
    to get the above. My code is as follows
    import java.io.*;
    public class udexec {
    public static void main(String args[]) {
    try{
    Runtime rt = Runtime.getRuntime();
    System.out.println("Before");
    Process prcs = rt.exec("ud32 -U sa\n");
    System.out.println("After: " + prcs);
    InputStreamReader isr = new InputStreamReader(prcs.getInputStream());
    PrintWriter out = new PrintWriter(prcs.getOutputStream());
    out.println("SRVCNM CB_EXESUB");
    out.println("CLFY_SUB ExternalMsg");
    out.println("EQUIPID 1");
    out.println("");
    int ret = isr.read();
    String line;
    System.out.println("Before Print");
    System.out.println(ret);
    catch (Exception e) { System.out.println(e); }
    Any help will be greatly appreciated.
    Thank You
    Raju

  • Call Java program in APEX

    Hi, I am an APEX newbie... I need to call a Java program (.JAR file) from a PL/SQL script inside an APEX application. My question is, does the JAR file need to be in a particular place (and if so, what's the best way to get it there)?
    - somewhere in the APEX database?
    - somewhere in the production database (9i)?
    - could it be called if it resides on a shared network drive?
    Any help would be appreciated... everything I've found thus far tells me to use the loadjava tool to get it onto the prod. database, but I want to make sure that there isn't an easier option as I've had some trouble with that.
    Thanks in advance...
    Kenny

    Hi,
    If you want to call the method of the java class that is stored in the jar you have to make this jar file accessible to the client.
    1/ The jar file can be stored in the database by using loadjava utility
    E.g. loadjava -u scott/tiger -resolve yourjavapackage.jar
    More details on http://www.oracleutilities.com/OSUtil/loadjava.html
    and http://www.csee.umbc.edu/help/oracle8/java.815/a64683/tools1.htm
    1.1/ Once the jar file is in the database you can access it's object methods by defining the pl/sql function that is able to call particular java method
    E.g.
    FUNCTION jCreateDir (dir varchar2, checkExistsOnly number, grantRootDir varchar2)
    RETURN NUMBER as LANGUAGE java
    NAME 'mypkg.Utils.createDirectory(java.lang.String, int, java.lang.String) return int';
    Above function then calls the java method defined in the class included in the jar file (jar file is just an archive of the java classes - to bundle several classes, images... in one file)
    The example contents of the java class
    package mypkg;
    import java.io.File;
    public class Utils {
    public static int createDirectory(String dir, int checkExistsOnly, String grantScriptDir)
    ///some code here
    1.3/ So if you know what method to call, what are the input parameters and return value you can create your calling procedure/function in pl/sql
    I am not very sure if you can load jar files containing the classes that render some user interface items(buttons,panels etc - items from awt or swing package) so basicaly load just the code that performs actions like computation/ xml transformation/ file I/O so anything that does not require GUI items.
    2/ If your jar file contains the objects that display some user interface control or you need to call the java from the javascript then you need to embed your jar file in the html code by using <OBJECT > or <APPLET> tag
    Re: Open program in FF
    Rado

  • Starting a java program on a ordinary windows computer (without JDK)

    I have made an ordinary java program which reads from a specified text file, changes it a bit and then creates a new file with the new text. This works good when I use a computer with an JDK installed, but I must be able to run this program on a Windows 2000 computer (without any "extras" installed, only the programs that are included in Windows 2000). The reason for this is that I'm not allowed to install programs on this computer. Can anyone help me?

    You neither need to
    1- have a JRE installed on the computer (Java Runtime Environment)
    The Java Virtual Machine to convert the compiled byte code into the necessary instructions for the computer it is running on... W/O it...can't run it.
    2- create a native executable...there are packages etc for which this is true. If you can install NOTHING on the computer... you would either
    A- Find one of the packages that creates .exe files from java or class files
    B- Bundle the JRE with it... it doesn't need to be 'installed' persay-- unpack the directories and create a batch file that calls <path-to-java>/java <path-to-program>myclass
    C- Write it in C or C++
    That is not an inclusive list of possibilities... Java's portability comes with the price-tag of needing something that can run it... once you have that something (and the JRE is fairly ubiquitous, or at least, easy to get if not present generally) ... you can run the program.
    ~Dave

  • Shell script for executing java program

    i want to write a shell script which will export the classpath and compile & run the java program.
    any references from where i can get that?

    Try typing "man sh" at the command prompt.
    Ultimately it'll end up looking a lot like this:
    #!/bin/sh
    CLASSPATH=/path/to/a.jar:/path/to/anther.jar
    JAVA_HOME=/path/to/where/you/installed/java
    $JAVA_HOME/bin/java your.classes.package.YourClass

  • Launch many java programs at runtime

    Hi i got one question.
    i have a list of java program ina file.
    i read this file and get each program names.
    i would like to launch all java programs at Runtime from my main Java application.
    here is my code so far:
    String fileName = expansion + ".txt";
              try
                   File file = new File(fileName);
                   FileReader     fileReader= new FileReader(file);
                   BufferedReader bufferReader = new BufferedReader(fileReader);
                   while((program=bufferReader.readLine())!= null)
                        Runtime launch=Runtime.getRuntime();
                        System.out.println("I launch "+ program);
                        launch.exec("cmd.exe /c start /c cd /bin");
                        launch.exec("java "+program);
    this does not work. How can i handle this?
    thank you
    seb

    while((program==bufferReader.readLine())
    != null) {Sorry, I meant
    while((program==bufferReader.readLine())!= null) {{=^)                                                                                                                                                                                                                                                                                                                                                                   

  • Java Applet that reads from file

    I'm quite new to java, I'm fiddling around with it for a nonprofit organization.
    I have a java program that reads from a specified file and generates output but my final goal is a search box on the website that will take user input, run it through my program which searches through a prespecified file, and generate output.
    I'd appreciate any help.

    What can I do with this? I need it to be a String because I'm breaking it down to Tokens.
    Thanks,
    -Grant
    Scanner input = null; //input is going to be the Scanner object
    input = new Scanner(new BufferedReader(new FileReader("test.txt"))); /*setting up the Scanner object "input" to read the file "test.txt"*/
    String words = null;
    String MyArray[] = new String[5000];
    while (input.hasNext()) { //Puts ALL the file's data into one string
    words = words + " " + input.next(); /*Without that space the string "words" contains is all just one word making it unTokenizable*/
    }

  • I'm a new java learner from china,how should I start my journey?

    I have never learned java before,how should I start it? Dose it hard to learn?
    At the beginning,which part of it should I learn?
    Thank you !

    Advice:
    1. Learn the basics with simple command line applications first. Don't worry about complicated topics like Swing, databases, Web applications, etc. for at six months
    2. After you learn how to write, compile & run programs with just a text editor & Java compiler, download & learn to use an Integrated Development Environment, such as Eclipse. Especially, learn how to use the debugger that comes with the IDE.
    3. Experiment with lots of small programs & examples. Learn by doing (and by making mistakes).
    4 Find others in your community who use Java & learn from them.

  • How to run java program from website?

    Hello
    I'd like to know how to run java program from my web page.
    I'd like to push some button in this web page so java program that would be on my server
    would pop-up. Can it be done automaticaly upon running this web site? (without any buttons - I just enter website and program pops up).
    Cheers

    I rather thought about RMI. But I could try servlets. So how it would look like?.
    I would make http request in browser (enter address) and program would show up in its window?. And I would not have to change anything in my program?. This program would run then on both boxes?. One remotely and one not?.
    But I would have to learn some basics, I've never worked with servlets. Could you suggest some good sites about it?. With ready examples so I could tweak them to my purpose.
    Message was edited by:
    macmacmac

  • Beginning java programming in a course from home

    hi, i've recently started working on a java course, learning from home and am a bit stuck on what it all means really as my level of english isnt very good.
    it says i have to write a class to represent a calendar date, and then write a program that instantiates 2 of these date objects, initializes their member variables and print them out.
    Would someone please be abel to help me with an example of this,
    I would be so grateful!!!
    from
    waynemorgan86

    not compiled... not unit tested... but commented to the beejeepers.
    //DateStringExample is an example of a simple java class. It creates two dates,
    //initialises their member variables, and prints both values.
    class DateStringExample
         //the DateString class encapsulates all the variables and methods which
         //enable is to store a date as a String, and retrieve it again.
         private String DateString {
              //a "member" variable... note that it is private meaning that it is
              //visible only within the DateString class... so other classes can't
              //see it, allowing you to restrict access to this value, and validate
              //value when it is "stored".
              private String date;
              //a default contructor ("no arg" constructor) nb: if you don't
              //specify a default contructor java creates an empty one for you.
              DateString() {
                   //set the value of the date variable in this instance of the DateString
                   //class to todays date, which is the default value of a Date object.
                   this.date = (new Date).toString;
              //a "setter contructor" allows you to create a new DateString and
              //set it's value in one easy move.
              DateString(String date) throws Exception {
                   setDate(date);
              //a "setter" validates the supplied value and sets the member variable.
              void setDate(String date) throws Exception {
                   if (date = null) throw Exception("null date");
                   try {
                        Date tmp = DateFormat.parse(date);
                   } catch ( ParseException e ) {
                        throw new Exception("invalid date " + date, e);
                   this.date = date;
              //a "getter" returns the current value of the member variable.
              DateString getDate() {
                   return(this.date);
         //this is the special main method which java run's automatically when
         //you run the "program"
         public static void main(String[] argv)
              try {
                   //get me an instance of a DateString called today, which contains
                   //todays date (as a string);
                   DateString today = new DateString();
                   //get me another instance of a DateString called today, which contains
                   //tomorrowsa date
                   DateString tomorrow = new DateString("2006-09-20 12:46:00");
                   //output the two values
                   System.out.println("today is "+today+" and tomorrow is "+tomorrow);
                   //try to set tommorow to an invalid date, and print again
                   tomorrow.setDate("2006-02-31 00:00:00");
                   System.out.println("today is "+today+" and tomorrow is "+tomorrow);
              //catch any errors, and just report them to the standard error stream.
              } catch (Exception e) {
                   System.err.println(e);
    //NOTES:
    //* This whole class is obviously a complete waste of time, except as
    //      a simple example of a class to newbie java programmers.
    //* The Java language provides a rich featured set of classes for date manipulation.//and a few obvious bugs... hand this in as is and you will fail.
    corlettk: removed dodgy BadDateStringException, I think.

  • Interested in Learning Java Programming.

    Hello All,
    I a college student and I am interested in learning Java programming. Where would be a good place for me to start?
    Thanks

    Sun's basic Java tutorial
    Sun's New To Java Center. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    http://javaalmanac.com. A couple dozen code examples that supplement The Java Developers Almanac.
    jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    Bruce Eckel's Thinking in Java (Available online.)
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java.

Maybe you are looking for

  • Is there a way to connect my MacPro (with DVI and Display ports) to the new Thunderbolt display?

    I'd like to connect these devices together.

  • ChaRM 4.0  NO Export Sytem

    we are using ChaRM 4.0 , when i am refreshing the project cycle project administration . it's giving the following warning error . Warning: Problems occurred during synchronizat of the system landscape i have checked the logs in SLG1 transaction , it

  • Printing blank sheets

    My daughter and  I have the same hp printer.  She ran out of black ink, so I took mine out of my printer as I didn't have any extra on hand.  When I replaced mine with a  new cartridge, it would print blank sheets.  Also, the ink cartridge she borrow

  • WAD report with Report Item occurs binding error

    Hi, We created a report by Report Designer and embaded in a WAD report. If we run the report in Report Designer, It can generate the result correctly, but it will show "Binding error for characteristic value: / Binding error for key figure:Dynarmic"

  • Conditional email

    Hi, I am trying to use the OdiSendMail tool with a conditional piece of code to change the content of the email depending on whether there were errors in the previous step. I have written the following piece of code: <% if (odiRef.getPrevStepLog("ERR