BASIC JAVA - PowerPoint PPT Presentation

About This Presentation
Title:

BASIC JAVA

Description:

BASIC JAVA. Hello World // Hello world program. public class MyFirstJavaProgram ... System.out.println('Hello World'); System.out.print('No new line'); System. ... – PowerPoint PPT presentation

Number of Views:87
Avg rating:3.0/5.0
Slides: 10
Provided by: ValuedGate2137
Category:
Tags: basic | java | hello

less

Transcript and Presenter's Notes

Title: BASIC JAVA


1
BASIC JAVA
2
Hello World
3
  • // Hello world programpublic class
    MyFirstJavaProgram public static void
    main(String args) char c
    'H' String s c "ello \nWorl"
    int last 'd' s s (char)last
    System.out.println(s)

4
Java Comments
  • // for the java one liner
  • / for a multi-line
  • comment /
  • / for a javadoc comment
  • /

5
Simple output
  • System.out.println(Hello World)
  • System.out.print(No new line)
  • System.out.print(6)
  • System.out.print(true)
  • System.out.println(610) displays 16
  • System.out.println(610) displays 610

6
Primitive Types
  • byte there are no byte literals 8 bits
  • short there are no short literals 16
    bits
  • int literals(23, -98, 077, 0xAF) 32
    bits
  • long lierals(23L, -9L) 64 bits
  • float literals (34F, -4.5f) 32 bits
  • double literals (34.0, 5e2, .4) 64 bits
  • char literals (A, \n, \377,
    \u0041) 16 bits unsigned
  • boolean literals (true, false) 16 bits

7
Assignment and types
  • short m 5 // int to short is ok
    if it fits
  • short m 500000 // compiler error 50000 int
    to short not ok
  • float m 50.0 // compiler error need
    to cast double to float
  • float m (float)50.0 // ok cast the double to
    float
  • byte b 4L // compiler error cast
    to byte

8
More on Assignment and types
  • double m 6 // int to double is fine
  • int m 6.0 // compiler error need
    to cast the double to int
  • int m (int)6.0 // works fine
  • double c \n // ok but strange
  • char c A 1 // c now holds B
  • System.out.println(A 1) // displays 66
  • System.out.println((char)(A 1)) // displays
    B

9
The String Type
  • String s "Peanut" // or, see below
  • String s new String(Peanut) // same as
    above
  • Use concatenation for long strings
  • System.out.println("This is "
  • "a very long string")
  • Many string operations exist
  • System.out.println(s.length())
  • System.out.println("Hello".length())
Write a Comment
User Comments (0)
About PowerShow.com