0% found this document useful (0 votes)
62 views4 pages

A. System Is A Class in The Java - Lang Package. B. Out Is A Static Member of The System Class, and Is An Instance of Java - Io.Printstream

Java was designed by James Gosling at Sun Microsystems. It uses a Java Virtual Machine (JVM) to interpret Java code into machine language. Java can be used to create applications and applets, as well as servlets which extend the functionality of web servers. Features of Java include being simple, secure, portable, object-oriented, robust, architecture-neutral, multithreaded, distributed and dynamic. There are 8 primitive data types in Java. The Scanner class is used to take user input in programs. Enums were introduced in Java 5.0 to restrict variables to a set of predefined values.

Uploaded by

Mannveen Bhullar
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)
62 views4 pages

A. System Is A Class in The Java - Lang Package. B. Out Is A Static Member of The System Class, and Is An Instance of Java - Io.Printstream

Java was designed by James Gosling at Sun Microsystems. It uses a Java Virtual Machine (JVM) to interpret Java code into machine language. Java can be used to create applications and applets, as well as servlets which extend the functionality of web servers. Features of Java include being simple, secure, portable, object-oriented, robust, architecture-neutral, multithreaded, distributed and dynamic. There are 8 primitive data types in Java. The Scanner class is used to take user input in programs. Enums were introduced in Java 5.0 to restrict variables to a set of predefined values.

Uploaded by

Mannveen Bhullar
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/ 4

1. Java is designed by James Gosling.

At Sun Microsystems(now acquired by oracle


corporation).
2. The two main components of the Java platform are the Java Application Programming
Interface (API), which is a library of Java command lines and the Java Virtual Machine
(JVM) that interprets Java code into machine language.
3. Java can be used to create two types of programs: Applications and Applets.
4. A servlet is a small program that executes on the server. Just as applets dynamically extend
the functionality of a web browser, servlets dynamically extend the functionality of a web
server.
5. Like all java codes servlets are compiled into byte code and executed by JVM. They are
portable. Thus, the same servlet can be used in a variety of different server environments.
The only requirements are that the server supports the JVM and a servlet container.
6. Features of java:
a.
b.
c.
d.

SIMPLE
SECURE
PORTABILITY
OBJECT-ORIENTED: Object-oriented programming organizes a program around its
data (that is, objects) and a set of well-defined interfaces to that data. An object-

e.
f.
g.
h.
i.

oriented program can be characterized as data controlling access to code.


ROBUST
ARCHITECTURE-NEUTRAL
MULTITHREADED
DISTRIBUTED
DYNAMIC

7. There are eight primitive data types in java:


TYPE:

boolean char byte short int long float double

BIT DEPTH:

JVM spec 16

VALUE RANGE: T or F

8. Meaning

of

16

32

64

32

64

0 to 65535 -128to-127

--

System.out.println("Hello

a. System is a class in the java.lang package.


b. out is a static member of the System
of java.io.PrintStream.

class,

and

World!");

is

an

instance

c. println is a method of java.io.PrintStream .This method is overloaded to


print message to output destination, which is typically a console or file.
9. Meaning of -- public static void main(String[] args)

a. public is the visibility. This can be public, private, protected or (if you omit a value)
default.
b. static is a special [optional] keyword that indicates that this method can be called
without creating an instance of this class. Without it, you have to instantiate this class and
call this method from the resulting object./ When the JVM makes call to the main method
there is not object existing for the class being called therefore it has to have static method to
allow invocation from class.
c. void is the return type of this method, indicating that this method doesn't return
anything. Methods must have a return type.
d. main( ... ) is the name of this method. Methods have to be named. The parentheses
indicate that this is a method.
e. String[] args is a single parameter for the method. String[] is the type of the parameter,
indicating an array of Strings. args is the name of the parameter. Parameters must be
named. args can be any name.
10. Use of Scanner: It is used to take input from keyboard in output screen.
Example for string:

import java.util.Scanner;
public class Input {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Hey, Whats your name?");
String name = input.next();
System.out.println("Hello " +name);
}//main
}//class
Example for number:

import java.util.Scanner;
public class InputInt {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("What is your favorite number?");
int number = input.nextInt();
System.out.println("You entered: " + number);
}
}
11. Program to add two numbers:
import java.util.Scanner;
public class HelloWorld {
public static void main(String[]args)
{
//int a;
int b;
double sum;
Scanner input= new Scanner(System.in);
System.out.println("enter the value of a");
int a = input.nextInt(); // here variable a is not declared
therefore declaring with int a.
System.out.println("enter the value of b");
b = input.nextInt();
sum= a+b;
System.out.println("sum of numbers is: " + sum);
input.close();
}
}
12. Java Enums:
Enums were introduced in java 5.0. Enums restrict a variable to have one of only a few
predefined values. The values in this enumerated list are called enums.
With the use of enums it is possible to reduce the number of bugs in your code.

For example, if we consider an application for a fresh juice shop, it would be possible to
restrict the glass size to small, medium and large. This would make sure that it would not
allow anyone to order any size other than the small, medium or large.
Example:
class FreshJuice {
enum FreshJuiceSize{ SMALL, MEDIUM, LARGE }
FreshJuiceSize size;
}
public class FreshJuiceTest {
public static void main(String args[]){
FreshJuice juice = new FreshJuice();
juice.size = FreshJuice.FreshJuiceSize.MEDIUM ;
System.out.println("Size: " + juice.size);
}
}
Above example will produce the following result:
Size: MEDIUM
Note: enums can be declared as their own or inside a class. Methods, variables, constructors
can be defined inside enums as well.

You might also like