Vous êtes sur la page 1sur 6

DataTypes

/*

* Program: DataTypes.java

* Author: Mr. Liconti

* Date: 09/09/2006

* Modified 5/10/2010

* Description: Example usage and range of Java data types.

*/

//PLEASE NOTE THAT I AM BUILDING VARIABLES ALL OVER THIS CLASS.

//DO NOT DO THIS WITH YOUR CLASSES!

public class DataTypes

public static void main(String[] args)

// Integer Data Types

// These data types cannot represent decimal places

byte b = 1; // range -128 to 127

short s = 10; // range -32,768 to 32,767

int i = 100; // range -2,147,483,648 to 2,147,483,647

long l = 1000; //range -9,223,372,036,854,775,808 to

// 9,223,372,036,854,775,807
// if L is supplied i.e.

// long myvar=1L, then the var will be

// stored in a 64 bit variable

//Floating Point Data Types

//These data types can represent decimal places

float f = 1.0F; // range -3.40292347E+38 to 3.40292347E+28

// java defaults float to double unless

// F is supplied i.e. float myvar=1.0F;

double d = 1.0; // range -1.79769313486231570E+308 to

// 1.79769313486231570E+308

//Character Data Type

char c = 'a'; // Single characters only, not strings

//Boolean Data Type

//This data type can only be true or false

//Do not use 0 or 1 like in C / C++

boolean bb = true;

//String Data Type

String ss = "Hi"; //Holds any series of characters

// In Java Strings are OBJECTS

// Strings are immutable


System.out.println("Byte: " + b);

System.out.println("Short: " + s);

System.out.println("Integer: " + i);

System.out.println("Long: " + l);

System.out.println("Float: " + f);

System.out.println("Double: " + d);

System.out.println("Character: "+ c);

System.out.println("Boolean: " + bb);

System.out.println("String: " + ss);

}
My First Program

/* Program: MyFirstProgram

* Author: Cody T.

*/

//Public is the type of class we are creating. It can be public or private

//MyFirstProgram is the name I am assigning to this class. Make sure the name matches
the file name.

public class MyFirstProgram

{ //This french brace opens the class

//Public is the type of method we are creating

//Static defines the method as being unchangable

//Void is used because this method will not be returning a value

//Main is the name of this method, and MUST be main

//String[] args is the name of the string array which will handle operations in main

public static void main(String[] args)

{ //This french brace opens main

//System.out.println is sending the message to the system's output function and is


printing the line
//When displaying a message, ensure that it rests in brackets and then quotations

System.out.println("This is my first program!"); //after every line of code lies a semi-


colon

} //This french brace closes main

} //This french brace closes the class

//Without the comments this is what the program looks like

public class MyFirstProgram

public static void main(String[] args)

System.out.println("This is my first program!");

HelloWorld
/*

* Program: HelloWorld.java

* Author: Mr. Liconti

* Date: 09/09/2006

* Description: A java version of the classic "Hello World!" application.

*/

public class HelloWorld

public static void main(String[] args)

System.out.println("Hi");

Vous aimerez peut-être aussi