SlideShare a Scribd company logo
BASIC STRUCTURE – Fundamentals to Understand
Class
Attributes
Primitive data types in Java
Arrays – How to declare them
Methods in Java
Main method - It provides the control of program flow.
Simple methods – We need object to access such methods
Static methods - We DON’T need object to access such methods
Constructors
Object – An instance of a class
How to instantiate? Calling of method/attribute.
//Creating an object of Student class with name as “ram”
Student ram = new Student();
//Accessing the method/attribute of ram
ram.course=“M.C.A”;
System.out.println(“New course of ram is: ”+ ram.course)
BASIC STRUCTURE – Fundamentals to Understand
Single line comments: These comments start with //
e.g.: // this is comment line
Multi line comments: These comments start with /* and end with */
e.g.: /* this is comment line*/
Since Java is purely an Object Oriented Programming language –
• We must have at least one class.
• We must create an object of a class, to access SIMPLE methods/attributes of
a class.
Static methods are the methods, which can be called and executed without
creating objects. e.g. main() method.
BASIC STRUCTURE – Flow of Execution
JVM contains the Java interpreter, which in turn calls the main () method using its Classname.main
() at the time of running the program.
main() method must contain String array as argument.
Since, main () method should be available to the JVM, it should be
declared as public.
Write the main method. Execution starts from main() method.
[Plz note, we do not need an object to access/execute main() method becuase it is static.]
Write the first class containing the main() method.
Name of the class and the name of the file should be EXACLTY same.
Import the required packages. By default import java.lang.*
A package is a kind of directory that contains a group of related classes and interfaces. A class or interface contains methods.
//This program prints Welcome to Java!
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
PROGRAM EXECUTION – STEP I
Enter main method.
The main method provides the control of program flow. The Java interpreter
executes the application by invoking the main method.
//This program prints Welcome to Java!
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
PROGRAM EXECUTION – STEP II
Execute Statement 1
ESCAPE SEQUENCE
Java supports all escape sequence which is supported by C/ C++.
t Insert a tab in the text at this point.
b Insert a backspace in the text at this point.
n Insert a newline in the text at this point.
r Insert a carriage return in the text at this point.
f Insert a form feed in the text at this point.
' Insert a single quote character in the text at this point.
" Insert a double quote character in the text at this point.
 Insert a backslash character in the text at this point.
USER INPUT
There are three ways to take input from a user:
1. User input as Command Line Argument
2. User input using Scanner class object
3. User input using BufferedReader class object
USER INPUT - Command Line Argument - Example
class Student{
String course;
String address;
Integer semester;
}
import java.lang.*;
class Test{
public static void main(String[] args){
Student ramesh = new Student();
//Set the values to attributes
ramesh.course="B.Tech";
ramesh.address=“Delhi";
}
}
USER INPUT - Command Line Argument - Example
class Student{
String course;
String address;
Integer semester;
}
import java.lang.*;
class Test{
public static void main(String[] args){
Student ramesh = new Student();
//Set the values to attributes
ramesh.course=args[0];
ramesh.address=args[1];
}
}
javac Test.java
java Test B.Tech Delhi
USER INPUT - Command Line Argument - Example
class Student{
String course;
String address;
Integer semester;
}
import java.lang.*;
class Test{
public static void main(String[] args){
Student ramesh = new Student();
//Set the values to attributes
ramesh.course=args[0];
ramesh.address=args[1];
int i = Integer.parseInt(args[2]);
ramesh.semester=i
}
}
javac Test.java
java Test B.Tech Delhi 5
USER INPUT - using Scanner class object
import java.util.Scanner;
class Test{
public static void main(String[] args){
Student ramesh = new Student();
Scanner ob=new Scanner(System.in);
System.out.println("Please enter the course");
String courseTemp=ob.nextLine();
System.out.println("Please enter sem no. ");
int semesterTemp=ob.nextInt();
//Set the values to attributes
ramesh.course=courseTemp;
ramesh.semester=semesterTemp;
}
}
For more: http://www.tutorialspoint.com/java/util/java_util_scanner.htm
USER INPUT - using BufferedReader class object
import java.io.BufferedReader;
import java.io.Exception;
import java.io.InputStreamReader;
public class Test{
public static void main(String[] args) throws Exception {
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.print("Enter String");
String s = br.readLine();
System.out.print("Enter Integer:");
try{
int i = Integer.parseInt(br.readLine());
}catch(Exception e){
System.err.println("Invalid Format!");
System.out.println(e);
}
}
}
For more: http://stackoverflow.com/questions/2231369/scanner-vs-bufferedreader
BASIC STRUCTURE – Fundamentals to Understand
Class
Attributes
Primitive data types in Java
Arrays – How to declare them
Methods in Java
Main method - It provides the control of program flow.
Simple methods – We need object to access such methods
Static methods - We DON’T need object to access such methods
Constructors
Object – An instance of a class
How to instantiate? Calling of method/attribute.
CONSTRUCTOR
A class contains constructors that are invoked to create objects.
There are basically two rules defined for the constructor:
• Constructor name must be same as its class name
• Constructor must have no explicit return type
Class Bicycle{
int gear, cadence, speed;
public Bicycle(int startCadence, int startSpeed, int startGear) {
gear = startGear;
cadence = startCadence;
speed = startSpeed;
}
}
To create a new Bicycle object called myBike, a constructor is called by the new operator:
Bicycle myBike = new Bicycle(30, 0, 8);
new Bicycle(30, 0, 8) creates space in memory for the object and initializes its fields.
CONSTRUCTOR
Although Bicycle only has one constructor, it could have others, including a no-argument
constructor:
//Inside Bicycle class
public Bicycle() {
gear = 1;
cadence = 10;
speed = 0;
}
//Outside Bicycyle class – e.g. Inside main method
Bicycle yourBike = new Bicycle();
above statement invokes the no-argument constructor to create a new Bicycle
object called yourBike.
• Both (or more) constructors could have been declared in same class - Bicycle.
• Constructors are differentiated by Java Interpreter based on the SIGNATURE.
• SIGNATURE = No. of arguments + Data type of arguments + Order of arguments
CONSTRUCTOR
class Student{
String course;
String address;
int semester;
//Default Constructor – NO ARGUMENT
public Student(){
//Creates space in memory for the object and initializes its fields to defualt.
}
//Parameterized Constructor – ALL ARGUMENTS
public Student(String s1, String s2, int i1){
this.course=s1;
this.course=s2;
this.semester=i1;
}
//Parameterized Constructor – FEW ARGUMENTS
public Student(String s1){
this.course=s1;
}
}
Rule: If there is no constructor in a class, compiler automatically creates a default constructor.
CONSTRUCTOR
import java.lang.*;
class Test{
public static void main(String[] args){
//Get the values in to TEMPORARY variables
String temp1 = args[0];
String temp2 = args[1];
int temp3 = args[2];
Student ramesh = new Student(temp1,temp2,temp3);
System.out.println(ramesh.course);
System.out.println(ramesh.address);
System.out.println(ramesh.semester);
}
}
javac Test.java
java Test B.Tech Delhi 5
PRIMITIVE DATA TYPE in JAVA
Type Contains Default Size Range
byte Signed integer 0 8 bits -128 to 127
short Signed integer 0 16 bits -32768 to 32767
int Signed integer 0 32 bits -2147483648 to 2147483647
float
IEEE 754 floating
point
0.0f 32 bits ±1.4E-45 to ±3.4028235E+38
long Signed integer 0L 64 bits
-9223372036854775808 to
9223372036854775807
double
IEEE 754 floating
point
0.0d 64 bits ±4.9E-324 to ±1.7976931348623157E+308
boolean true or false FALSE 1 bit NA
char Unicode character 'u0000' 16 bits u0000 to uFFFF
FEATURES of JAVA
• Simple: Learning and practicing java is easy because of resemblance with C and C++.
• Object Oriented Programming Language: Unlike C++, Java is purely OOP.
• Distributed: Java is designed for use on network; it has an extensive library which works
in agreement with TCP/IP.
• Secure: Java is designed for use on Internet. Java enables the construction of virus-free,
tamper free systems.
• Robust (Strong enough to withstand intellectual challenge): Java programs will not
crash because of its exception handling and its memory management features.
• Interpreted: Java programs are compiled to generate the byte code. This byte code can
be downloaded and interpreted by the interpreter. .class file will have byte code
instructions and JVM which contains an interpreter will execute the byte code.
FEATURES of JAVA
• Portable: Java does not have implementation dependent aspects and it yields or gives
same result on any machine.
• Architectural Neutral Language: Java byte code is not machine dependent, it can run
on any machine with any processor and with any OS.
• High Performance: Along with interpreter there will be JIT (Just In Time) compiler which
enhances the speed of execution.
• Multithreaded: Executing different parts of program simultaneously is called
multithreading. This is an essential feature to design server side programs.
• Dynamic: We can develop programs in Java which dynamically change on Internet (e.g.:
Applets).
P l e a s e G o o g l e / Re a d m o re fo r R E D h i g h l i g h t e d c o l o r ke y w o rd s
F O R M O R E I N F O / O F F I C I A L L I N K - JAVA
h t t p : / / d o c s . o ra c l e . c o m / j a v a s e / t u t o r i a l / j a v a / j a v a O O / i n d e x . h t m l

More Related Content

What's hot (19)

Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz
SAurabh PRajapati
 
Core java
Core javaCore java
Core java
Shivaraj R
 
Java platform
Java platformJava platform
Java platform
BG Java EE Course
 
Java Programming
Java ProgrammingJava Programming
Java Programming
Anjan Mahanta
 
Core Java
Core JavaCore Java
Core Java
Prakash Dimmita
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
eMexo Technologies
 
Core java
Core javaCore java
Core java
kasaragaddaslide
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
Singsys Pte Ltd
 
Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course
Kernel Training
 
Java API, Exceptions and IO
Java API, Exceptions and IOJava API, Exceptions and IO
Java API, Exceptions and IO
Jussi Pohjolainen
 
Java
JavaJava
Java
Sneha Mudraje
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
Sanjeev Tripathi
 
Object oriented programming-with_java
Object oriented programming-with_javaObject oriented programming-with_java
Object oriented programming-with_java
Hoang Nguyen
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
kankemwa Ishaku
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For Syntax
PravinYalameli
 
Java notes
Java notesJava notes
Java notes
Upasana Talukdar
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
Intelligo Technologies
 
Unit 2 Java
Unit 2 JavaUnit 2 Java
Unit 2 Java
arnold 7490
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
Vijay A Raj
 

Viewers also liked (14)

X$Tables And Sga Scanner, DOAG2009
X$Tables And Sga Scanner, DOAG2009X$Tables And Sga Scanner, DOAG2009
X$Tables And Sga Scanner, DOAG2009
Frank
 
Pemrograman Berorientasi Objek dengan Java
Pemrograman Berorientasi Objek dengan JavaPemrograman Berorientasi Objek dengan Java
Pemrograman Berorientasi Objek dengan Java
Ade Hendini
 
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Harmeet Singh(Taara)
 
Buffer and scanner
Buffer and scannerBuffer and scanner
Buffer and scanner
Arif Ullah
 
Define location of Preplaced cells(http://www.vlsisystemdesign.com/PD-Flow.php)
Define location of Preplaced cells(http://www.vlsisystemdesign.com/PD-Flow.php)Define location of Preplaced cells(http://www.vlsisystemdesign.com/PD-Flow.php)
Define location of Preplaced cells(http://www.vlsisystemdesign.com/PD-Flow.php)
VLSI SYSTEM Design
 
1 java - data type
1  java - data type1  java - data type
1 java - data type
vinay arora
 
Jnp
JnpJnp
Jnp
hj43us
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
Shahjahan Samoon
 
Java I/O
Java I/OJava I/O
Java I/O
Jussi Pohjolainen
 
Esoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsEsoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basics
Rasan Samarasinghe
 
Object-Oriented Analysis and Design
Object-Oriented Analysis and DesignObject-Oriented Analysis and Design
Object-Oriented Analysis and Design
RiazAhmad786
 
Structured Vs, Object Oriented Analysis and Design
Structured Vs, Object Oriented Analysis and DesignStructured Vs, Object Oriented Analysis and Design
Structured Vs, Object Oriented Analysis and Design
Motaz Saad
 
Class object method constructors in java
Class object method constructors in javaClass object method constructors in java
Class object method constructors in java
Raja Sekhar
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
Haitham El-Ghareeb
 
X$Tables And Sga Scanner, DOAG2009
X$Tables And Sga Scanner, DOAG2009X$Tables And Sga Scanner, DOAG2009
X$Tables And Sga Scanner, DOAG2009
Frank
 
Pemrograman Berorientasi Objek dengan Java
Pemrograman Berorientasi Objek dengan JavaPemrograman Berorientasi Objek dengan Java
Pemrograman Berorientasi Objek dengan Java
Ade Hendini
 
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Harmeet Singh(Taara)
 
Buffer and scanner
Buffer and scannerBuffer and scanner
Buffer and scanner
Arif Ullah
 
Define location of Preplaced cells(http://www.vlsisystemdesign.com/PD-Flow.php)
Define location of Preplaced cells(http://www.vlsisystemdesign.com/PD-Flow.php)Define location of Preplaced cells(http://www.vlsisystemdesign.com/PD-Flow.php)
Define location of Preplaced cells(http://www.vlsisystemdesign.com/PD-Flow.php)
VLSI SYSTEM Design
 
1 java - data type
1  java - data type1  java - data type
1 java - data type
vinay arora
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
Shahjahan Samoon
 
Esoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsEsoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basics
Rasan Samarasinghe
 
Object-Oriented Analysis and Design
Object-Oriented Analysis and DesignObject-Oriented Analysis and Design
Object-Oriented Analysis and Design
RiazAhmad786
 
Structured Vs, Object Oriented Analysis and Design
Structured Vs, Object Oriented Analysis and DesignStructured Vs, Object Oriented Analysis and Design
Structured Vs, Object Oriented Analysis and Design
Motaz Saad
 
Class object method constructors in java
Class object method constructors in javaClass object method constructors in java
Class object method constructors in java
Raja Sekhar
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
Haitham El-Ghareeb
 
Ad

Similar to java: basics, user input, data type, constructor (20)

Jacarashed-1746968053-300050282-Java.ppt
Jacarashed-1746968053-300050282-Java.pptJacarashed-1746968053-300050282-Java.ppt
Jacarashed-1746968053-300050282-Java.ppt
DilipDas70
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to Java
SMIJava
 
Mpl 1
Mpl 1Mpl 1
Mpl 1
AHHAAH
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
VijalJain3
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
Abhijeet Dubey
 
JAVA_BASICS.ppt
JAVA_BASICS.pptJAVA_BASICS.ppt
JAVA_BASICS.ppt
VGaneshKarthikeyan
 
JAVA_BASICS_Data_abstraction_encapsulation.ppt
JAVA_BASICS_Data_abstraction_encapsulation.pptJAVA_BASICS_Data_abstraction_encapsulation.ppt
JAVA_BASICS_Data_abstraction_encapsulation.ppt
VGaneshKarthikeyan
 
object oriented programming unit one ppt
object oriented programming unit one pptobject oriented programming unit one ppt
object oriented programming unit one ppt
isiagnel2
 
Unit 1
Unit 1Unit 1
Unit 1
LOVELY PROFESSIONAL UNIVERSITY
 
Java tutorial for beginners-tibacademy.in
Java tutorial for beginners-tibacademy.inJava tutorial for beginners-tibacademy.in
Java tutorial for beginners-tibacademy.in
TIB Academy
 
UNIT 1 : object oriented programming.pptx
UNIT 1 : object oriented programming.pptxUNIT 1 : object oriented programming.pptx
UNIT 1 : object oriented programming.pptx
amanuel236786
 
Module 1 full slidfcccccccccccccccccccccccccccccccccccdes.pptx
Module 1 full slidfcccccccccccccccccccccccccccccccccccdes.pptxModule 1 full slidfcccccccccccccccccccccccccccccccccccdes.pptx
Module 1 full slidfcccccccccccccccccccccccccccccccccccdes.pptx
rishiskj
 
Basics java programing
Basics java programingBasics java programing
Basics java programing
Darshan Gohel
 
Java Notes
Java Notes Java Notes
Java Notes
Sreedhar Chowdam
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
Sreedhar Chowdam
 
Java programmingjsjdjdjdjdjdjdjdjdiidiei
Java programmingjsjdjdjdjdjdjdjdjdiidieiJava programmingjsjdjdjdjdjdjdjdjdiidiei
Java programmingjsjdjdjdjdjdjdjdjdiidiei
rajputtejaswa12
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
caswenson
 
#_ varible function
#_ varible function #_ varible function
#_ varible function
abdullah al mahamud rosi
 
Java basic concept
Java basic conceptJava basic concept
Java basic concept
University of Potsdam
 
Multi Threading- in Java WPS Office.pptx
Multi Threading- in Java WPS Office.pptxMulti Threading- in Java WPS Office.pptx
Multi Threading- in Java WPS Office.pptx
ManasaMR2
 
Jacarashed-1746968053-300050282-Java.ppt
Jacarashed-1746968053-300050282-Java.pptJacarashed-1746968053-300050282-Java.ppt
Jacarashed-1746968053-300050282-Java.ppt
DilipDas70
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to Java
SMIJava
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
VijalJain3
 
JAVA_BASICS_Data_abstraction_encapsulation.ppt
JAVA_BASICS_Data_abstraction_encapsulation.pptJAVA_BASICS_Data_abstraction_encapsulation.ppt
JAVA_BASICS_Data_abstraction_encapsulation.ppt
VGaneshKarthikeyan
 
object oriented programming unit one ppt
object oriented programming unit one pptobject oriented programming unit one ppt
object oriented programming unit one ppt
isiagnel2
 
Java tutorial for beginners-tibacademy.in
Java tutorial for beginners-tibacademy.inJava tutorial for beginners-tibacademy.in
Java tutorial for beginners-tibacademy.in
TIB Academy
 
UNIT 1 : object oriented programming.pptx
UNIT 1 : object oriented programming.pptxUNIT 1 : object oriented programming.pptx
UNIT 1 : object oriented programming.pptx
amanuel236786
 
Module 1 full slidfcccccccccccccccccccccccccccccccccccdes.pptx
Module 1 full slidfcccccccccccccccccccccccccccccccccccdes.pptxModule 1 full slidfcccccccccccccccccccccccccccccccccccdes.pptx
Module 1 full slidfcccccccccccccccccccccccccccccccccccdes.pptx
rishiskj
 
Basics java programing
Basics java programingBasics java programing
Basics java programing
Darshan Gohel
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
Sreedhar Chowdam
 
Java programmingjsjdjdjdjdjdjdjdjdiidiei
Java programmingjsjdjdjdjdjdjdjdjdiidieiJava programmingjsjdjdjdjdjdjdjdjdiidiei
Java programmingjsjdjdjdjdjdjdjdjdiidiei
rajputtejaswa12
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
caswenson
 
Multi Threading- in Java WPS Office.pptx
Multi Threading- in Java WPS Office.pptxMulti Threading- in Java WPS Office.pptx
Multi Threading- in Java WPS Office.pptx
ManasaMR2
 
Ad

More from Shivam Singhal (10)

English tenses
English tenses English tenses
English tenses
Shivam Singhal
 
ofdm
ofdmofdm
ofdm
Shivam Singhal
 
Chapter 1 introduction to Indian financial system
Chapter 1 introduction to Indian financial systemChapter 1 introduction to Indian financial system
Chapter 1 introduction to Indian financial system
Shivam Singhal
 
Chapter 3 capital market
Chapter 3 capital marketChapter 3 capital market
Chapter 3 capital market
Shivam Singhal
 
Chapter 2 money market
Chapter 2 money marketChapter 2 money market
Chapter 2 money market
Shivam Singhal
 
project selection
project selectionproject selection
project selection
Shivam Singhal
 
introduction to project management
introduction to project management introduction to project management
introduction to project management
Shivam Singhal
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
Shivam Singhal
 
java:characteristics, classpath, compliation
java:characteristics, classpath, compliationjava:characteristics, classpath, compliation
java:characteristics, classpath, compliation
Shivam Singhal
 
10 8086 instruction set
10 8086 instruction set10 8086 instruction set
10 8086 instruction set
Shivam Singhal
 
Chapter 1 introduction to Indian financial system
Chapter 1 introduction to Indian financial systemChapter 1 introduction to Indian financial system
Chapter 1 introduction to Indian financial system
Shivam Singhal
 
Chapter 3 capital market
Chapter 3 capital marketChapter 3 capital market
Chapter 3 capital market
Shivam Singhal
 
Chapter 2 money market
Chapter 2 money marketChapter 2 money market
Chapter 2 money market
Shivam Singhal
 
introduction to project management
introduction to project management introduction to project management
introduction to project management
Shivam Singhal
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
Shivam Singhal
 
java:characteristics, classpath, compliation
java:characteristics, classpath, compliationjava:characteristics, classpath, compliation
java:characteristics, classpath, compliation
Shivam Singhal
 
10 8086 instruction set
10 8086 instruction set10 8086 instruction set
10 8086 instruction set
Shivam Singhal
 

Recently uploaded (20)

Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)
pelumiadigun2006
 
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODSWIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
samueljackson3773
 
Irja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus - Beyond Pass and Fail - DevTalks.pdfIrja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401
Unknown
 
社内勉強会資料_Chain of Thought .
社内勉強会資料_Chain of Thought                           .社内勉強会資料_Chain of Thought                           .
社内勉強会資料_Chain of Thought .
NABLAS株式会社
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Computer_vision-photometric_image_formation.pdf
Computer_vision-photometric_image_formation.pdfComputer_vision-photometric_image_formation.pdf
Computer_vision-photometric_image_formation.pdf
kumarprem6767merp
 
New Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docxNew Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docx
misheetasah
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
djiceramil
 
David Boutry - Mentors Junior Developers
David Boutry - Mentors Junior DevelopersDavid Boutry - Mentors Junior Developers
David Boutry - Mentors Junior Developers
David Boutry
 
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) ProjectMontreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Alexandra N. Martinez
 
Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.
Sowndarya6
 
Airport_Substation_With_Diagrams (2).pptx
Airport_Substation_With_Diagrams (2).pptxAirport_Substation_With_Diagrams (2).pptx
Airport_Substation_With_Diagrams (2).pptx
BibekMedhi2
 
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journeyRigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Yannis
 
IOt Based Research on Challenges and Future
IOt Based Research on Challenges and FutureIOt Based Research on Challenges and Future
IOt Based Research on Challenges and Future
SACHINSAHU821405
 
Structure of OS ppt Structure of OsS ppt
Structure of OS ppt Structure of OsS pptStructure of OS ppt Structure of OsS ppt
Structure of OS ppt Structure of OsS ppt
Wahajch
 
22PCOAM16 _ML_Unit 3 Notes & Question bank
22PCOAM16 _ML_Unit 3 Notes & Question bank22PCOAM16 _ML_Unit 3 Notes & Question bank
22PCOAM16 _ML_Unit 3 Notes & Question bank
Guru Nanak Technical Institutions
 
Ppt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineeringPpt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineering
ravindrabodke
 
Présentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptxPrésentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptx
KHADIJAESSAKET
 
Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)
pelumiadigun2006
 
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODSWIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
samueljackson3773
 
Irja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus - Beyond Pass and Fail - DevTalks.pdfIrja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401
Unknown
 
社内勉強会資料_Chain of Thought .
社内勉強会資料_Chain of Thought                           .社内勉強会資料_Chain of Thought                           .
社内勉強会資料_Chain of Thought .
NABLAS株式会社
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Computer_vision-photometric_image_formation.pdf
Computer_vision-photometric_image_formation.pdfComputer_vision-photometric_image_formation.pdf
Computer_vision-photometric_image_formation.pdf
kumarprem6767merp
 
New Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docxNew Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docx
misheetasah
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
djiceramil
 
David Boutry - Mentors Junior Developers
David Boutry - Mentors Junior DevelopersDavid Boutry - Mentors Junior Developers
David Boutry - Mentors Junior Developers
David Boutry
 
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) ProjectMontreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Alexandra N. Martinez
 
Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.
Sowndarya6
 
Airport_Substation_With_Diagrams (2).pptx
Airport_Substation_With_Diagrams (2).pptxAirport_Substation_With_Diagrams (2).pptx
Airport_Substation_With_Diagrams (2).pptx
BibekMedhi2
 
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journeyRigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Yannis
 
IOt Based Research on Challenges and Future
IOt Based Research on Challenges and FutureIOt Based Research on Challenges and Future
IOt Based Research on Challenges and Future
SACHINSAHU821405
 
Structure of OS ppt Structure of OsS ppt
Structure of OS ppt Structure of OsS pptStructure of OS ppt Structure of OsS ppt
Structure of OS ppt Structure of OsS ppt
Wahajch
 
Ppt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineeringPpt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineering
ravindrabodke
 
Présentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptxPrésentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptx
KHADIJAESSAKET
 

java: basics, user input, data type, constructor

  • 1. BASIC STRUCTURE – Fundamentals to Understand Class Attributes Primitive data types in Java Arrays – How to declare them Methods in Java Main method - It provides the control of program flow. Simple methods – We need object to access such methods Static methods - We DON’T need object to access such methods Constructors Object – An instance of a class How to instantiate? Calling of method/attribute. //Creating an object of Student class with name as “ram” Student ram = new Student(); //Accessing the method/attribute of ram ram.course=“M.C.A”; System.out.println(“New course of ram is: ”+ ram.course)
  • 2. BASIC STRUCTURE – Fundamentals to Understand Single line comments: These comments start with // e.g.: // this is comment line Multi line comments: These comments start with /* and end with */ e.g.: /* this is comment line*/ Since Java is purely an Object Oriented Programming language – • We must have at least one class. • We must create an object of a class, to access SIMPLE methods/attributes of a class. Static methods are the methods, which can be called and executed without creating objects. e.g. main() method.
  • 3. BASIC STRUCTURE – Flow of Execution JVM contains the Java interpreter, which in turn calls the main () method using its Classname.main () at the time of running the program. main() method must contain String array as argument. Since, main () method should be available to the JVM, it should be declared as public. Write the main method. Execution starts from main() method. [Plz note, we do not need an object to access/execute main() method becuase it is static.] Write the first class containing the main() method. Name of the class and the name of the file should be EXACLTY same. Import the required packages. By default import java.lang.* A package is a kind of directory that contains a group of related classes and interfaces. A class or interface contains methods.
  • 4. //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } PROGRAM EXECUTION – STEP I Enter main method. The main method provides the control of program flow. The Java interpreter executes the application by invoking the main method.
  • 5. //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } PROGRAM EXECUTION – STEP II Execute Statement 1
  • 6. ESCAPE SEQUENCE Java supports all escape sequence which is supported by C/ C++. t Insert a tab in the text at this point. b Insert a backspace in the text at this point. n Insert a newline in the text at this point. r Insert a carriage return in the text at this point. f Insert a form feed in the text at this point. ' Insert a single quote character in the text at this point. " Insert a double quote character in the text at this point. Insert a backslash character in the text at this point.
  • 7. USER INPUT There are three ways to take input from a user: 1. User input as Command Line Argument 2. User input using Scanner class object 3. User input using BufferedReader class object
  • 8. USER INPUT - Command Line Argument - Example class Student{ String course; String address; Integer semester; } import java.lang.*; class Test{ public static void main(String[] args){ Student ramesh = new Student(); //Set the values to attributes ramesh.course="B.Tech"; ramesh.address=“Delhi"; } }
  • 9. USER INPUT - Command Line Argument - Example class Student{ String course; String address; Integer semester; } import java.lang.*; class Test{ public static void main(String[] args){ Student ramesh = new Student(); //Set the values to attributes ramesh.course=args[0]; ramesh.address=args[1]; } } javac Test.java java Test B.Tech Delhi
  • 10. USER INPUT - Command Line Argument - Example class Student{ String course; String address; Integer semester; } import java.lang.*; class Test{ public static void main(String[] args){ Student ramesh = new Student(); //Set the values to attributes ramesh.course=args[0]; ramesh.address=args[1]; int i = Integer.parseInt(args[2]); ramesh.semester=i } } javac Test.java java Test B.Tech Delhi 5
  • 11. USER INPUT - using Scanner class object import java.util.Scanner; class Test{ public static void main(String[] args){ Student ramesh = new Student(); Scanner ob=new Scanner(System.in); System.out.println("Please enter the course"); String courseTemp=ob.nextLine(); System.out.println("Please enter sem no. "); int semesterTemp=ob.nextInt(); //Set the values to attributes ramesh.course=courseTemp; ramesh.semester=semesterTemp; } } For more: http://www.tutorialspoint.com/java/util/java_util_scanner.htm
  • 12. USER INPUT - using BufferedReader class object import java.io.BufferedReader; import java.io.Exception; import java.io.InputStreamReader; public class Test{ public static void main(String[] args) throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter String"); String s = br.readLine(); System.out.print("Enter Integer:"); try{ int i = Integer.parseInt(br.readLine()); }catch(Exception e){ System.err.println("Invalid Format!"); System.out.println(e); } } } For more: http://stackoverflow.com/questions/2231369/scanner-vs-bufferedreader
  • 13. BASIC STRUCTURE – Fundamentals to Understand Class Attributes Primitive data types in Java Arrays – How to declare them Methods in Java Main method - It provides the control of program flow. Simple methods – We need object to access such methods Static methods - We DON’T need object to access such methods Constructors Object – An instance of a class How to instantiate? Calling of method/attribute.
  • 14. CONSTRUCTOR A class contains constructors that are invoked to create objects. There are basically two rules defined for the constructor: • Constructor name must be same as its class name • Constructor must have no explicit return type Class Bicycle{ int gear, cadence, speed; public Bicycle(int startCadence, int startSpeed, int startGear) { gear = startGear; cadence = startCadence; speed = startSpeed; } } To create a new Bicycle object called myBike, a constructor is called by the new operator: Bicycle myBike = new Bicycle(30, 0, 8); new Bicycle(30, 0, 8) creates space in memory for the object and initializes its fields.
  • 15. CONSTRUCTOR Although Bicycle only has one constructor, it could have others, including a no-argument constructor: //Inside Bicycle class public Bicycle() { gear = 1; cadence = 10; speed = 0; } //Outside Bicycyle class – e.g. Inside main method Bicycle yourBike = new Bicycle(); above statement invokes the no-argument constructor to create a new Bicycle object called yourBike. • Both (or more) constructors could have been declared in same class - Bicycle. • Constructors are differentiated by Java Interpreter based on the SIGNATURE. • SIGNATURE = No. of arguments + Data type of arguments + Order of arguments
  • 16. CONSTRUCTOR class Student{ String course; String address; int semester; //Default Constructor – NO ARGUMENT public Student(){ //Creates space in memory for the object and initializes its fields to defualt. } //Parameterized Constructor – ALL ARGUMENTS public Student(String s1, String s2, int i1){ this.course=s1; this.course=s2; this.semester=i1; } //Parameterized Constructor – FEW ARGUMENTS public Student(String s1){ this.course=s1; } } Rule: If there is no constructor in a class, compiler automatically creates a default constructor.
  • 17. CONSTRUCTOR import java.lang.*; class Test{ public static void main(String[] args){ //Get the values in to TEMPORARY variables String temp1 = args[0]; String temp2 = args[1]; int temp3 = args[2]; Student ramesh = new Student(temp1,temp2,temp3); System.out.println(ramesh.course); System.out.println(ramesh.address); System.out.println(ramesh.semester); } } javac Test.java java Test B.Tech Delhi 5
  • 18. PRIMITIVE DATA TYPE in JAVA Type Contains Default Size Range byte Signed integer 0 8 bits -128 to 127 short Signed integer 0 16 bits -32768 to 32767 int Signed integer 0 32 bits -2147483648 to 2147483647 float IEEE 754 floating point 0.0f 32 bits ±1.4E-45 to ±3.4028235E+38 long Signed integer 0L 64 bits -9223372036854775808 to 9223372036854775807 double IEEE 754 floating point 0.0d 64 bits ±4.9E-324 to ±1.7976931348623157E+308 boolean true or false FALSE 1 bit NA char Unicode character 'u0000' 16 bits u0000 to uFFFF
  • 19. FEATURES of JAVA • Simple: Learning and practicing java is easy because of resemblance with C and C++. • Object Oriented Programming Language: Unlike C++, Java is purely OOP. • Distributed: Java is designed for use on network; it has an extensive library which works in agreement with TCP/IP. • Secure: Java is designed for use on Internet. Java enables the construction of virus-free, tamper free systems. • Robust (Strong enough to withstand intellectual challenge): Java programs will not crash because of its exception handling and its memory management features. • Interpreted: Java programs are compiled to generate the byte code. This byte code can be downloaded and interpreted by the interpreter. .class file will have byte code instructions and JVM which contains an interpreter will execute the byte code.
  • 20. FEATURES of JAVA • Portable: Java does not have implementation dependent aspects and it yields or gives same result on any machine. • Architectural Neutral Language: Java byte code is not machine dependent, it can run on any machine with any processor and with any OS. • High Performance: Along with interpreter there will be JIT (Just In Time) compiler which enhances the speed of execution. • Multithreaded: Executing different parts of program simultaneously is called multithreading. This is an essential feature to design server side programs. • Dynamic: We can develop programs in Java which dynamically change on Internet (e.g.: Applets). P l e a s e G o o g l e / Re a d m o re fo r R E D h i g h l i g h t e d c o l o r ke y w o rd s F O R M O R E I N F O / O F F I C I A L L I N K - JAVA h t t p : / / d o c s . o ra c l e . c o m / j a v a s e / t u t o r i a l / j a v a / j a v a O O / i n d e x . h t m l