Method: Public Class Public Static Void
Method: Public Class Public Static Void
Whats is Java??
A computer language is a series of words used to give instructions to the
computer, telling it what to do, how to do it, and when to do it. Just like there
are various human languages used to communicate, there are also various
computer languages. One of these computer languages is called Java.
Whats is Class??
A class is a list of criteria used to describe something.
!ample" #ooks, Publishers, Authors, $ear Published
Whats is Ob%ects???
An ob%ect is the result of describing something using the preset criteria of a
&known' class.
Author name, (ationalit) &Particular' some thing which is particular is called
ob%ect.
*ow to +ave a %ava ,le
Java ,le must followed with . %ava like " hello.%ava, new,le.%ava
*ow to complile a simple hello or introductor) program in %ava b) using %ava
method???
Method
public class hello -
public static void main&+tring args ./'-
00 1his is a simple program
+)stem.out.println&2*ello )outube2'3
4
4
Result
*ello )outube
*ow to add comment in between coding to describing something???
comment can be write with 00 s)mbols. !ample
00 1his is a simple program
Whats is 5ariable in Programming???
A variable is a s)mbolic name for &or reference to' information. 1he variable6s name
represents what information the variable contains. 1he) are called variables because
the represented information can change but the operations on the variable remain
the same.
*ow to 7et 8esult of something in Java Programming???
for Print or 8esult this satement or command can be used. but this all follows class
and ob%ects method as well as mentioned above in ,rst simple program.
+)stem.out.print&(umber' +)stem.out.print&21e!t2'
1his above line print all together in one lin if )ou want to print too man) things.
+)stem.out.println&(umber' +)stem.out.println&21e!t2'
1his above command print on new line after using println command. ever)thing after
that will come on new line if each and ever)time println used.
*ow to get 9ata input from :ser???
1o get 9ata from a user we have to import ,rst %ava scanner using this command"
import %ava.util.+canner3
1hen insert )our class
public class hello -
4
1hen insert ob%ect
public static void main&+tring./ args' -
+canner scnr ; new +canner&+)stem.in'3
+tring ,rst(ame3
*ere scnr is a variable and scanner used to get data from user and system.in
used for that whatever user write when its asked from user.
import %ava.util.+canner3
public class hello -
public static void main&+tring./ args' -
+canner scnr ; new +canner&+)stem.in'3
+tring ,rst(ame3
00 +tring onl) contain 1e!ts
+)stem.out.print&2nter the <irst (ame" 2'3
00 <irst print above line to get data
,rst(ame ; scnr.ne!t&'3
00 After getting data now print below line
+)stem.out.print&2<irst (ame" 2'3
00 it will Write as <irst (ame" then user data
+)stem.out.print&,rst(ame'3
4
4
8esult" <irst (ame " nter <irst (ame
<irst (ame " as )ou write in nter <irst (ame
=f = miss this line & +)stem.out.print&2<irst (ame" 2'3 ' from above method its
shows result like below"
8esult" Whatever )ou written in nter <irst (ame or >ike Ali
=n above program user inputiing onl) one data in te!t now lets do it with di?erent
data t)pe. +tring is a te!t data t)pe.
What are the 9ata 1)pe???
+tring" A string is one or more characters considered as a single value.
its use as ne!t&'
#)te" A b)te is series of @ bits. =t is used to represent small numbers. 1o declare a
variable that would hold a natural number between ABC@ and BCD, )ou can use the
b)te data t)pe.
its use as ne!t#)te&'
=nt" =n Java, an integer is variable whose values are between AC,BED,E@F,GE@ and
C,BED,E@E,GED.
its use as ne!t=nt&'
+hort =ntegers " An integer is referred to as short if its value is between AFCDG@ and
FCDGD. 1his number can ,t in BG bits. 1o declare a variable that would hold numbers
in that range, )ou can use the short data t)pe.
its use as ne!t+hort&'
>ong" A long integer is a variable that can hold a ver) large number that ma) reHuire
GE bits to be stored accuratel).
=ts use as ne!t>ong&'
9ouble" 1o declare a variable used to hold such a decimal number, )ou can use
the double ke)word
its use as ne!t9ouble&'
<loat" 1o declare a variable that would hold decimal values with little to no
concern with precision, )ou can use the Ioat data t)pe.
its use as ne!t<loat&' Containt value and < at the end like ; F.BCF<3
<inal " 1o create a constant value in Java, t)pe ,nal, followed b) the t)pe of the
variable, its name, the assignment operator 2;2, and the desired value.
Char" 1he single Huote is used to include one character to initialiJe, or assign
a s)mbol to, a variable declared as char.
!ample >ike " K, A, < 7
import %ava.util.+canner3
public class hello -
public static void main&+tring./ args' -
00declaring scnr as a input variable
+canner scnr ; new +canner&+)stem.in'3
009eclaring C +trings 1ogether
+tring ,rst(ame,last(ame3
00 9eclaring (umber 9ata t)pe as 9ouble
9ouble age3
00<irst getting data for ,rst(ame
+)stem.out.print&2nter <irst (ame" 2'3
,rst(ame ; scnr.ne!t&'3
00 (ow 7etting 9ata for last(ame
+)stem.out.print&2nter >ast (ame" 2'3
last(ame ; scnr.ne!t&'3
00(ow 7etting age
+)stem.out.print&2nter Age2'3
age ; scnr.ne!t9ouble&'3
00(ow Printing all together in one line with space
+)stem.out.print&,rst(ame'3
+)stem.out.print&2 2'3
+)stem.out.print&last(ame'3
+)stem.out.print&2 2'3
+)stem.out.println&age'3
00 1his also can be coded
+)stem.out.println&,rst(ame L 2 2L last(ame L 2 2Lage '3
4
4
9eclaring C +trings and One (umber 5ariables with +ome =deas??
Result:
<irstname lastname age
#) using this command" +)stem.out.println&,rst(ame L 2 2L last(ame L 2 2Lage '3
this also gives same result" ,rst(ame last(ame age
Writing and 7etting 9ata for +ome 9ata 1)pes together in One Program???
import %ava.util.+canner3
public class hello -
public static void main&+tring./ args' -
00declaring scnr as a input variable
+canner scnr ; new +canner&+)stem.in'3
009eclaring C +trings 1ogether
+tring ,rst(ame,last(ame3
00 9eclaring (umber 9ata t)pe as #)te
#)te age3
009eclaring C integars one will contain A and one will L values
int minuss, pluss3
009eclaring +hort =ntegar that contain values onl) between AFCDG@ and FCDGD
+hort salar)3
007etting 9ata for All 9ata 1)pes one b) one
+)stem.out.print&2nter <irst (ame" 2'3
,rst(ame ; scnr.ne!t&'3
+)stem.out.print&2nter >ast (ame" 2'3
last(ame ; scnr.ne!t&'3
+)stem.out.print&2nter Age2'3
age ; scnr.ne!t#)te&'3
+)stem.out.print&2nter (egative 5alue2'3
minuss ; scnr.ne!t=nt&'3
+)stem.out.print&2nter Posetive 5alue2'3
pluss ; scnr.ne!t=nt&'3
+)stem.out.print&2nter +alar) between AFCDG@ and FCDGD2'3
salar) ; scnr.ne!t+hort&'3
00 1his also can be coded
+)stem.out.println&,rst(ame L 2 2L last(ame L 2 *is age is 2LageL 2 )ears
old2 '3
4
4
8esult"
sa%id hussain *is age is CM )ears old
:sing All Algebric Operators in one +imple Program???
import %ava.util.+canner3
public class Operators -
public static void main &+tring args ./' -
+canner user; new +canner&+)stem.in'3
int onevalue, twovalue, answerplus,
answerminus,answermultiplication,answerdevide3
+)stem.out.print&2nter 5alue one" 2'3
onevalue; user.ne!t=nt&'3
+)stem.out.print&2nter 5alue two" 2'3
twovalue;user.ne!t=nt&'3
00 :sing Operators
answerplus ; onevalue L twovalue3
answerminus ; onevalue A twovalue3
answerdevide; onevalue 0 twovalue3
answermultiplication; onevalue N twovalue3
+)stem.out.println&2Answer Plus is " 2L answerplus'3
+)stem.out.println&2Answer Kinus is " 2L answerminus'3
+)stem.out.println&2Answer 9evide is " 2L answerdevide'3
+)stem.out.println&2Answer Kultiplication is " 2L
answermultiplication'3
4
=ncrement and 9ecrement All together???
public class incrementdecrement -
public static void main &+tring args./'-
int valueone ; FM, valuetwo ; CM3
+)stem.out.println&LLvalueone'3
+)stem.out.println&AAvaluetwo'3
+)stem.out.println&LLvalueone'3
+)stem.out.println&AAvaluetwo'3
+)stem.out.println&LLvalueone'3
+)stem.out.println&AAvaluetwo'3
+)stem.out.println&LLvalueone'3
4
4
8esult"
FB
BO
FC
B@
FF
BD
FE
Working #etween in two options like this or not this in programming language if and
else???
public class ifandelse -
public static void main&+tring args ./'-
int one ,two, three3
one; BM3
two ; CM3
three ; FM3
00 if its Hueal to and its s)mboll ;;
if &one ;; O'-
+)stem.out.println&2)es 2'3
00if its not eHual
4else -
+)stem.out.println&2no 2'3
4
if &twoP; O'-
+)stem.out.println&2)es2'3
4else -
+)stem.out.println&2no 2'3
4if &three Q; O'-
+)stem.out.println&2)es 2'3
4else -
+)stem.out.println&2no2'3
4
4
4
8esult"
(o
(o
$es