Click here to Skip to main content
Licence CPOL
First Posted 7 Nov 2007
Views 17,143
Downloads 239
Bookmarked 17 times

Java Learner IDE

By | 7 Nov 2007 | Article
A single window Java Learner IDE with C#
Screenshot - jli.jpg

Introduction

I was making a processor for one of my C++ DOS applications. This inspired me to make this tool. This tool is not a professional one but shows an example which makes use of the System.Diagnostics namespace. With this tool, you can write small console based Java programs, compile and run. Just a way to practically learn Java.

Prerequisites

Yes, to learn Java - you must install Java SDK first and then you need to add the path to your javac.exe and java.exe in your path environment variable if you do not have it already. This application will check whether it is ok. If there is something wrong, it will give you the message: "Java not installed or not found in the PATH variable". Also, at the same time Compile, Run and Compile & Run buttons will become disabled.

Workflow

When you invoke the application, Java check will happen in the Form1_Load event. The method I have used is CheckIfJavaInstalled(). There is no system level task executing to check whether Java is installed or not. It simply checks whether the path environment variable contains the word 'java'.

private bool CheckIfJavaInstalled()
{
    bool flag = true;
    if (Environment.GetEnvironmentVariable("path").ToLower().IndexOf("java") == -1)
    {
        flag = false;
    }
    return flag;
}

In the main window (well, only one window is there ;)), I used One split container, two text boxes, one panel and three buttons. Both text boxes are multiline enabled. One is used for writing Java code while the other is for showing status messages and program output.

'Compile' button will first save the currently displayed code in a file named test.java (function: SaveFile()). It is because javac.exe needs a Java program file to compile. After saving, it invokes the function CompileJava(). This again invokes a function Execute(@"javac.exe", "test.java"). I wrote this as a separate method since I want to use the same for Runjava() method too.

Here is what the code looks like:

private bool Execute(string filename, string arguments)
{
    bool flag = true;
    Process p = new Process();
    p.StartInfo.FileName = filename;
    p.StartInfo.Arguments = arguments;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.RedirectStandardError = true;
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.ErrorDialog = false;
    p.StartInfo.CreateNoWindow = true;
    p.Start();
    p.WaitForExit();
            
    string err = p.StandardError.ReadToEnd();
    string output =  p.StandardOutput.ReadToEnd();
    string str = err + output;
    if (output.Length == 0)
    {
        if (err.Length > 0)
        {
            str += "Status: Failed";
            flag = false;
        }
        else
        {
            str += "Status: Success";
        }
    }


    txtOutput.SelectionLength = txtOutput.Text.Length;
    txtOutput.SelectedText = str + "\r\n--------------------------------------\r\n";

    return flag;
}

If you are a beginner, you may be wondering what SelectectionLength and SelectedText mean. These two lines are used to move the cursor of status textbox to scroll to the bottom.

System.Diagnostics.Process is used to invoke the command line applications javac.exe and java.exe and redirect the output from console to status textbox of our application.

Problems?

Well, as I mentioned before - this is not a professional software but a hobby program. That too, I wrote it too quickly, may be in just 30 minutes or less. So there is no exception handling, design, documentation/help, etc.

History

  • 7th November 2007: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

NinethSense



India India

Member

Follow on Twitter Follow on Twitter
Praveen.V.Nair - aka NinethSense - Microsoft MVP - is a person with an abnormal passion for technology. He has been playing with electronics from the age of 10 and with computers from the age of 14. He usually blogs at http://blog.ninethsense.com/.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralGreat! PinmemberBoyDeveloper10:43 22 Aug '10  
GeneralRe: Great! PinmemberNinethSense10:09 23 Aug '10  
Generalyes, learn java PinmemberThanks for all the fish7:51 7 Nov '07  
Laugh | :laugh:
GeneralI like this but you should look at PinmemberSacha Barber2:56 7 Nov '07  
GeneralRe: I like this but you should look at PinmemberNinethSense17:10 8 Nov '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 7 Nov 2007
Article Copyright 2007 by NinethSense
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid