0% found this document useful (0 votes)
8 views12 pages

Java Basics

The document provides an overview of the Java programming language. It discusses that Java is an object-oriented, class-based language developed by James Gosling at Sun Microsystems in 1995. It notes some key features of Java including that it is statically typed, supports developing various types of applications, and uses the .java file extension. It also discusses Java packages, classes, and how to write a basic Java program.

Uploaded by

Jordi el Pablo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
8 views12 pages

Java Basics

The document provides an overview of the Java programming language. It discusses that Java is an object-oriented, class-based language developed by James Gosling at Sun Microsystems in 1995. It notes some key features of Java including that it is statically typed, supports developing various types of applications, and uses the .java file extension. It also discusses Java packages, classes, and how to write a basic Java program.

Uploaded by

Jordi el Pablo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 12

Welcome to BTPS

Session 2

Java

............

1-jAVA IS programming Language.

2-IT is advance version of c++.

3-Java is developed By "James Gosling" in 1995 at sunmicro System.

4- JAVA'S Old name was OAK.

5-NoW JAVA is take over by oracle.

6-JAVA is High LeveL PL.

7-Java is statically typed PL becoz we have to declare datatype at the

time program creation like c and c++.

8-Python is Dynamically typed PL.

9-JAVA IS Object oriented PL not Procedural Oriented PL.

10-USING Java we can develop any kind of Application such as

software(desktop ApplicationS),

web Application,Mobile Application,Embedded Based Application and many More.

11-Java is case sensitive PL like c and c++.

12-the extention of java programe is .java.

13-Every Programming Language have its own Compiler.

14-the name of java compiler is javac.

15-Java is compilative and Interpreative PL Where as Python is only Interpreative PL.


Sun microsystem divided the java in three Module

1-J2SE(JSE) [JAVA STANDARD Edition]

2-J2EE(JEE) [JAVA Enterprise Edition]

3-J2ME (JME) [JAVA Micro Edtion]

Programming Stucture of Java Program

......................................

packages

class

blocks

statements

Java first Programe IN Notepad

.................................

import java.lang.*;

class Test

{
public static void main(String[] args)

System.out.println("btps");

Note:-

1-className:-1st letter should be capital letter.

2-Method Name or Function Name:--1st letter should be small letter.

ex:-print(),btps(),....

but if a method name contain two words combination,then 2nd word, 1st letter should be

capital letter.

this naming convention is called as camel case.

ex:-btpsKanpur(),nextInt(),nextDouble(),.....

3-package Name:-1st letter shoule be small.

4-All keywords:-should be small letter.

..................................................................................................

Differnce Between Function and method

.........................................

if a function is defined with in a class then it becomes as method.


and without class it is called as function.

what is the basic Need to Run Java Prog- in our System

.........................................................

Jdk(java Development Kit)

...........................

jdk is the combination of java compiler(javac.exe),JRE(java--->JVM,Lib.).

1-download the jdk from Oracle web site.

2-install the jdk.

3-How we can check jdk is installed?

---go to C:\Program Files\Java\jdk1.8.0_241\bin [javac.exe file should be present]

javac

.........

this is java compiler and responsible to compile java prog..

java

......

this file is responsible to run java Prog becoz it internally calls the jvm.
First Way of Writing First Java Program

...........................................

1-Open your Notepad run as Administrator [RC On Notepad]

2-Write Java Program in Notepad.

import java.lang.*;

class Test

public static void main(String[] args)

System.out.println("welcome to BTPS");

if you want to keep your java prog- any where in your System then you have to register the java

compiler path to the Operating System . [Set the Enviorment]

3-How to set the Enviornment

..............................

a-copy the path where java compiler is present.

" C:\Program Files\Java\jdk1.8.0_241\bin"


b-go to my computer->RC->Properties->Advance System Settings->Enviorment Variable->NEW-

give the variable name=path

give the variable value=C:\Program Files\Java\jdk1.8.0_241\bin

4-Make A folder in YOUR System any where name as My All java Prog.

5-Open notepad normally.

6-write the java Prog..

7-save the java prog where your folder is persent by using .java extention

Note- fileName same as class Name [Recommonded]

open the cmd or Console window where your all prog is present.

8-now compile prog.

c.....>javac filename......enter..

ex.

c......>javac Test.java

9-now Run prog..

c....>java ClassName.....enter

ex.

c....>java Test .....enter


why we use packages?

......................

when we want to use any predefined class in our prog- then

we have to import appropriate package in our prog-

what is Header Files in c/C++

....................................

>Collections of predefined Functions and global variables.

what is packages in java?

..............................

>collection of predefined classes and Interfaces.

why we use java.lang package?

..............................

-in java java.lang package is default package.

-it is very imp package amoung all other packages.

-String,System class is present inside the java.lang package..

which is the most IMP package in java?

..........................................

java.lang is most imp package in java.


without this package you can not run single java prog-.

Compilation & Excecution Structure of Java Prog.

...................................................

java Prog ==>javac ==>Byte code==>jvm ==>Machine Code.

Note:- when ever we compile our java Prog- ,java compiler

creates a new .class file with the name

of className not File Name.

In java + operator is used for Concatination purpose.

Coding Standard of java

.................................

1- Can we defined more than one classes inside a single java file?

ans:- Yes, we can define more than one classes in signle java file but after

compilation seprate .class file will be created.

2-Can we defined more than one main () method in single java file?
ans:- yes we can define more than one main() method in single java file inside seprate

classes.

3-can we defined more than one public classes in single java file?

ans:- No,we can not define more than one public classes in single java file.

we can define only one public class and file name should be same as public class Name.

Note:- whenever we run our java prog- jvm first search the main() method in that class.

4- Is it Recommondded to keep multiple classes in single java file?

..................................................................

No.. IT is not recommondded to keep more than one classes in signle java file.

please Keep single class in single java file.

and try to keep file name should be same as class name.

How to take Input from User in Java?

............................................................

we have differnt ways to take input from user in java.

There are three differnt ways to take input from user.


1-Scanner class (present in java.util package)

2-BufferedReader class (present in java.io package)

3-System.in.read()

Scanner class is easieast way to take input from user in all amoung ways.

Scanner class (present in java.util package)

....................................................

it is predefined class in java.

1-Scanner class is used to take input from keyboard,File,network.

2-Scanner class is Present in java.util package.

3-Scanner class Provides us various methods (functions) to take

differnt types of data from user.

ex. next(),nextInt(),nextFloat(),nextLine(),..........

4-Scanner class is final class means we can not create child classes from it.

5-Scanner class does not have zero parmeter contructor(default constructor).

You might also like