Friday, March 6, 2015

Moving to Eclipse

BlueJ is an excellent environment to get started in Java programming, but eventually you need to move to a full IDE with many more features.  More features are not helpful while learning basic concepts, but as you progress trivial tasks become annoying and feature rich programming environment can allow you to move to the next level in programming.  So, this is what this post will help you with including the accompanying video.


Basic outline of the video topics
Video reference: http://youtu.be/2yL8yCPveuk
Get Eclipse

https://eclipse.org/downloads/
https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/luna/SR2/eclipse-java-luna-SR2-win32-x86_64.zip

Set a workspace          ( change it later if needed: File->Switch workspace->Other )

Show all Key Assist Shortcuts - Ctrl+Shift+L

Create a project
//shortcuts
New project ->                       Alt+Shift+N then J
New class ->                          Alt+Shift+N then C
Main method ->                     type main then Ctlr + Space
Println ->                                type sysout then Ctrl + Space
Toggle Comment ->               Ctrl + /        ( or Ctrl+7 )
Add block comment ->          Ctrl+Shift+/
Remove block comment ->    Ctrl+Shift+\
Add docstring ->                    Alt+Shift+J
Indent code ->                        Ctrl+A then Ctrl+I
Add libraries ->                      Ctrl+Shift+O       (use M for a single import ) 

Source->Generate ...
Create Constructors
Create getters and setters ( mutators and accessors )


Install offline documentation

Get Java Documentation
http://www.oracle.com/technetwork/java/javase/documentation
 Window --> Preferences --> Java --> "Installed JREs"

Templates can speed up your work

You can see all the templates predefined by default Window -> Preferences -> Java -> Editor -> Templates

You can also add a Template View, Window -> Show View -> Other -> Search for Templates

Create a project for a chapter exercise and import sample source code

Ugly code to fix
public class Practice06 {
private static int x;
private static int y;

private int z;
private int k;

public static void main(String[] args) {   //type main then press Ctrl + Shift then enter
System.out.println("Hello World");     //Ctrl+A then Ctrl+I to fix indentation
System.out.println("Hello Again");     //Ctrl + /  to toggle comment
File inFile=new File(args[0]);    //source
Scanner cin=new Scanner(inFile);  //System.in to get input from keyboard
File outFile=new File(args[1]);   //destination
if(outFile.exists()){
System.out.println("The output file exists, please remove it or select another file.");
System.exit(5);
}
PrintWriter cout=new PrintWriter(outFile);
while(cin.hasNext()){
cout.println(cin.nextLine());
}//end of while
cin.close();
cout.close();
} // end of main
}  //end of class
 


Code discussed in the video

import java.io.File;          //Ctrl+Shift+O
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Practice  COSC 1437 class project
 * @author Zoltan
 * @version 1.0.0
 */

public class Practice05 {
    private static int x;
    private static int y;
  
   
    /**
     * @param z
     * @param k
     */

    public Practice05(int z, int k) {
        super();
        this.z = z;
        this.k = k;
    }

    /**
     * @param z
     */

    public Practice05(int z) {
        super();
        this.z = z;
    }

    /**
     *
     */

    public Practice05() {
        super();
    }

    /**
     * @return
     */

    public static int getX() {
        return x;
    }

    /**
     * @param x
     */

    public static void setX(int x) {
        Practice05.x = x;
    }

    /**
     * @return
     */

    public static int getY() {
        return y;
    }

    /**
     * @param z
     */

    public void setZ(int z) {
        this.z = z;
    }

    private int z;
    private int k;
   
    /**
     * Entry point to my application  //docstring Alt+Shift+J
     * @param args as a String array
     * @throws FileNotFoundException
     */

    public static void main(String[] args) throws FileNotFoundException {   //type main then press Ctrl + Shift then enter
        System.out.println("Hello World");     //Ctrl+A then Ctrl+I to fix indentation
        System.out.println("Hello Again");     //Ctrl + /  to toggle comment

        File inFile=new File(args[0]);    //source
        Scanner cin=new Scanner(inFile);  //System.in to get input from keyboard

        File outFile=new File(args[1]);   //destination
        if(outFile.exists()){
            System.out.println("The output file exists, please remove it or select another file.");
            System.exit(2015);
        }
        PrintWriter cout=new PrintWriter(outFile);
        while(cin.hasNext()){
            cout.println(cin.nextLine());

        }//end of while

        cin.close();
        cout.close();

    } // end of main

//end of class

No comments:

Post a Comment