Creating and Running programs in BlueJ Getting Started with BlueJ You need to have BlueJ before completing the following steps. Download the java files you need from the class web site. You don't have to put them in the BlueJ folder, just remember where you download them to on your computer. In this example I will assume they have been downloaded to the desktop.
Start BlueJ by either clicking on the icon you created when you downloaded and installed BlueJ or by navigating to the BlueJ directory and double clicking on the bluej.bat icon. You can alter some of the defaults for BlueJ my modifying the file called bluej.defs with a text editor.This file is located in the lib directory in the bluej folder. You can also modifying the template that starts when creating new programs and classes. The template is stored in the lib - english - templates - newclass folder. When BlueJ is up and running you should see a window that looks something like this: To create a new program you first need to create a new project. Click on the Project menu and select New Project. This opens a new window.
From this window type in the name of the new project in the text field File name. The name of the project does not have to be the same as the name of the java file you will later add to the project. It can be anything you want. After giving the new project and name and clicking Create you see the new project.
There aren't any classes, which are the basic building blocks of programs in Java, or code associated with the project yet. The icon that looks like a piece of paper is just a simple text file that acts as the projects readme file. You can double click on it to add comments about the project as a whole or write notes to yourself on things that need to be done. You probably won't use it much at first.
If you need to add any pre-existing classes to the project now is a good time to do that. On the first assignment you need to download and add then add the class to your project. To add the existing file to the project click on the Edit menu and then select Add Class from File. A new window pops up that allows you to navigate to the correct directory and select the file you want to add. Only files that end in.java are shown. Navigate to the directory that contains the file or files you want to add. If you want to add a single file, click on it and then click on the Add button.
If you want to add 2 or more files from the same directory hold down the CTRL key and click on all the files you want to add, then click on the Add button. Now the new file / class has been added to the file.
It shows up with diagonal lines because it has not been compiled yet. To compile a class that is part of a program you can either click the Compile button on the left side of the window or right click on the icon of the class and select the Compile option from the pop up menu. If the class does not have any syntax errors it will now be shown without any diagonal lines on its icon. To add a new class to the project click on the New Class button. A menu pops up asking for the name of the class. On assignment 1 the name must be Circle. Ensure the Class radio button is selected, type in Circle for the Class Name and click the okay button.
A new class is added to our project. To edit the code in a class double click on its icon. This opens an editor window which is very like a simple word processor.
Select and delete the default code in the class. Type in the changes to the program. You save the program by clicking on the Class menu and selecting Save. You can attempt to compile the program by clicking the Compile button. Any errors will show up in the text area at the bottom of the edit window.
If an error occurs the line the error is on is highlighted in yellow. After compiling the program and getting it to work close the editing window w and go back to the project window. The program / class icon no longer has diagonal lines across it.
To run the program right click on the icon that has the main method in it. IN assignment one, this is the Circle class. This brings up a menu that allows you to carry out various actions.
(You could also compile classes here.) Select the menu option void main(args). This causes the main method of the class to be executed. Another menu pops up that asks what parameters or information you want to pass to the method, in this case main. In this class we won't normally pass any information to method main so just click Ok. This causes the program to run. In assignment 1 a separate window opens and you may have to click on that window to see the program run. For more help with BlueJ see the and.
Shortcuts for everything In IntelliJ IDEA you have dedicated keyboard shortcuts for nearly everything, including rapid selection and switching between tool windows and the editor. Accessing a tool window via its shortcut moves the input focus to it, so you can use all keyboard commands in its context. When you need to go back to the editor, just hit Esc.
When you're in the Project tool window, you can not only navigate through the existing items, but also create new ones by just pressing Alt+Ins.
Java Coding Samples Java Coding Samples Various Java programs to illustrate various concepts. A Java program. A sample of how to call methods in the same class. A simple example of using for loops to calculate factorial.
Uses the built in int data type so only good to 13!.: An example that shows the behavior of value parameters. In Java all parameters are passed by value. A few brief examples of String manipulations.
A program with examples of various Java syntax that converts a base 10 int to base 2 String. A program with various approaches to determine if an int is prime or not. Used to demonstrate Java syntax. You need the class, a non standard Java class, as well. A simplified version of filtering a picture represented by ints. Very simple version of the Conway's Game of Life.
Demonstration of try / catch blocks. Sister carol dread natty congo. The CIA 2008 Factbook may be downloaded from. First version of the IntList class developed in class. Developing class to illustrate various class design and implementation issues in Java.
Translator offline. So no need to worry about the internet connections. Offline translator has made the job more easy as now you can translate words, documents everywhere. There are hundreds of translations apps available in the market but almost all of them require internet connection to be able to translate even a single word.
Added default add method, equals method, and toString methods. Includes versions of toString using String concatenation and StringBuffer to illustarte performance differences. Added insert and remove methods. Inherits from InListVer3 to create a SortedIntList.
Class is 'broken' because random insertions still allowed. Altered the list to store anything, not just ints.
A class that models a playing die.: This illustrates some of the more confusing concepts in class syntax and mechanics such as constructors, static vs. Instance methods, and method overloading. A class for measuring how long it takes for a program to run. A method that using polymorphism to create a set from an array. Includes examples on finding space taken up by files in a directory including all files in all subdirectories, recursive factorial, recursive power, recursive Fibonacci numbers, and a simple knapsack problem. Code to find a a solution to an N queens problem. Note the queensAreSafe method has not been completed.
Bluej Example Projects
Determine if airlines can be moved from airline to another based on network of airline partners. Another example of recursion from the game minesweeper. Changed the GenericList class so that it implements the interface in order to demonstrate how to implement an using an inner class.
Changed GenericList so it is generic based on Java generics syntax instead of relying on Object. A singly linked node class used to build linked lists. A simple list interface. Similar to the LinkedList developed in class.
Does not contain all the methods you would expect of a LinkedList. Also implements the iterator remove method in O(N) time. An O(1) time remove method is possible. An unsorted set that uses a hashtable with closed address hashing to store values.
Currently only the add method is implemented. A method to compare Java's TreeSet and HashSet to the BianrySearchTree, UnsortedSet, and UnsortedHashSet classes developed in class. Note you need a lot of other files for this to work. Program demonstrating use of a map to count the frequency of words in a file. Program that compares counting words in files using an ArrayList and a Map.
How To Use Bluej
Shortcuts for everything In IntelliJ IDEA you have dedicated keyboard shortcuts for nearly everything, including rapid selection and switching between tool windows and the editor. Accessing a tool window via its shortcut moves the input focus to it, so you can use all keyboard commands in its context. When you need to go back to the editor, just hit Esc. When you're in the Project tool window, you can not only navigate through the existing items, but also create new ones by just pressing Alt+Ins.
Learn to code in Java and improve your programming and problem-solving skills. You will learn to design algorithms as well as develop and debug programs. Using custom open-source classes, you will write programs that access and transform images, websites, and other types of data.
At the end of the course you will build a program that determines the popularity of different baby names in the US over time by analyzing comma separated value (CSV) files. After completing this course you will be able to: 1. Edit, compile, and run a Java program; 2.
Use conditionals and loops in a Java program; 3. Use Java API documentation in writing programs. Debug a Java program using the scientific method; 5. Write a Java method to solve a specific problem; 6.
Develop a set of test cases as part of developing a program; 7. Create a class with multiple methods that work together to solve a problem; and 8. Use divide-and-conquer design techniques for a program that uses multiple methods. In this module, you will learn to write and run your first Java programs, including one program that prints “Hello!” in various countries’ languages and another where you will analyze the perimeters and other information of shapes.
To accomplish these tasks, you will learn the basics of Java syntax and how to design stepwise solutions with programs. By the end of this module, you will be able to: (1) Download and run BlueJ, the Java programming environment for this course; (2) Access the documentation for the Java libraries specially designed for this course; (3) Edit, compile, and run a Java program; (4) Construct methods, variables, if else statements, and for each loops in Java; and (5) Use Iterables (like DirectoryResource) to run a program that iterates over multiples lines in a document or webpage or multiple files in a directory.