03-JAVA Syntax(2).PDF

Similar documents
PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

02 C h a p t e r Java

1

K&R2 Reference Manual 번역본

프로그램을 학교 등지에서 조금이라도 배운 사람들을 위한 프로그래밍 노트 입니다. 저 역시 그 사람들 중 하나 입니다. 중고등학교 시절 학교 도서관, 새로 생긴 시립 도서관 등을 다니며 책을 보 고 정리하며 어느정도 독학으르 공부하긴 했지만, 자주 안하다 보면 금방 잊어

05-class.key

PowerPoint 프레젠테이션

자바 프로그래밍

09-interface.key

Microsoft PowerPoint 자바-기본문법(Ch2).pptx

untitled

01-OOPConcepts(2).PDF

07 자바의 다양한 클래스.key

Microsoft PowerPoint - lec2.ppt

chap10.PDF

5장.key

Microsoft PowerPoint - 04-UDP Programming.ppt

Java

ilist.add(new Integer(1))과 같이 사용하지 않고 ilist.add(1)과 같이 사용한 것은 자바 5.0에 추가된 기본 자료형과 해당 객체 자료 형과의 오토박싱/언박싱 기능을 사용한 것으로 오토박싱이란 자바 컴파일러가 객체를 요구하는 곳에 기본 자료형

12-file.key

초보자를 위한 C# 21일 완성

rmi_박준용_final.PDF

Chap12

Connection 8 22 UniSQLConnection / / 9 3 UniSQL OID SET

Modern Javascript

비긴쿡-자바 00앞부속

Microsoft PowerPoint - Java7.pptx

C++-¿Ïº®Çؼ³10Àå

03장.스택.key

JAVA PROGRAMMING 실습 02. 표준 입출력

자바GUI실전프로그래밍2_장대원.PDF

PowerPoint Presentation

Java ...

Java ~ Java program: main() class class» public static void main(string args[])» First.java (main class ) /* The first simple program */ public class

11 템플릿적용 - Java Program Performance Tuning (김명호기술이사)

교육2 ? 그림

ch09

신림프로그래머_클린코드.key

13주-14주proc.PDF

MasoJava4_Dongbin.PDF

4. #include <stdio.h> #include <stdlib.h> int main() { functiona(); } void functiona() { printf("hihi\n"); } warning: conflicting types for functiona

Microsoft PowerPoint - 3ÀÏ°_º¯¼ö¿Í »ó¼ö.ppt

4장.문장

자바로

C# Programming Guide - Types

Mobile Service > IAP > Android SDK [ ] IAP SDK TOAST SDK. IAP SDK. Android Studio IDE Android SDK Version (API Level 10). Name Reference V

<4D F736F F F696E74202D20C1A63236C0E520BED6C7C3B8B428B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

PowerPoint Presentation

쉽게 풀어쓴 C 프로그래밍

JMF3_심빈구.PDF


Microsoft PowerPoint - 2강

歯JavaExceptionHandling.PDF

chap x: G입력

Cluster management software

교육자료

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

Cluster management software

example code are examined in this stage The low pressure pressurizer reactor trip module of the Plant Protection System was programmed as subject for

C프로-3장c03逞풚

untitled

FileMaker ODBC and JDBC Guide

JMF2_심빈구.PDF

5.스택(강의자료).key

10.0pt1height.7depth.3width±â10.0pt1height.7depth.3widthÃÊ10.0pt1height.7depth.3widthÅë10.0pt1height.7depth.3width°è10.0pt1height.7depth.3widthÇÁ10.0pt1height.7depth.3width·Î10.0pt1height.7depth.3width±×10.0pt1height.7depth.3width·¡10.0pt1height.7depth.3width¹Ö pt1height.7depth.3widthŬ10.0pt1height.7depth.3width·¡10.0pt1height.7depth.3width½º, 10.0pt1height.7depth.3width°´10.0pt1height.7depth.3widthü, 10.0pt1height.7depth.3widthº¯10.0pt1height.7depth.3width¼ö, 10.0pt1height.7depth.3width¸Þ10.0pt1height.7depth.3width¼Ò10.0pt1height.7depth.3widthµå

PowerPoint 프레젠테이션

fundamentalOfCommandPattern_calmglow_pattern_jstorm_1.0_f…

OCaml

[ 정보 ] 과학고 R&E 결과보고서 Monte Carlo Method 를이용한 고교배정시뮬레이션 연구기간 : ~ 연구책임자 : 강대욱 ( 전남대전자컴퓨터공학부 ) 지도교사 : 최미경 ( 전남과학고정보 컴퓨터과 ) 참여학생 : 박진명 ( 전

10-Java Applet

PowerPoint Presentation

Microsoft PowerPoint - java1-lab5-ImageProcessorTestOOP.pptx

PowerPoint Presentation

슬라이드 1

PowerPoint 프레젠테이션

Contents Contents 2 1 Abstract 3 2 Infer Checkers Eradicate Infer....

03장

자바-11장N'1-502

초보자를 위한 자바 2 21일 완성 - 최신개정판

10장.key

Microsoft PowerPoint - Supplement-03-TCP Programming.ppt [호환 모드]

untitled

A Tour of Java

예제 2) Test.java class A intvar= 10; void method() class B extends A intvar= 20; 1"); void method() 2"); void method1() public class Test 3"); args) A

FileMaker ODBC and JDBC Guide

13ÀåÃß°¡ºÐ

Design Issues

PowerPoint Presentation

Network Programming

DocsPin_Korean.pages

A Tour of Java

Microsoft PowerPoint - Chapter_04.pptx

歯9장.PDF


슬라이드 1

Interstage5 SOAP서비스 설정 가이드

chap8.PDF

Transcription:

JAVA Programming Language Syntax of JAVA (literal) (Variable and data types) (Comments) (Arithmetic) (Comparisons) (Operators) 2

HelloWorld application Helloworldjava // class HelloWorld { //attribute //methods // HelloWorld public static void main ( String args [ ] ) { /* public void main, String args[ ] main */ String msg = hello world! Systemoutprint( hello, world! ); Systemoutprintln(msg); // System out print // 3 HiJava applet HiJavajava // import javaawtgraphics; // import c #include import javaappletapplet; // javaawtgraphics public class HiJava extends javaappletapplet { javaawt /* javaappletapplet extends HiJava */ public void paint(graphics g) //paint { gdrawstring( Hi, my friend Java, 5, 25); ***html // drawstring x,y // <applet code = HiJavaclass width=250 height=250 > 4

class object Class template Object attribute + operation( + ),, 5 class object class Motorcycle { // Motorcyclejava String make; String color; boolean enginestate; public Motorcycle( ){ void startengine( ) { void showatts( ) { // attribute // construct // methods public static void main (String args [ ] ) { Motorcycle m = new Motorcycle( ); // Motorcycle new // m mmake = "Yamaha RZ350"; // m mcolor = "yellow"; Systemoutprintln("Calling showatts"); mshowatts( ); // class m Systemoutprintln("--------"); Systemoutprintln("Starting engine"); mstartengine( ); 6

(identifier) HelloWorld, heydude3, tail, pounda Hello World //, /t, /n 3heyDude // short // #pounda // # 7 abstract default if private throw boolean do implements protected throws break double import public transient byte else instanceof return try case extends int short void catch final interface static volatile char finally long super while class float native switch const for new synchronized continue goto package this 8

(literal),, : 8,10,16 12=10 =16 0xC ( 0x ) = 8014 ( 0 ) 32bit int 64bit long ( l ): long pennytottal = 4L; : float double 32bit float ( f ):float pivalue = 31415927f; 64bit double: double mygpa = 225; 9 (literal) (boolean) true false boolean tothineownself = true; Java C 1 true, 0 false, true true false false ( ) a, #, 3 10

(literal) \n \f \d 8 \t \\ \xd 16 \b \ \r \ \ud String class (String primitive type ) String password= Lucifer ; c, struct / union 11 (Variable) (= ), _, $ int highscore; String username; boolean gameover; int zipcode = 90210; String name = randon ; boolean cheatedonkelly = true; int age = 28, height = 70, weight = 140; 12

(separators) { ; :, 13 (Comments) /* */ // /** */ Javadoc HTML 14

/** * A TicTacToe applet A very simple, and mostly brain-dead * implementation of your favorite game! <p> * * In this game a position is represented by a white and black * bitmask A bit is set if a position is ocupied There are * 9 squares so there are 1<<9 possible positions for each * side An array of 1<<9 booleans is created, it marks * all the winning positions * * @version 12, 13 Oct 1995 * @author Arthur van Hoff * @modified 04/23/96 Jim Hagen : winning sounds * @modified 02/10/98 Mike McCloskey : added destroy() */ 15 Javadoc 16

Javadoc html 17 (Data types) (primitive types) (reference type) (Primitive type) : byte, short, int, char ( ) : float, double (reference type),, 18

(Data types) ( ) Primitive type Size Minimum Maximum Default value boolean 1-bit - - False char 16-bit Unicode 0 Unicode 2 16-1 \u0000 (null) byte 8-bit -128 +127 (byte)0 short 16-bit -32,768 +32,767 (short)0 int 32-bit -2,147,483,648 2,147,483,647 0 long 64-bit -2 63 2 63-1 0L float 32-bit IEEE754 IEEE754 00f double 64-bit IEEE754 IEEE754 00d void - - - 1 In Java version 11 only, not in 10 19 (reference type) 20

(reference type) class Car{ public static void main( ){ 1 int a = 100 ; 2 Car mycar, yourcar; 3 mycar = new Car(); 4 yourcar= mycar; 1 int a = 100; a, 100 2 Car mycar, yourcar; Car 3 mycar = new Car(); Car, (300) mycar 4 yourcar =mycar; yourcar mycar (300), yourcar mycar 21 (array) Simple or composite data types, int number[ ] ; char [ ] letters ; int grid [ ] [ ] ; char alphabet [ ] = new char [26] int primes = {7,11,13 22

Array Java ( : exception) String difficultwords[ ]; String[ ] difficultwords; Point hits[ ]; Point[ ] hits; int donations[ ]; int[ ] donations; 23 Array new [ 1] [ ] = new [ ]; [ 2] [ ] = new [ ]; ( ) String[ ] playernames = new String[10]; ( ) int temp[ ] = new int[99]; : 0 boolean : false : \0 : NULL (index) 0 = ( ) int[ ] arrayofints = ; // compile error int[ ] simple = {0, 1, 2, 3, 4; int simple[ ] = {0, 1, 2, 3, 4; 24

Array, String[] Speak = new String[10]; length length int len = Speaklength; = length - 1 len = 10 length ( ) 25 Array int[ ][ ] coords = new int[12][12]; coords[0][0] = 1; coords[0][1] = 2; new int[3][3][2] 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 2 0 1 2 0 1 2 0 1 2 26

(Operator) (Arithmetic operator) *, /(DIV), %(MOD), +(add), -(subtract) (Logical operator) &&(AND), (OR),!(NOT) (Relational operator) <, <=, ==,!=, >, >= instanceof( ) - Boolean - true - false 27 (Operator) (Unary operator) +(plus), -(minus), ++(increase), --(decrease) ~( ) (Bit operator) &(AND), (OR), ^(XOR), ~(NOT) (Conditional operator)? : ( )? (true) : (false) int a= 7, b = 10; int c = ((a * 2) < (a + b))? a : b; c a 7 28

(Operator) public class AutoInc { public static void main(string args[]) { int i = 1; prt("i : " + i); prt("++i : " + ++i); // Pre-increment prt("i++ : " + i++); // Post-increment prt("i : " + i); prt("--i : " + --i); // Pre-decrement prt("i-- : " + i--); // Post-decrement prt("i : " + i); static void prt(string s) { Systemoutprintln(s); ///:~ Output i : 1 ++i : 2 i++ : 2 i : 3 --i : 2 i-- : 2 i : 1 +, (String) (concatenate) 29 (Operator) (Shift operator) << ( ) n << s : n 2 s (n*2 s ) 0 >> ( ) n >> s : n 2 s (n/2 s ) >>> ( ) n >>> s n : n >> s n : n s 0 30

(Operator) (Cast operator) (Storage type) int a = 23; Systemoutprintln( Casting test ); long b = (long) ( a * 2323); 31 (typecasting) Byte Short Char Int Long Float Short, char, int, long, float, double int, long, float, double int, long, float, double long, float, double float, double double 32

(typecasting), (=),,, (promotion) '+' (concatenate) int j : int j = 10; Systemoutprintln("j = " + j); j 5 160 50 : int j = 5; double f = 160 + j; 33 (typecasting) : CastOnejava 1 class CastOne { 2 public static void main(string args[]) { 3 byte byte1 = 10; 4 short short1 ; 5 char char1 = 10; 6 int int1 ; 7 float float1 ; 8 long long1 ; 9 double double1 ; 10 11 short1 = byte1; // byte(8 bits) => short(16 bits) 12 int1 = short1; // short(16 bits) => int(32 bits) 13 int1 = char1; // char(16 bits) => int(32 bits) 14 long1 = int1; // int(32 bits) => long(64 bits) 15 float1 = int1; // int(32 bits) => float(32 bits) 16 double1 = long1; // long(64 bits) => double(64 bits) 17 18 34

(Operator) [] () ++ --! ~ instanceof new (type)expression * / % + - << >> >>> < > <= >= ==!= & ^ &&? : = += -= *= /= %= ^= &= = <<= >>= >>>= 35 (Operator) )) (+(plus), -(minus), ++(increase), --(decrease)~( (+, --, *, /, %, &,, ^, <<,>>,>>>) (<, >, <=, >=, ==,!=) (++, -- --,) (+, --, *, /, % ) (<, >, <=, >=, ==,!=) (&,, ^, &&,,!, ==,!=,? ) (+) 36

(Operator) (Assignment operator) =, +=, -=, *=, /=, %= <<=, >>=, >>>= &=, ^=, = 37 (Operator) == equals( ) == equals( ) ==, equals( ) public class Equivalence { public static void main(string args[]) { Integer n1 = new Integer(47); Integer n2 = new Integer(47); Systemoutprintln(n1 == n2); Systemoutprintln(n1!= n2); Output false true ==,!= 38

(Operator) public class EqualsMethod { public static void main(string args[]) { Integer n1 = new Integer(47); Integer n2 = new Integer(47); Systemoutprintln(n1equals(n2)); ///:~ Output true equals() 39 : Equaljava 1 public class Equal { 2 public static void main(string args[]) { 3 String a = new String("abc"); 4 String b = "abc"; 5 String c = b; 6 String d = a; 7 StringBuffere = newstringbuffer("abc"); 8 StringBufferg = e; 9 if(a == b) { 10 Systemoutprintln("a==b"); 11 // if(a == e) { // 12 // Systemoutprintln("a==e"); 13 if(c == b) { 14 Systemoutprintln("c==b"); 15 if(dequals(a)) { 16 Systemoutprintln("dequals(a)"); 17 if(dequals(b)) { 18 Systemoutprintln( dequals(b)"); 19 if(bequals(e)) { Systemoutprintln("bequals(e)"); % java Equal c==b dequals(a) dequals(b) 40

class ArithmeticTest { public static void main(string args[ ]) { Systemoutprintln("4+2 : " + (4+2)); Systemoutprintln("45-2 : " + (45-2)); Systemoutprintln("44*22 : " + (44*22)); Systemoutprintln("46/3 : " + (46/3)); Systemoutprintln("46%3 : " + (46%3)); Systemoutprintln("46%31 : " + (46%31)); C:\>java ArithmeticTest 4+2 : 6 45-2 : 25 44*22 : 9680000000000001 46/3 : 15333333333333332 46%3 : 15999999999999996 46%31 : 14999999999999996 41 class LogicalTest { public static void main(string args[ ]) { int x, y, z; boolean t; C:\>java LogicalTest x=2, y=1, z=1, t=true x=3, y=2, z=2, t=true x=0, y=-1, z=-1, t=false x=1, y=0, z=0, t=false x = y = z = 1; t = ((++x!= 0) (++y!= 0) (++z!= 0)); Systemoutprintln("x=" + x + ", y=" + y + ", z=" + z + ", t=" + t); t = ((++x!= 0) (++y!= 0) (++z!= 0)); Systemoutprintln("x=" + x + ", y=" + y + ", z=" + z + ", t=" + t); x = y = z = -1; t = ((++x!= 0) && (++y!= 0) && (++z!= 0)); Systemoutprintln("x=" + x + ", y=" + y + ", z=" + z + ", t=" + t); t = ((++x!= 0) & (++y!= 0) & (++z!= 0)); Systemoutprintln("x=" + x + ", y=" + y + ", z=" + z + ", t=" + t); 42

class IncDecTest { public static void main(string args[ ]) { int i=23, j=8, k; k = ++i + j--; Systemoutprintln("i=" + i + ", j=" + j +", k=" + k); k = i-- + --j; Systemoutprintln("i=" + i + ", j=" + j +", k=" + k); Systemoutprintln("i=" + ++i + ", j=" + j-- + ", i=" + --i + ", j=" + --j); C:\>java IncDecTest i=24, j=7, k=32 i=23, j=6, k=30 i=24, j=6, i=23, j=4 43 class RelationalTest { public static void main(string args[ ]) { int a=3, b=4; boolean c; c = a < b; Systemoutprintln("a=" + a + ", b=" + b + ", c=" + c); C:\>java RalationalTest a=3, b=4, c=true 44

class BitwiseTest { public static void main(string args[ ]) { byte x=(byte)0x0a, y=(byte)0x48, z=(byte)0xcc; Systemoutprintln(" x y & z = " + (byte)(x y & z)); Systemoutprintln(" x y & ~z = " + (byte)(x y & ~z)); Systemoutprintln(" x ^ y & ~z = " + (byte)(x ^ y & ~z)); x = (byte)1; y = (byte)-1; Systemoutprintln(" ~x x = " + (byte)(~x x)); Systemoutprintln(" x ^ x = " + (byte)( x ^ x)); Systemoutprintln(" x << 3 = " + (byte)(x << 3)); Systemoutprintln(" x >> 3 = " + (byte)(x >> 3)); Systemoutprintln(" x >>> 3 = " + (byte)(x >>> 3)); Systemoutprintln(" y << 3 = " + (byte)(y << 3)); Systemoutprintln(" y >> 3 = " + (byte)(y >> 3)); Systemoutprintln(" y >>> 3 = " + (byte)(y >>> 3)); 45 class AssignmentTest { public static void main(string args[ ]) { int x=2, y=5, z=0; x += 3 + 2; Systemoutprintln("x=" + x + ", y=" + y + ", z=" + z); x += y -= z = 4; Systemoutprintln("x=" + x + ", y=" + y + ", z=" + z); C:\>java AssignmentTest x=7, y=5, z=0 x=8, y=1, z=4 46

class ConditionalTest { public static voidmain(string args[ ]) { int a=23, b=12, max, min; min = (a < b)? a : b; Systemoutprintln("min=" + min + ", a=" + a + ", b=" + b); max = (a > b)? a : b; Systemoutprintln("max=" + max + ", a=" + a + ", b=" + b); C:\>java ConditionalTest min=12, a=23, b=12 max=23, a=23, b=12 47 class OperatorTest { public static void main(string args[ ]) { int a=10, b=10; float f = (float)3141592; Systemoutprintln("a=" + a + ", f=" + f + ", b=" + b); a = (int)f-- * --b; Systemoutprintln("a=" + a + ", f=" + f + ", b=" + b); C:\>java OperatorTest a=10, f=3141592, b=10 a=27, f=2141592, b=9 48