AP Computer Science Lesson Introductory Java Language Features (1)

in #education7 years ago

This lesson is based off of the AP Computer Science A Barron's textbook. I am using it to guide my class this year. Barron's has always been my #1 choice since I used it when I was in school for AP Biology. Enjoy the lesson folks!

APCSLogo.png

Packages and Classes

Packages are inherited programs mostly provided with the compiler.
The classes can come with the packages, but can also be made by the user, you.
import packagename.*; (This imports an entire package, * means all)
import packagename.ClassName; (This imports a class from a package)
** You do not need to know package names or import anything for the AP Exam, but we may use it to make things easier on us later!
Every Java program must contain a class. Objects are created using classes, consider them to be traits of an object.

Commenting in Codes

Comments are extremely important when coding (programming). To make a comment do this:
/**
Whatever you are explaining goes here.
*/
Or you can use this (//) // Like this
// Or like this

We use these to clarify for the reader of the program, whether it be for yourself or a new user. Imagine going through 100,000 lines of code that you know nothing about without comments.

Identifiers

An identifier is a name for a variable, parameter, constant, user-defined method, or user defined class. Identifiers must have a type, which may include int, double, boolean, etc.

int – integer (… -1, 0, 1, …) These are bounded, too bug or too small will not work.
double – rational numbers (any decimals) A double precision floating point number.
boolean – Either “True” or “False”.
final – we use in front of a constant we declare. We might say
final double taxRate = .065;

Given length and width we could find an area using:
double rectangleArea;
rectangleArea = length*width;

Storage of Numbers

The biggest integer that can be stored in one byte (8 ones)!


Which is 255.
The type int uses 4 bytes, or 32 bits, so the largest possible integer is 2^31 - 1 or 2147483647... Just use double for anything bigger.

The Hello World Program:

This is the classic beginners program. All it does is display (or print) the string "Hello, World".


public class HelloWorld {

public static void main(String[] args) {
    // Prints "Hello, World" to the terminal window.
    System.out.println("Hello, World");
}

}


Thank you for viewing Steemers! Learn much!

LogoShiny.gif

Sort:  

Sorry to say this, but Java is a dead language. :(

A tutorial for anyone that wants to know it! Lol. Many companies use C, C++, etc. which are similar enough to compare it to. If it dies it will be in like 40 years. Like FORTRAN to us now (which people still use).

Thank you steemiteducation! You're amazing!

Coin Marketplace

STEEM 0.20
TRX 0.13
JST 0.030
BTC 65306.74
ETH 3488.89
USDT 1.00
SBD 2.51