0% found this document useful (0 votes)
3 views

Class 12 Finesh Java Practical File

The document provides examples of basic Java programming concepts, including the 'Hello, World!' program, arithmetic operators, if...else statements, and various control structures like loops and exception handling. Each example includes a code snippet and expected output. It serves as a beginner's guide to understanding fundamental Java syntax and operations.

Uploaded by

nitikabimrah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Class 12 Finesh Java Practical File

The document provides examples of basic Java programming concepts, including the 'Hello, World!' program, arithmetic operators, if...else statements, and various control structures like loops and exception handling. Each example includes a code snippet and expected output. It serves as a beginner's guide to understanding fundamental Java syntax and operations.

Uploaded by

nitikabimrah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Java "Hello, World!

" Program

II Your First Pr ogram

I ! ,_. I l 1 11•,' r ~ ,1 1
(String[] args) {
,·:,y·-, t ,__'Ill. uui . pr ir1t In( ,·,,:1r 1
• l·j ' ,, ) ,'

Output

He ll o, world'
Example 3: Java if...else Statement

',.' 1 l I

f]IJIT'-h•''

I I rhPcl-..•; if !HJl'lhPI I c, .('.rP,1tf>r t hari 0

' !ilJllf1••' '


'
' , •~ ·, 1 •·•1T
'" I'' ; 11 I , I
'

II "x,_•1u1•• th1<, hlocl-..


11 1f rni1•1h+_:f 1•, 1101 grt•<1ter thJri O

Run Code »

Output

T hi:- r1u11tJ...-r 1::. lJuSLt:..':'.


State~ent J~ts1d~ 1f ... ~ls':' r::~~
Example 1: Arithmetic Operators

Rur, Code ,>

Output
Example 2: Assignment Operators

Run CodE' >>

Output
Example 3: Relational Operators
Example 5: Increment and Decrement Operators

R1Jn Code, •;,

Output
Example 1: Java break statement

II for looi..,

II 1f the~ ~alue of 1 1s 5 rne loop :err1nares

Run Code »

Output:
Example: Access Array Elements

Output
Example: Java Constructor

I ,l'II•"

! ' ,,_ '. _I I

Ru n Corje ) >

Output:
Example 1: Java Inheritance

Output

?,' , I •II •· , • I

: • - j.
Example: Java Polymorphism

',_•_1\,_• JI I ~-l •·

Run Coru:; ,.,

Output
Example: Exception handling using try...catch

R,.m Codt.> ,)

Output
Example 1: Java Encapsulation

Run Cod-e >>

Output
Example 1: Java Nested for Loop

Run Cod,e »

Output
Example: Create objects inside the same class

/; stores the ~alue for _:i~:


/ / true If light 1s 0n
II false If ltght 1s 0~~

// nethad to :urn on t~~ ::~~:

Run Code >>

Output

L_;: · t r - - 'J ~
1. Get the Length of a String
To find the length of o string, we use the Iengch() method. For
example,

I•• ti•• r' l

Run Code, ,)

Output

-r 1 :. ...,,... • _ 1. • •
L,...r:_ ..1 ' _

You might also like