Basic Syntax

Programs made up of statements

  • statements end with a semicolon
  • parts separated by zero or more witespaces

System.out.println("Welcome to Java");


Reasons for writing comments

  • for wirting human readable notes

  • to hide the code from compiler

Types of comments

// line comments

/* Block comment
Text ignored within the block
 */

 /**
 Javadoc comment
 compiler treats similar to block comment,

 can be used to generate documentation
 */

Packages in Java

Packages provide organization Follow standard naming convention Affect source code structure

Package name conventions

  • All lowercase.
  • use reverse domain name notation to assure global uniqueness.
  • add further qualifiers to assure uniqueness within a company or group

package com.pluralsight; package com.pluralsight.search; package com.pluralsight.sales; package com.pluralsight.sales.accountmanagement;

Type names are qualified by their package

com.pluralsight.example.Main

package com.pluralsight.example;
public class Main {
    public static void main(String[] args){
        //....
    }
}

Package Names Affect Source Code Organization

Pakcage names affect the souce code organization src->com->pluralsight->example->Main.java

Variables

/*
Named data storage
Strongly typed

*/

int dataValue;
dataValue = 100;

int myInfo = 200;


/*
Variable Naming

Use only letters and numbers
first charcter cannot be a number
*/

int total;
int grade4;


/*
Style names using camel case
start each word after the first with uppercase
all other letters are lower case
*/

int sum;
int studentCount;
int bankAccountBalance;
int level12Training;

// unintalized, only declared variable example;

int myVar;

// intialized variable
myVar = 50;

/*v
variables can be declared final
values cannot be changed once set
helps avoid errors caused by indadvertent variable changes

*/

final int maxStudents = 25;
// final variable can be declared without intialization, but once the value is set compiler will not be allow us to change it again.
final int someVariable;

int someOtherVariable = 100;

someVariable = someOtherVariable;

Primitive Data Types

  • Built into the language
  • Foundation of all the other types
  • Four Categories
    • Integer
    • Floating point
    • Character
    • Boolean

Integer

TypebitsMin Valuemax ValueLiteral form
byte8-1281270
short16-32768327670
int32-214748364821474836470
long64-922337203685477580892233720368547758070L

Floating Point Types

store values containing a fraction portion. Literal values placed between single qoutes. for unicode code points, use \u followed by 4-digit hex value

TypebitsMin Valuemax ValueLiteral form
float321.4 * 10 rais to power -453.4 * 10 raise to power 380.0f
double644.9 * 10 rais to power -3241.7 * 10 raise to power 3080.0 or 0.0d

Character Data Types

Stores a single unicode charcter Literal values placed between single quotes

char regular = 'U';
char accentedU = '\u00DA';

Boolean Type

Stores ture/false values Literal values are true and false

Primitive data types are stored by values

It means that each variable gets its own independent copy of each value.

int firstValue = 100;

// otherValue varriable will have it's own value which is hundred in this case and otherValue and firstValue has no link or relationship after assignment.

int otherValue = firstValue;

Arithmetic Operators

Basic

Produce a result, No impact on values used in the operation.

Prefix/Postfix

Increase or decrease a value Replace orignal value.

++ Increment value by 1

Dccrement value by 1

Order Matter Prefix applies operation before returning value ``+

Postfix applies operation after returning value

Compound Assignment

operate on a value replace orignal value

Next