Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
63 views

Intro To Java

The document provides an introduction to the Java programming language. It discusses what Java is, why it should be used, and gets the reader started with their first Java program. Key points covered include: - Java is a widely used, high-level programming language that is platform independent. - The first program prints "Hello World" to demonstrate how to compile and run a Java program in NetBeans IDE. - Basic Java concepts like classes, methods, and variables are introduced. - Readers are instructed on how to install Java SDK and NetBeans to begin programming.

Uploaded by

api-326363829
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Intro To Java

The document provides an introduction to the Java programming language. It discusses what Java is, why it should be used, and gets the reader started with their first Java program. Key points covered include: - Java is a widely used, high-level programming language that is platform independent. - The first program prints "Hello World" to demonstrate how to compile and run a Java program in NetBeans IDE. - Basic Java concepts like classes, methods, and variables are introduced. - Readers are instructed on how to install Java SDK and NetBeans to begin programming.

Uploaded by

api-326363829
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 33

Introduction

to Java

Codeffine

What is Java?
Java

is one of the most widely used programming


language!

It

is a high-level machine language.

This

means we dont need to code in binary like the


old days!

Binary

consists of 01 only! Everything we write will


eventually get translated into it!

Computers

only understand binary!

Why use Java?

It is one of the most used language!

It is platform-independent.

This means the programs you write can be ran on any platforms.
Windows, OSX, Linux, etc.

Did you know Android is based on Java?

Lets get started with


our first program!

First step: Installation

Download Java Software Development Kit

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads2133151.html
This allows you to develop and run Java programs!

(OPTIONAL)Download an IDE! Netbeans IDE will be used throughout the


tutorial!

http://www.filehippo.com/download_netbeans/

If you have install third-party themes or patch windows system files, please
restore them using sfc/scannow in cmd because custom files has been known
to cause issues.

Please install the above two program!

Note: You could program without an IDE, but its much harder.

Second Step: Using Netbeans!

Open Netbeans.

Click New Project.

Select Java Application.


Then Click Next.

Name the Project Programminity!


Then Click Finish!

You should see this screen!

Delete // TODO code application logic here.


Type System.out.println(Hello World); in its place!

Click Shift + F6. This runs your program! You


should see Hello Wolrd in the output box!

Congratulations! You have created your first


Java Program!

Concepts that will be covered in the upcoming PowerPoint!

What is a class?

What is a method?

What is a variable?

How do we use variable in our program?

What is syntax?

Java: Class and


Variables
BY: PROGRAMMING COMMUNITY

Class and Its Components

A class can hold methods and variables.

Method: a set of code which has specific functions

Variables: data holders

A method can use and operate on variables.

A class is also a blueprint of objects. (OOP, a topic that will be


covered in the future)

Example

Lets imagine there is a class called Car!


It will have many methods.
Lets image a method named SteeringWheel
It has one specific function. To change
direction.

In

a good program, all the methods in the class


work together to create a complete program.
More advanced programs will even have
multiple classes working together!

Syntax time!

public class HelloWorld{

public static void main(String args[]){

System.out.println(HelloWorld);

If you remember from last tutorial, this is a simple console app to


print HelloWorld to the screen.

Rule 1: Curly Braces

In Java, curly braces must be used to indicate the start and end
of a class or method.

For example.

public class HelloWorld{

//statements

In the lines above, { is used to indicate the start of HelloWorld, }


is used to indicate the end of it.

Methods must have it too.

Rule 2: Java is case sensitive!

Public class HelloWorld{

the above line will create an error because it is supposed to be


public, not Public.
{ } can be think of as scope.

Rule 3: Naming Limitations

For both class name and variable names

It cannot start with a number.

It cannot have space. ex: Hello World will be error.

It cannot have a special character.

Variables name cannot overlap. (if within the same scope)

^ means there cant be two or more variables with the same name in
the same method. But it will be ok for both methodA and methodB to
have variables with same name. This is because the variable is in
different scope.

Rule 4: Variables name use Camel


Case.

This is not really a syntax rule. This means it will not create an
error even if you choose to not follow this rule.

However, using Camel Case for variables name is a tradition of


Java. Its highly recommended you follow it.

Camel Case: the first letter of the word is lowercase. All the
following first letter of words will be uppercase.

Example

String numOfPrograms

int numOfKids

String lionelMessi

Back to the Program!

public class HelloWorld{ //start of class

public static void main(String args[]){

System.out.println(HelloWorld);

//This part is in class.

} //end of class

Last Rule: A program needs a main method to run!

Scope of
Method

Scope of
class

Exploring System.out.println();

This is a method used to print out words to the screen.

System.out.println(HelloWorld);

You write what you want to print in the brackets (). If you are not
going to print out variables you will need like the above
example.

Summary

A lot was covered in this PowerPoint. So please reread through it


again!

Concepts to be covered in the next PowerPoint.

Data type and variables

Printing out variables.

What is wrong with this set of codes.

Java: Data Types

The Two Categories

Primitive: basic data types

byte, short, int, long, double, float, char, boolean

Reference: String, Objects

holds the reference to the actual data

reference: the pointer which points to a memory address.

The data that can be stored is based on the data type you used.

The Four Important Primitives

int: hold numbers without decimal

double: hold numbers with decimal

ex: 12.4, 24.5, 12.0

char: hold a single letter

ex: 12, 24, but cannot be 12.3

a, b, c

boolean: true or false

useful for checking conditions

Reference: String

String is a reference data type.

It can hold phrases, sentences and words.

ex. This is a String

Variables

You have probably heard of variables in Math class before.

Like them, they are names or letters that hold data.

They are used in conjunction with data types to specify what type
of data to hold.

Naming variables

Cannot start with a letter

No space

No special character

Use camelCase. Not using this will not create an error but its
java style.

camelCase = first letter of first word small. first letter of following


words capitalized.

Using variables

There are two stages.

Declaring: specifying data type and the name

Initializing: putting in data for the first time.

Declaring

int x; variable named x that hold int(numbers)

char y;

boolean trueOrFalse;

double xy;

String letters;

REMEMBER: Java is case sensitive. Only String is


capitalized.

Using variables

Initializing (Refer to slide above for what type of data the variable
was initialized into)

x = 2;

y = a; note that the is needed to initialize a char

xy = 4.0; note that even if we just input 4, the Java will turn it into
4.0

trueOrFalse = true;

letters = This is a String note that is used.

Declaration and Initializing can be combined in one step.


Ex: int x = 2;

What will happen if the variable is


not initialized?

Java will assign default values!

String: null

int: 0

double: 0.0

char: '\u0000 a null character.

Boolean: false

You might also like