mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 15:24:09 +03:00
Fix errors specified in #410.
This commit is contained in:
parent
13822f9c15
commit
8121793f32
@ -26,7 +26,8 @@ import java.util.ArrayList;
|
|||||||
// Import all classes inside of java.security package
|
// Import all classes inside of java.security package
|
||||||
import java.security.*;
|
import java.security.*;
|
||||||
|
|
||||||
// Each .java file contains one public class, with the same name as the file.
|
// Each .java file contains one outer-level public class, with the same name as
|
||||||
|
// the file.
|
||||||
public class LearnJava {
|
public class LearnJava {
|
||||||
|
|
||||||
// A program must have a main method as an entry point
|
// A program must have a main method as an entry point
|
||||||
@ -84,7 +85,7 @@ public class LearnJava {
|
|||||||
// Char - A single 16-bit Unicode character
|
// Char - A single 16-bit Unicode character
|
||||||
char fooChar = 'A';
|
char fooChar = 'A';
|
||||||
|
|
||||||
// Use final to make a variable immutable
|
// final variables can't be reassigned to another object
|
||||||
final int HOURS_I_WORK_PER_WEEK = 9001;
|
final int HOURS_I_WORK_PER_WEEK = 9001;
|
||||||
|
|
||||||
// Strings
|
// Strings
|
||||||
@ -99,7 +100,7 @@ public class LearnJava {
|
|||||||
System.out.println(bazString);
|
System.out.println(bazString);
|
||||||
|
|
||||||
// Arrays
|
// Arrays
|
||||||
//The array size must be decided upon declaration
|
//The array size must be decided upon instantiation
|
||||||
//The format for declaring an array is follows:
|
//The format for declaring an array is follows:
|
||||||
//<datatype> [] <var name> = new <datatype>[<array size>];
|
//<datatype> [] <var name> = new <datatype>[<array size>];
|
||||||
int [] intArray = new int[10];
|
int [] intArray = new int[10];
|
||||||
@ -161,10 +162,13 @@ public class LearnJava {
|
|||||||
// Incrementations
|
// Incrementations
|
||||||
int i = 0;
|
int i = 0;
|
||||||
System.out.println("\n->Inc/Dec-rementation");
|
System.out.println("\n->Inc/Dec-rementation");
|
||||||
System.out.println(i++); //i = 1. Post-Incrementation
|
// The ++ and -- operators increment and decrement by 1 respectively.
|
||||||
System.out.println(++i); //i = 2. Pre-Incrementation
|
// If they are placed before the variable, they increment then return;
|
||||||
System.out.println(i--); //i = 1. Post-Decrementation
|
// after the variable they return then increment.
|
||||||
System.out.println(--i); //i = 0. Pre-Decrementation
|
System.out.println(i++); //i = 1, prints 0 (post-increment)
|
||||||
|
System.out.println(++i); //i = 2, prints 2 (pre-increment)
|
||||||
|
System.out.println(i--); //i = 1, prints 2 (post-decrement)
|
||||||
|
System.out.println(--i); //i = 0, prints 0 (pre-decrement)
|
||||||
|
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
// Control Structures
|
// Control Structures
|
||||||
@ -294,14 +298,14 @@ public class LearnJava {
|
|||||||
trek.speedUp(3); // You should always use setter and getter methods
|
trek.speedUp(3); // You should always use setter and getter methods
|
||||||
trek.setCadence(100);
|
trek.setCadence(100);
|
||||||
|
|
||||||
// toString is a convention to display the value of this Object.
|
// toString returns this Object's string representation.
|
||||||
System.out.println("trek info: " + trek.toString());
|
System.out.println("trek info: " + trek.toString());
|
||||||
|
|
||||||
} // End main method
|
} // End main method
|
||||||
} // End LearnJava class
|
} // End LearnJava class
|
||||||
|
|
||||||
|
|
||||||
// You can include other, non-public classes in a .java file
|
// You can include other, non-public outer-level classes in a .java file
|
||||||
|
|
||||||
|
|
||||||
// Class Declaration Syntax:
|
// Class Declaration Syntax:
|
||||||
@ -319,7 +323,7 @@ class Bicycle {
|
|||||||
String name; // default: Only accessible from within this package
|
String name; // default: Only accessible from within this package
|
||||||
|
|
||||||
// Constructors are a way of creating classes
|
// Constructors are a way of creating classes
|
||||||
// This is a default constructor
|
// This is a constructor
|
||||||
public Bicycle() {
|
public Bicycle() {
|
||||||
gear = 1;
|
gear = 1;
|
||||||
cadence = 50;
|
cadence = 50;
|
||||||
@ -327,7 +331,7 @@ class Bicycle {
|
|||||||
name = "Bontrager";
|
name = "Bontrager";
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a specified constructor (it contains arguments)
|
// This is a constructor that takes arguments
|
||||||
public Bicycle(int startCadence, int startSpeed, int startGear, String name) {
|
public Bicycle(int startCadence, int startSpeed, int startGear, String name) {
|
||||||
this.gear = startGear;
|
this.gear = startGear;
|
||||||
this.cadence = startCadence;
|
this.cadence = startCadence;
|
||||||
|
Loading…
Reference in New Issue
Block a user