You are on page 1of 43

BlueJ : An Introduction

towards JAVA Expertise

Dheeraj Mehrotra
City Montessori School
Kanpur Road, Lucknow
attention@computerscienceexpertise.com
www.computerscienceexpertise.com

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Credits

Michael Kölling
School of Network Computing
Monash University, Australia

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


What is BlueJ?
BlueJ is a Java™ development environment specifically
designed for teaching at an introductory level. It was
designed and implemented by the BlueJ team at Monash
University, Melbourne, Australia.

More information about BlueJ is available at


http://bluej.monash.edu.

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


BlueJ
Installation
BlueJ is distributed as an archive of Java classes in “jar” format. Installing it is
quite straightforward.

Prerequisites
You must have JDK 1.2.2 or later installed on your system to use BlueJ. Some
functionality works better with JDK 1.3, so it is worth getting or updating to the
latest JDK release. If you do not have JDK installed you can download it from
Sun’s web site at http://java.sun.com/j2se/.

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Getting BlueJ
The BlueJ distribution file is named bluej-
xxx.jar, where xxx is a version number. For
example, the BlueJ version 1.1.1 distribution is
named bluej-111.jar. You might get this file on
disk, or you can download it from the BlueJ web
site at http://bluej.monash.edu.

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Installing BlueJ

Windows:
Double-click the install file (bluejsetup).
And follow the instructions further.

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Installing BlueJ

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Installing BlueJ

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


BlueJ installation

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


BlueJ Installation

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


BlueJ Installation

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


BlueJ Installation

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


BlueJ Installation

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


BlueJ Installation

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


BlueJ Installation

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


BlueJ Installation

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Installing BlueJ

Once the BlueJ with JDK is installed, double click the above icon to
have the following screen.

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


BlueJ Opening Screen

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Opening a project in BlueJ

BlueJ projects, like standard Java packages, are directories


containing the files included in the project. If you start BlueJ from
a command line, and you give a project as an argument, it will
automatically be opened.
If you start BlueJ without an argument, use the Project –

Open... menu command to select and open a project.

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Coding a program

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Compiling the program

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Close the program

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Next Screen

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Creating an Object

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Creating an Object

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Creating Object

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Executing the program through
objects

Right
Click
the
Mouse

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Executing an Object

Select
Void computerscienceexpertise.com
work(String)
TOWARDS QUALITY LITERACY
function

PDF created with pdfFactory Pro trial version www.pdffactory.com


Executing the program
Supply
The
String as
Input
Within “ “

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


INPUT STRING

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Output Screen

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Example Program 1
// Program to compute and print if(s==2)
all prime numbers between 100 {
and 500 System.out.println(i+" ");
class test1 d=d+1;
{ }
void prime() }
{ System.out.println();
int i,j,s=0,d=0; System.out.println("the no. of prime
for(i=100;i<500;i++) no. are = "+d);
{ }
s=0; }
for(j=1;j<=i;j++)
{
if(i%j==0)
s=s+1;
}
computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Example Program 2
// Create a program to define a System.out.println("The HCF of the
function found() given two numbers is "+h);
// to print the Highest Common }
Factor of any two numbers. }

class compute
{
public void found(int a, int b) //
declaration of the function
{
int p,h=0;
p=a*b;
for (int i=1;i<=p;i++)
{
if (a%i==0 && b%i==0)
h=i;
} computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Example Program 3
// Program to print the characters public void array1(String a)
of the string present at odd {
positions. l=a.length();
public class odd System.out.print("the
{ characters of the string "+a+" at odd
positions are:");
private int x,i,l; for(i=0;i<l;i++)
{
public odd() if (i%2!=0)
{
System.out.print(a.charAt(i));}
x = 0; }
} }

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Example Program 4
// Program to print the characters public void array1(String a)
of the string present at even {
positions. l=a.length();
public class even System.out.print("the
{ characters of the string "+a+" at even
positions are:");
private int x,i,l; for(i=0;i<l;i++)
{
public even() if (i%2==0)
{
System.out.print(a.charAt(i));}
x = 0; }
} }

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Example Program 5
//Write a program to compute for (int count = 0, k=0;k<=t;k++)
prime factors of any entered {
number with the help of a System.out.println(anum[k]+" is a
function pfact(). factor of "+n);
class compute for (int m=1;m<=anum[k];m++)
{ {
if (anum[k]%m==0) count = count + 1;
void pfact(int n) // Definition }
{ if (count==2)
int t=-1; System.out.println(anum[k]+" is also
int anum[]=new int[10]; prime");
for (int i=1;i<=n-1;i++) count = 0;
{ }
if (n%i==0) }
{ }
t=t+1;
anum[t]=i;
computerscienceexpertise.com
} TOWARDS QUALITY LITERACY
}
PDF created with pdfFactory Pro trial version www.pdffactory.com
Example Program 6
// Program to print the sum of the System.out.println("The sum of the
odd digits of an entered number odd digits of the number is "+sum);

public class prog }


{ }
public void work(int n)
{
int digit, sum=0;
while(n>0)
{
digit = n%10;
// checking digit even
if (digit%2!=0)
sum = sum + digit;
n=n/10;
}
computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Example Program 7
// length of each word of a public void work(String s)
sentence {s=s+" ";
// print longest word l=s.length();
for(i=0;i<l;i++)
{
class string4 z=s.charAt(i);
{ c++;
private int i,l,c; System.out.print(z);
char z; if(z==' ')
{c--;
System.out.print(" :"+c+" ");
public string4() c=0;
{ System.out.println();
// initialise }
instance variables }
c=0;
} }
computerscienceexpertise.com
}
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Example Program 8
// Program to display the factorial of any entered number using the
do-while loop.
class dowhileloop
{
public void work(int N)
{
int i;
double fact;
fact=1;
i = 1;
while(i <=N)
{
fact = fact*i;
i++;
}
System.out.print("The factorial of the Number is" +fact);
}
computerscienceexpertise.com
} TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Example Program 9
// Program to print the digits of an
for(int i=9;i>=0;i--)
entered number in descending
{
order.
while(n>0)
{
public class prog
digit = n%10;
{
if (digit==i )
public void work(int n)
System.out.print(digit);
{
n=n/10;
int digit,num=n;
}
System.out.println("The
n=num;
entered number is "+n);
}
System.out.println("The
sorted digits in descending order
}
is ");
}

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


Example Program 10
public void sampleMethod(String str)
{
// Program to input a string and l=str.length();
print each word in reverse.
System.out.print(str);
for(i=0;i<l;i++)
public class reverse
{
{
char a=str.charAt(i);
// instance variables - replace
/* System.out.print(a);*/
the example below with your own a1=(int) a;
private int i,a1,l,p,j; if(a1==32 || i==l-1)
{ for(j=i;j>=p;j--)
/** {
* Constructor for objects of char b=str.charAt(j);
class reverse
System.out.print(b);
*/
}
public reverse()
System.out.print(" ");
{
p=i;
p=0; // initialise instance
}
variables }
computerscienceexpertise.com
} TOWARDS QUALITY LITERACY
} }

PDF created with pdfFactory Pro trial version www.pdffactory.com


A Revision Tour
o What is BlueJ?
o Java : It’s utility in totality?
o Execution of class files.
o Instatiation of Objects.

o Thanks for going through the e-book.


n Comments on
attention@computerscienceexpertise.com

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com


o VISIT US AT:
n www.computerscienceexpertise.com
n Towards QUALITY IT LITERACY FOR ALL.

computerscienceexpertise.com
TOWARDS QUALITY LITERACY

PDF created with pdfFactory Pro trial version www.pdffactory.com

You might also like