Java’s byte (-128 to 127)

Java’s byte is a signed 8-bit numeric type whose range is -128 to 127 (JLS 4.2.1). 233 is outside of this range; the same bit pattern represents -23 instead.

11101001 = 1 + 8 + 32 + 64 + 128 = 233 (int)
           1 + 8 + 32 + 64 - 128 = -23 (byte)

A byte plus a byte is an int in Java.

 

byte a = 1;
byte b = 2; 
byte c = a + b; // compile error (byte + byte = int)
byte c = (byte)(a + b); // corrected

Data Type

Primitive Type vs Reference Type

8 Primitive Data Type
https://en.wikibooks.org/wiki/Java_Programming/Primitive_Types

boolean A binary value of either true or false
byte 8 bit signed value, values from -128 to 127
short 16 bit signed value, values from -32.768 to 32.767
char 16 bit Unicode character
int 32 bit signed value, values from -2.147.483.648 to 2.147.483.647
long 64 bit signed value, values from -9.223.372.036.854.775.808 to 9.223.372.036.854.775.808
float 32 bit floating point value
double 64 bit floating point value

Object Types

Data type Description
Boolean A binary value of either true or false
Byte 8 bit signed value, values from -128 to 127
Short 16 bit signed value, values from -32.768 to 32.767
Character 16 bit Unicode character
Integer 32 bit signed value, values from -2.147.483.648 to 2.147.483.647
Long 64 bit signed value, values from -9.223.372.036.854.775.808 to 9.223.372.036.854.775.808
Float 32 bit floating point value
Double 64 bit floating point value
String N byte Unicode string of textual data. Immutable

Reference Types

class A class is also a data type – a non primitive reference data type
interface An interface is a reference type in Java, it is similar to class, it is a collection of abstract methods.
array An array’s type is written as type[] , where type is the data type of the contained elements; arrays are objects, are dynamically created, and may be assigned to variables of type Object
enum An enum type is a special data type that enables for a variable to be a set of predefined constants.

 

Variables

instance variable vs static variable vs local variable

public class Hello {

private String name; // instance variable
private static int value = 10; // static variable

public int sum(int n, int m) {

int result = n + m; // result : local variable
return result;

}

public static void main(String args[]) {

Hello h = new Hello();
h.name = “Hello”;
System.out.println(h.name);
System.out.println(Hello.value);

}

}

Naming Conventions

http://www.oracle.com/technetwork/java/codeconventions-135099.html

Identifier Type

Rules for Naming

Examples


Packages

The prefix of a unique package name is always written in all-lowercase ASCII letters and should be one of the top-level domain names, currently com, edu, gov, mil, net, org, or one of the English two-letter codes identifying countries as specified in ISO Standard 3166, 1981.Subsequent components of the package name vary according to an organization’s own internal naming conventions. Such conventions might specify that certain directory name components be division, department, project, machine, or login names.
com.sun.engcom.apple.quicktime.v2

edu.cmu.cs.bovik.cheese


Classes

Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).

class Raster;
class ImageSprite;

Interfaces

Interface names should be capitalized like class names.

interface RasterDelegate;
interface Storing;

Methods

Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.

run();
runFast();
getBackground();

Variables

Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters. Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed. Variable names should be short yet meaningful. The choice of a variable name should be mnemonic- that is, designed to indicate to the casual observer the intent of its use. One-character variable names should be avoided except for temporary “throwaway” variables. Common names for temporary variables are i, j, k, m, and n for integers; c, d, and e for characters.
int             i;
char            c;
float           myWidth;

Constants

The names of variables declared class constants and of ANSI constants should be all uppercase with words separated by underscores (“_”). (ANSI constants should be avoided, for ease of debugging.)

static final int MIN_WIDTH = 4;static final int MAX_WIDTH = 999;

static final int GET_THE_CPU = 1;

 

Eclipse Installer Error

Unfortunately the Java version needed to run Eclipse Installer couldn’t be found on your system. Java 1.8.0 (64 bit)
Please download and install a Java Runtime Environment(JRE) or a Java Development Kit (JDK)

1. 이클립스 설치 에러 발생하면 User의 이름이 한글로 되어 있는 것을 영문으로 변경
2. JRE/JDK1.8 (Window 64-bit)을 받아서 설치
https://www.oracle.com/java/technologies/javase-jre8-downloads.html
3. 오라클 JDK를 설치하면 아래 그림에서 보이듯이 환경변수 path 편집에서 C:\Program Files (x86)\Common Files\Oracle\Java\javapath가 있는데 이 부분을 삭제
4. 이후 다시 Eclipse 2019-12 설치

Lab0

JDK + Eclipse IDE + HelloJava

1.자바 JDK(Java Development Kit) 13.0.2 다운로드 설치 (설치 동영상 2020-03-03 JDK)
https://www.oracle.com/java/technologies/javase-jdk13-downloads.html

1) 환경변수 설정 JAVA_HOME 추가
컴퓨터 – 오른쪽 버튼 – 속성 – 고급시스템 설정 – 환경변수
시스템변수 – 새로 만들기
변수이름 : JAVA_HOME
변수값 : C:\Program Files\Java\jdk-13.0.2 (JDK설치폴더명)
2) 환경변수 설정 PATH 설정
시스템변수 – Path 변수값 수정
세미콜론(;) 추가 후 %JAVA_HOME%\bin 추가
3) 설치된 자바 버전 확인
cmd 창 열고, 설치된 자바 버전 확인 java -version

2.Eclipse IDE 2019-12 다운로드 설치 (설치 동영상 2020-03-03 Eclipse)
https://www.eclipse.org/downloads/

1)인스톨러에서 Eclipse IDE for Java Developers 선택해서 설치
최초 실행시 workspace 경로 설정 (C:\Users\park\eclipse-workspace\java20)

3.Hello Java 작성 (설치 동영상 2020-03-03 Hello Java)
1) 이클립스 File – New – Java Project – Project name: Hello & Use an execution environment JRE JavaSE-13 & Finish 버튼 – Create module-info.java “Don’t Create” 버튼 => Hello 프로젝트 생성
2) Hello 프로젝트 우클릭 – New – Class – Package에는 아무것도 적지말고 & Name: Hello & public static void main(String[] args) 체크 & Inherited abstract methods 언체크 – Finish 버튼 => Hello 클래스 파일 생성
3) Hello.java의 main 메소드 안에 System.out.println(“Hello World”);
4) Hello 프로젝트 우클릭 – Run as – Java Application
5) 이클립스 Console 창에서 Hello World 출력 확인