JAVA / Progate 본문

IT

JAVA / Progate

호랑구야 2020. 7. 27. 09:00

 

 

- print to Console

 

System.out.pirntln("~string~")

 

- variables

 

String // for letters

 

int // for numbers

 

double // for decimal num

 

//without any quotes for variable-name

 

data-type variable-name;

 

variable-name = value;

 

or

 

data-type variable-name=value;

 

 

- calculation

 

x = x + 1; -> x +=1; -> x++;

 

 

- camelCase

use a variable-name

 

camel // fine

camelCase //fine

camel_case // is used

a // not descriptive

1name // not start with a num

 

 

- cast

(double)number1 / number2;

 

 

- boolean

true or false

 

&&

||

!()

 

 

- if

 

if(condition1) {

// run this code

} else if(condition2) {

// run this code

} else {

// run this code

}

 

- switch

 

sitch (value of condition) {

case value1:

// run this code;

break;

case value2:

// run this code;

break;

case value3:

// run this code;

break;

default:

// run this code;

break;

}

 

 

 

- while

 

while (condition) {

// repeat this code

}

 

 

 

- for

 

for (initialize the variable; add a condition; upadate the variable) {

 

// repeat this code

}

 

- break;

when you want to exit the loop immediately.

 

- continue;

when you skip the loop for that specific iteration

 

 

 

 

- array

datatype[] array_name = {~,~,~};

array_name[index] = ~~

// can not assign a value to an element doen't exist

array_name.length // the length of the array

 

 

- enhanced for loop

for (type variableName: arrayName) {

// run this code

}

 

 

- method

 

class Main {

 

public static void Method_Name() {

// run this code

}

}

 

// call a method

Method_Name()

 

 

- arguments

 

// can have multiple variables. seperate them with ,

public static void Method_Name(data-type variable for reciving an argument) {

// run this code

}

 

Method_Name(argument)

 

 

- return values

 

//datatype should match the return value

public static datatype methodName(parameter) {

// run this code

return returnValue

}

 

void : no return value

 

 

- class

 

// call the method where is in the other class

className.methodName()

 

class className

// capitalized

 

 

- libraries

 

// import lib

import external library

 

// lib for calculation

import java.lang.Meth

 

      • max
      • Math.round(argument) > imported by default
      • import java.util.Scanner > scanner

 

Scanner scanner = new Scanner(System.in)

// make a new Scanner instance

String vaiableName = scanner.next();

// read a string

// method for integers and the decimals

nextInt , nextDouble

 

 

 

- Object-Oriented Programming

 

new ClassName();

// create an instance of the ClassName class

 

ClassType varableName = new ClassName();

// assign an instane to variables

 

public returnValueType methodName() {

// run this code

}

// defining methods

 

instsanceName.methodName();

// calling instance metohds

 

 

- instance

 

public dataType varableNAme;

//declar instance fields

 

instanceName.fieldName();

//access instance fileds

 

 

 

- this

 

this.varible

// only in the body of a method

// this is replaced by the instance

 

 

 

- constructors

 

// parameters of the constructor

ClassName(dataType variableName) {

// operations to run upon instantiation

}

// give the constructors the same name as its class

// do not write return or void

 

ClassType varableName = new ClassName();("arguments")

 

 

this(~~,~~,~~);

// some argument are duplicated, using this()

 

 

 

- Instances Methods

 

 

 

- class field

 

public static ~~  = 0

// class field

// set the initial value for a field

 

public ~~

// instance field

 

 

ClassName.classFieldName;

// access class field

 

 

 

 

- class method

 

public static returnType methodName() {

//code for the method

}

 

ClassName.methodName();

 

 

- getter

 

public dataType getFieldName() {

return this.privateFieldValue;

}

 

 

 

- setter

 

public dataType setFieldName() {

this.privateFieldValue = varableName;

}

 

 

 

- class inheritance

 

calss SubclassName extends SuperclassName {

// run this code

}

 

 

 

- override

 

// main calls subclass then, checks superclass

 

super.methodName();

 

 

 

 

- abstract method

 

abstract class ~ {

 

abstract public void ~(~);

 

반응형

'IT' 카테고리의 다른 글

[제25회 데이터 분석 준전문가(ADsP)/독학/합격후기]  (0) 2020.08.18
[제37회 SQL 개발자(SQLD)/독학/합격후기]  (0) 2020.08.13
JavaScript / Progate  (0) 2020.07.24
SQL / Progate  (0) 2020.07.22
HTML , CSS / Progate  (0) 2020.07.20
Comments