Code-x Private Server
HomeHome  PortalPortal  SearchSearch  RegisterRegister  Log inLog in  


 Introduction to java - Using JCreator

Go down 

Number of posts : 33
Registration date : 2008-06-07

Introduction to java - Using JCreator Empty
PostSubject: Introduction to java - Using JCreator   Introduction to java - Using JCreator Icon_minitimeTue Jul 01, 2008 1:17 pm

****************Need JCreator for some of the codes**********************
Created by: Purez/Justin

An Integrated Devoelopment Environment


public class Hello
   public static void main(String[]args)
   //display a greeting in the console window
      System.out.println("Hello, World!");

A simple program
public class ClassName
public static void main(String[]args)
Method call
System class
System.out object
pringln method

Syntax 1.1: Method Call


-System.out.println("Hello, Dave!");

Number types
-int: integers, no fractional part
1, -4, 0
-double: floating-point numbers (double precision)
0.5, -3.11111, 4.3E24, 1E-14

Assignment operator
int nickels = 0;
int dimes = 0;
int quarters = 0;

nickels = nickels+count

-nickels++ is the same as nickels = nickels + 1
-nickels-- decrements the content of the variable

final double NICKEL_VALUE = 0.05;
final double DIME_VALUE = 0.1;
final double QUARTER_VALUE = 0.25;
double money = 0;

money = nickels * NICKEL_VALUE + dimes*DIME_VALUE + quarters + QUARTER_VALUE;

Division and Remainder
-/ is the division operator
-if both arguments are integers, the result is an integer. The remainder is discarded
7.0 / 4 = 1.75
7 / 4 = 1
Get the remainder with % (pronounced "Modulo")
7 % 4 = 3

Mathematical Functions

Type Conversion
-in assignment, types must match.
double total = "a lot"; //no
-Use "cast" (int) to convert floating-point values to integer values:
int pennies
= (int)(total * 100);
-Cast discards fractional part.

-Use Math.roun for rounding:
int dollar =

-Strings constants:
-String variables:
String name = "Carl";
-String length:
int n = name.length()

-String fname = "Harry"'
String iname = "Hacker";
String name = fname +iname;
-Name is "HarryHacker"
-if one operand of + is a string, the other is converted to a string:
String a = "Agent";
String name = a + 7;
-name is Agent7

Converting between Strings and Numbers
-Convert to number:
int n = integer.parseint(str);
double x = Double.parseDouble(x);
-Convert to string
String str = "" + n;
str = Integer.toSTring(n);

-String greeting = "Clown";
String sub = greeting.substring(1, 4);
-Supply start and "past the end" position
-First position is at 0
1-C, 2-L, 3-O, 4-W, n
-substring length = "past the end" - start

Reading Input
-String input = JOptionPane.showIntputDialog(prompt)
-Convert strings to numbers if necessary:
int count = Integers.parseInt(input);
-Conversion throws an exception if user doesn't supply a number
to the main method of any program the uses JOptionPane

An input Dialog

Import javax.swing.JOptionPane

this program tests input from an input dialog.
public class InputTest
   public static void main(String[]args)
   Purse myPurse = new Purse();
String input = JOptionPane.showInputDialog(“How many nickels do you
   Int count = Integer.parseInt(input);
   my Purse.addNickels(count);
   input = JOptionPane.showInputDialog(“How many dimes do you have?”);
   count = integer.parseInt(input);
   myPurse. addDimes(count);
   input = JOptionPane.showInputDialog(“How many quarters do you have?”);
   count = integer.parseInt(input);
   double totalValue = myPurse.getTotal();
   System.out.println(“The total is “ + totalValue);

-char: character type-a single Unicode character
-Character constants use single quotes:
'A', '\n','\u00E9'
-'A' is not the same as "A"
-charAt method gets character from a string "Hello".charAt(0) is 'H'

Copying numbers

-double balance1 = 1000;
double balance2 = balance1;
balance2 = balance2 + 500;
-Change in balance2 does not affect balance1

Message Box Output
-JOptionPane.showMessageDialog(null. per.toString(), "Testing inheritence", JOptionPane.INFORMATION_MESSAGE);
-Message types

Hope this helped it took me about a hour to think it up
(Im suspended from school so I havnt been on ds or any computers till today while moms gone Very Happy)
Back to top Go down
Introduction to java - Using JCreator
Back to top 
Page 1 of 1
 Similar topics
» Jester java chess program
» Chess by Cellufun for mobile (java)
» j-PGN (a lightweight multiplatform java PGN reader)
» Java Chess Protocol Interface
» Bulgarian Boy Introduce Himself !

Permissions in this forum:You cannot reply to topics in this forum
Code-x :: General Chat :: runescape private [TUT] section-
Jump to: