Java Tutotrial for NLPAI 2 - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Java Tutotrial for NLPAI 2

Description:

class int2. public static void main(String[] arguments) int ... Press escape and then these 3 characters ':wq' To quit vi without saving the latest changes ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 18
Provided by: CFI9
Category:
Tags: nlpai | class | java | tutotrial

less

Transcript and Presenter's Notes

Title: Java Tutotrial for NLPAI 2


1
JavaTutotrial for NLP-AI2
  • ashishfa_at_cse.iitb.ac.in

2
Last Assignment
asgn1 asgn2
  • ? Print the details in tabular format
  • - use tabs \t
  • System.out.println("\"Can we print '\\' with
    System.out.println() statement?\"" )

3
Storing data
  • In Java, Data can be stored as
  • Numbers
  • 2, 6.67, 0.009
  • Characters
  • c, p, ?, 2
  • Strings
  • data, Hindi language, 99, www.rediff.com

4
Program
int1 int2
  • // this program will declare and print a number
  • class int2
  • public static void main(String
    arguments)
  • int weight 68
  • System.out.println("your weight
    is " weight)
  • //end of program

5
Comments(double slash)
  • Not executed
  • For documentation
  • Can be placed on any line
  • Anything written after // is not executed
  • E.g.
  • // this is a comment
  • Used to explain/describe what is done in the
    program
  • Good practice

6
Types of numbers
float1
  • int
  • Whole numbers like 0, 575, -345 etc.
  • double
  • Numbers with decimal point
  • like 12.453, 3.432, 0.0000002

7
Variable declaration
  • Before using any name, it must be declared
  • (with its type i.e int or double).
  • Needed only once in one program
  • Generally, done initially
  • Syntax
  • datatype name
  • double total // stores the total value
  • int index
  • int a,b , c, sum, interest

8
Assignment
int3 int5
  • int a //declaration needed once
  • a 10 // assignment declared above
  • int a 10 // assignment and declaration
    together
  • 10 a // not possible compilation error
  • Left hand side is always a variable for assignment

Storage area
a
10
9
Assignment
int4
  • int a , b
  • a 4
  • b 7
  • a b
  • b a
  • a 5

// a ? b ? // a 4 b ? // a 4
b 7 // a 7 b 7 // a 7 b 7 //
a 5 b 7
10
Character data
char1 char2
  • Characters
  • a, A, c , ? , 3 ,
  • (last is the single space)
  • Enclosed in single quotes
  • Character variable declaration
  • char ch
  • Character assignment
  • ch k

11
String data
string1 string2 string3
  • Strings are sequence of characters enclosed in
    double quotes
  • Declaration
  • String name
  • String address
  • String line
  • Assignment
  • name ram
  • line this is a line with spaces
  • name a // single character can be stored
  • name // empty string
  • The sequence of characters enclosed in double
    quotes, printed in println() are also strings.
  • E.g. System.out.println( Welcome ! )

12
Practice problem
  • Try to print these two figures on the screen
    using println and least number of strings

13
Essential Linux commands
  • Use tukaram(10.144.22.105) or any other linux
    machine
  • Type javac and java, to verify if java is
    installed and working properly.
  • Login to tukaram
  • ashish_at_tukaram lec2
  • Create folder (directory)
  • mkdir ltfoldernamegt
  • Goto that folder
  • cd ltfoldernamegt
  • cd
  • - To use or work into the folder
  • Remove a folder
  • rmdir ltfoldernamegt
  • list all file in the folder
  • ls

14
Vi (Vim)
  • Vi is notepad of Linux.
  • Used to write programs
  • Works in 2 modes
  • Command mode
  • - While in vi, press escape to go to command
    mode
  • Edit mode
  • - while in vi, if you are in command mode, press
    i on keyboard once to go to edit mode .

15
Vi
  • vi ltfilenamegt
  • To create a new file or existing file.
  • e.g. vi int1.java
  • Before start typing, press i to goto edit mode
    and type the program.
  • To save program
  • Press escape and then these 2 characters w
  • To save and quit vi
  • Press escape and then these 3 characters wq
  • To quit vi without saving the latest changes
  • Press escape and then these 3 characters q!

16
Essential Linux commands
  • rm ltfilenamegt
  • This command deletes the file specified
  • e.g. rm int1.class
  • To log out press ctrl-D at command prompt
  • javac , java

17
Thank you
  • ?
Write a Comment
User Comments (0)
About PowerShow.com