BlueJ : An Introduction towards JAVA Expertise Dheeraj Mehrotra City Montessori School Kanpur Road, Lucknow
[email protected] 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 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 bluejxxx.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 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 all prime numbers between 100 and 500 class test1 { void prime() { int i,j,s=0,d=0; for(i=100;i<500;i++) { s=0; for(j=1;j<=i;j++) { if(i%j==0) s=s+1; }
if(s==2) { System.out.println(i+" "); d=d+1; } } System.out.println(); System.out.println("the no. of prime no. are = "+d); } }
computerscienceexpertise.com TOWARDS QUALITY LITERACY
PDF created with pdfFactory Pro trial version www.pdffactory.com
Example Program 2 // Create a program to define a function found() // to print the Highest Common Factor of any two numbers.
System.out.println("The HCF of the given two numbers is "+h); } }
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 of the string present at odd positions. public class odd { private int x,i,l; public odd() {
public void array1(String a) { l=a.length(); System.out.print("the characters of the string "+a+" at odd positions are:"); for(i=0;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 of the string present at even positions. public class even { private int x,i,l; public even() {
public void array1(String a) { l=a.length(); System.out.print("the characters of the string "+a+" at even positions are:"); for(i=0;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 prime factors of any entered number with the help of a function pfact(). class compute { void pfact(int n) // Definition { int t=-1; int anum[]=new int[10]; for (int i=1;i<=n-1;i++) { if (n%i==0) { t=t+1; anum[t]=i; } }
for (int count = 0, k=0;k<=t;k++) { System.out.println(anum[k]+" is a factor of "+n); for (int m=1;m<=anum[k];m++) { if (anum[k]%m==0) count = count + 1; } if (count==2) System.out.println(anum[k]+" is also prime"); count = 0; } } }
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 odd digits of an entered number
System.out.println("The sum of the 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 public void work(String s) {s=s+" "; l=s.length(); for(i=0;i
// length of each word of a sentence // print longest word
class string4 { private int i,l,c; char z;
public string4() { // 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 entered number in descending order. public class prog { public void work(int n) { int digit,num=n; System.out.println("The entered number is "+n); System.out.println("The sorted digits in descending order is ");
for(int i=9;i>=0;i--) { while(n>0) { digit = n%10; if (digit==i ) System.out.print(digit); n=n/10; } n=num; } } }
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
=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 o o o
What is BlueJ? Java : It’s utility in totality? Execution of class files. Instatiation of Objects. o Thanks for going through the e-book. n Comments on
[email protected]
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