Method: Public Class Public Static Void

You might also like

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 12

Java Programming

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???
1he vairable also called identi,er. 1he word 25araible2 means varries, means its value
can be changed. it also can be declared as constant as well.
Classi,cation of 5ariables???
5ariables classi,ed in three t)pes" 6' 7nstance 8' +tatic 9' :ocal 5ariable
6' Instance variable: use to re;ect the state of the ob%ects
8' Static Variable: these variables or common to all instance variables.
9' Local Variables: 1hese variables are declared within a method and visible
onl) in a block inwhich the) are declared.
Note:1 5ariables &7denti,eres' are case sensitive means will start with lower
case, <&With =ollor +ign', > &With underscore'. :ike
number5alue, >b)pass, <value, tech
In Programming method:
public class classi,cattionofclass -
public static void main&+tring args./'-
char number5alue, >b)pass, <value, tech3
4
4
What are the Permitive =ata 1)pes???
1here are ? primitve data t)pes.
+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. 7t is used to represent small numbers. 1o declare a
variable that would hold a natural number between @68? and 68A, )ou can use the
b)te data t)pe.
its use as ne!t#)te&'
7nt" 7n Java, an integer is variable whose values are between @8,6BA,B?9,CB? and
8,6BA,B?B,CBA.
its use as ne!t7nt&'
+hort 7ntegers " An integer is referred to as short if its value is between @98AC? and
98ACA. 1his number can ,t in 6C 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) reDuire
CB bits to be stored accuratel).
7ts use as ne!t:ong&'
=ouble" 1o declare a variable used to hold such a decimal number, )ou can use
the double ke)word
its use as ne!t=ouble&'
Eloat" 1o declare a variable that would hold decimal values with little to no
concern with precision, )ou can use the ;oat data t)pe.
its use as ne!tEloat&' Containt value and E at the end like F 9.689E3
Einal " 1o create a constant value in Java, t)pe ,nal, followed b) the t)pe of the
variable, its name, the assignment operator 2F2, and the desired value.
Char" 1he single Duote is used to include one character to initialiGe, or assign
a s)mbol to, a variable declared as char.
!ample :ike " H, A, E I
import %ava.util.+canner3
public class hello -
public static void main&+tring./ args' -
00declaring scnr as a input variable
+canner scnr F new +canner&+)stem.in'3
00=eclaring 8 +trings 1ogether
+tring ,rst(ame,last(ame3
00 =eclaring (umber =ata t)pe as =ouble
=ouble age3
00Eirst getting data for ,rst(ame
+)stem.out.print&2nter Eirst (ame" 2'3
,rst(ame F scnr.ne!t&'3
00 (ow Ietting =ata for last(ame
+)stem.out.print&2nter :ast (ame" 2'3
last(ame F scnr.ne!t&'3
00(ow Ietting age
+)stem.out.print&2nter Age2'3
age F scnr.ne!t=ouble&'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 J 2 2J last(ame J 2 2Jage '3
4
4
=eclaring 8 +trings and One (umber 5ariables with +ome 7deas??
Result:
Eirstname lastname age
#) using this command" +)stem.out.println&,rst(ame J 2 2J last(ame J 2 2Jage '3
this also gives same result" ,rst(ame last(ame age
Writing and Ietting =ata for +ome =ata 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 F new +canner&+)stem.in'3
00=eclaring 8 +trings 1ogether
+tring ,rst(ame,last(ame3
00 =eclaring (umber =ata t)pe as #)te
#)te age3
00=eclaring 8 integars one will contain @ and one will J values
int minuss, pluss3
00=eclaring +hort 7ntegar that contain values onl) between @98AC? and 98ACA

+hort salar)3

00Ietting =ata for All =ata 1)pes one b) one
+)stem.out.print&2nter Eirst (ame" 2'3
,rst(ame F scnr.ne!t&'3
+)stem.out.print&2nter :ast (ame" 2'3
last(ame F scnr.ne!t&'3
+)stem.out.print&2nter Age2'3
age F scnr.ne!t#)te&'3
+)stem.out.print&2nter (egative 5alue2'3
minuss F scnr.ne!t7nt&'3
+)stem.out.print&2nter Posetive 5alue2'3
pluss F scnr.ne!t7nt&'3
+)stem.out.print&2nter +alar) between @98AC? and 98ACA2'3
salar) F scnr.ne!t+hort&'3

00 1his also can be coded
+)stem.out.println&,rst(ame J 2 2J last(ame J 2 *is age is 2JageJ 2 )ears
old2 '3
4
4
Kesult"
sa%id hussain *is age is 8L )ears old
*ow to Iet Kesult of something in Java Programming???
for Print or Kesult 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 =ata input from Mser???
1o get =ata 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 F new +canner&+)stem.in'3
+tring ,rst(ame3
*ere scnr is a variable and scanner used to get data from user and systemin
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 F new +canner&+)stem.in'3
+tring ,rst(ame3
00 +tring onl) contain 1e!ts
+)stem.out.print&2nter the Eirst (ame" 2'3
00 Eirst print above line to get data
,rst(ame F scnr.ne!t&'3
00 After getting data now print below line
+)stem.out.print&2Eirst (ame" 2'3
00 it will Write as Eirst (ame" then user data
+)stem.out.print&,rst(ame'3
4
4
Kesult" Eirst (ame " nter Eirst (ame
Eirst (ame " as )ou write in nter Eirst (ame
7f 7 miss this line & +)stem.out.print&2Eirst (ame" 2'3 ' from above method its
shows result like below"
Kesult" Whatever )ou written in nter Eirst (ame or :ike Ali
7n above program user inputiing onl) one data in te!t now lets do it with diNerent
data t)pe. +tring is a te!t data t)pe.
Msing All Algebric Operators in one +imple Program???
import %ava.util.+canner3
public class Operators -
public static void main &+tring args ./' -
+canner userF new +canner&+)stem.in'3
int onevalue, twovalue, answerplus,
answerminus,answermultiplication,answerdevide3
+)stem.out.print&2nter 5alue one" 2'3
onevalueF user.ne!t7nt&'3
+)stem.out.print&2nter 5alue two" 2'3
twovalueFuser.ne!t7nt&'3
00 Msing Operators
answerplus F onevalue J twovalue3
answerminus F onevalue @ twovalue3
answerdevideF onevalue 0 twovalue3
answermultiplicationF onevalue O twovalue3
+)stem.out.println&2Answer Plus is " 2J answerplus'3
+)stem.out.println&2Answer Hinus is " 2J answerminus'3
+)stem.out.println&2Answer =evide is " 2J answerdevide'3
+)stem.out.println&2Answer Hultiplication is " 2J
answermultiplication'3
4
7ncrement and =ecrement All together???
public class incrementdecrement -
public static void main &+tring args./'-
int valueone F 9L, valuetwo F 8L3
+)stem.out.println&JJvalueone'3
+)stem.out.println&@@valuetwo'3
+)stem.out.println&JJvalueone'3
+)stem.out.println&@@valuetwo'3
+)stem.out.println&JJvalueone'3
+)stem.out.println&@@valuetwo'3
+)stem.out.println&JJvalueone'3
4
4
Kesult"
96
6P
98
6?
99
6A
9B
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
oneF 6L3
two F 8L3
three F 9L3
00 if its Dueal to and its s)mboll FF
i! &one FF P'-
+)stem.out.println&2)es 2'3
00if its not eDual
4else -
+)stem.out.println&2no 2'3
4
i! &twoQF P'-
+)stem.out.println&2)es2'3
4else -
+)stem.out.println&2no 2'3
4i! &three RF P'-
+)stem.out.println&2)es 2'3
4else -
+)stem.out.println&2no2'3
4
4
4
Kesult"
(o
(o
$es
Msing two conditions in one if and else logical operators program???
public class twoconditions -
public static void main &+tring args./'-
int apple, price3
00 =eclaring no. of apples and prices
apple F C3
price F 83
00 if no. of apples more than C price reduced and show ,ne
i! &apple Q? SS price R6'-
00 in this above condition both conditions should be true not one onl) and both
depend on each other
+)stem.out.println&21his price is ,ne2'3
00 if no. of apple more than C and price is same or more than 8 show huge
4else -
+)stem.out.println&21his price is huge2'3
4
4
4

You might also like