BlueJJ : An Intr Blue Introd oduc ucti tion on towards JAVA Expertise Dheeraj Mehrotra City Montessori School Kanpur Kanpur Road, Road, Luckn Lucknow ow
[email protected] www.computerscienceexpertise.com
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Credits Michael Kölling School of Network Computing Monash Monash Unive Universit rsity y, Austra Australia lia
computerscienceexpertise.com TOWARDS QUALITY LITERACY
What is BlueJ? BlueJ BlueJ is a Java™ Java™ develop developmen mentt environ environment ment speci specifica fically lly designed for teaching at an introductory level. It was designed designed and implemented implemented by the BlueJ team at Monash Monash University, Melbourne, Australia. More informat information ion about about BlueJ is available available at http://bluej.monash.edu.. http://bluej.monash.edu
computerscienceexpertise.com TOWARDS QUALITY LITERACY
BlueJ Installation BlueJ is distributed distributed as as an archive archive of Java classes classes in “jar” format. format. Installin Installing g 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 up dating 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
Getting BlueJ The BlueJ distributio distribution n file file is is named named bluej- xxx.jar , where xxx is a version number. For example, example, the BlueJ BlueJ version version 1.1.1 1.1.1 distribution distribution is is named bluej-111.jar . You might get this file on disk, or or you can dow download nload it from from the BlueJ web site at http://bluej.monash.edu http://bluej.monash.edu..
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Installing BlueJ Windows: Double-click the install file (bluejsetup ). ). And follow the instructions further.
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Installing BlueJ
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Installing BlueJ
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Blue lueJ ins insta tallla lati tion on
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Blue lueJ Ins Instal alla lati tion on
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Blue lueJ Ins Instal alla lati tion on
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Blue lueJ Ins Instal alla lati tion on
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Blue lueJ Ins Instal alla lati tion on
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Blue lueJ Ins Instal alla lati tion on
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Blue lueJ Ins Instal alla lati tion on
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Blue lueJ Ins Instal alla lati tion on
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Installing BlueJ
Once the BlueJ with JDK is installed, installed, double click the above icon to to have the following screen. computerscienceexpertise.com TOWARDS QUALITY LITERACY
Blue Bl ueJJ Open Openin ing g Sc Scre reen en
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Opening a project in BlueJ
BlueJ projects, projects, like standard standard Java packages, packages, are directories directories containing containing the files included included in the project. project. If you start BlueJ BlueJ from a command line, line, and you give a project as an argument, it will automatically be opened. If you start start BlueJ BlueJ without without an argument, argument, use the the Project – Open... menu command to select and open a project.
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Coding a program
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Compiling the program
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Close the program
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Next Screen
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Creating an Object
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Creating an Object
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Creating Object
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Executing the program through objects
Right Click the Mouse
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Executing an Object
Select Void computerscienceexpertise.com work(String) TOWARDS QUALITY LITERACY function
Executing the program Supply The String as Input Wit Within hin “ “
computerscienceexpertise.com TOWARDS QUALITY LITERACY
INPUT STRING
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Output Screen
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Example Program 1 // Program to compute and print all prime numbers between 100 and 500 class test1 { void prime() { int i,j,s i,j,s=0, =0,d=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. System.out.print println("t ln("the he no. of prime no. are = "+d); } }
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Example Program 2 // Create a program to define a function found() // to print the Highest Common Factor of any two numbers.
System.out. System.out.print println("T ln("The he HCF of the given two numbers is "+h); } }
class compute { public public void void ffoun ound(i d(int nt a, int int b) // // declaration of the function { int int p,h=0 p,h=0;; p=a*b; for (int i=1;i<=p;i++ i=1;i<=p;i++)) { if (a%i==0 && b%i==0) h=i; } computerscienceexpertise.com TOWARDS QUALITY LITERACY
Example Program 3 // Program to print the characters of the string present at odd positions. public class odd { privat private e int x,i,l x,i,l;; public odd() { x = 0; }
public void array1(String a) { l=a.length(); System.out.print("the characters of the string s tring "+a+" at odd positions are:"); for(i=0;i
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Example Program 4 // Program to print the characters of the string present at even positions. public class even { privat private e int x,i,l x,i,l;; public even() { x = 0; }
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
computerscienceexpertise.com TOWARDS QUALITY LITERACY
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 pfact(int n) // Definiti Definition on { int int t=-1 t=-1;; int anum[]=new anum[]=new int[10]; int[10]; for (int i=1;i<=n-1;i i=1;i<=n-1;i++) ++) { if (n%i==0) { t=t+1; anum[t]=i; }
for (int count = 0, 0, k=0;k<=t; k=0;k<=t;k++) k++) { System.out.println(anum[k]+" is a factor of "+n); for (int m=1;m<=anum m=1;m<=anum[k];m [k];m++) ++) { if (anum[k]%m== (anum[k]%m==0) 0) count = count count + 1; } if (count==2) System.out.println(anum[k]+" is also prime"); count = 0; } } }
computerscienceexpertise.com TOWARDS QUALITY LITERACY
Example Program 6 // Program to print the sum of the odd digits of an entered number
System.out. System.out.print println("T ln("The he sum of the odd digits of the number is "+sum);
public class prog
}
{
} public public void void work(int work(int n) { int digit, digit, sum= sum=0; 0; while(n>0) { digit = n%10; // checking digit even if (digit%2!=0) sum = sum sum + digit digit;; n=n/10; } computerscienceexpertise.com TOWARDS QUALITY LITERACY
Example Program 7 // length of each word of a sentence // print longest word
class string4 { privat private e int i,l,c i,l,c;; char z;
public string4() { // initialise instance variables c=0; }
public void work(String work(String s) {s=s+" "; l=s.length(); for(i=0;i
Example Program 8 // Program to display the factorial of any entered number using the do-while loop. class dowhileloop { public void work(int work(int N) { in t i; double fact; fact=1; i = 1; whilile(i wh e(i <=N) <=N) { fact = fact*i; i++; } System.out.print("The factorial of the Number Number is" +fact); } computerscienceexpertise.com } TOWARDS QUALITY LITERACY
Example Program 9 // Program to print the digits of an entered number in descending order. public class prog { public public void void work(int work(int n) { int digit, digit,num num=n; =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;ii=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
Example Program 10 public void void sampleMethod(S sampleMethod(Strin tring g 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 initialise instance instance } variables } computerscienceexpertise.com } TOWARDS QUALITY LITERACY } }
A Revision Tour o o o o
What is BlueJ? Java : It’s utility in totality? Execution of class files. Instat Instatia iati tion on of Object Objects. s. o
Thanks for going through the e-book. n
Comments on [email protected]
computerscienceexpertise.com TOWARDS QUALITY LITERACY
o
VISIT US AT: n n
www.computerscienceexpertise.com Towards QUALITY IT LITERACY FOR ALL.
computerscienceexpertise.com TOWARDS QUALITY LITERACY