Scope Of Public Variable And Distributed Application

Jun 2, 2014

A distributed application consists of modules which run on different machines. How is this possible? Does it have any link with the public modifier?

View Replies


ADVERTISEMENT

JSF :: View Scope Versus Application Scope For Beans

Sep 11, 2014

Viewing this example of pagination [URL] and other similar beans for pagination, why do they do these beans view scoped? These beans dont contain any properties for a form so they could be application scoped, right?

View Replies View Related

Variable In Interface Cannot Be Instance Scope?

May 5, 2014

I'm just wondering why variables in interface can't be instance scope?

interface Test{
int a;
}

And then

Test test = new TestImpl();
test.a=13;

Yes, it violates OO, but I don't see why this is not possible? Since interface is not an implementation, therefore it can;t have any instance scope variable. I can't find the correlation of interface being abstract and being able to hold instance scope variable. There's gotta be another reason. I'm just curious about any programmatic limitation, not deliberate design constraint. the example of programmatic limitation is like when Java forbids multiple inheritance since when different parents have the exact same method, then the child will have trouble determining which method to run at runtime.

View Replies View Related

EJB / EE :: Distributed Transactions On MDB

Jan 12, 2015

I have a scenario :

A ) If there is a message driven bean with CMT and transaction attribute required

-begin MDB
-Write to DB
-Send message to queue
-Null pointer exception.

I know this is a system exception , the transaction will be rolled back , which mean all my changes to DB will be rolled back.

But what will happen to the message sent to JMS queue ? It will be removed also ?

B) what will happen if the same above sequence appear with BMT

-Start transaction
-Write to DB
-Send message to queue
-Null pointer exception.

What about my changes at DB and my message at queue ?

View Replies View Related

JSF :: Scope Of Bean Associated With Form?

Aug 8, 2014

I have a managed bean for a form. I map the fields filled in the form with managed bean properties. when I submit the form and click new form , values from the previous form submitted gets displayed in the input fields. I used the scope of the from bean to session. what should be its scope so that values should be destroyed after I submit the form .For every new form ,new bean has to be initialized. On submit I navigate to another bean with session scope.

View Replies View Related

Servlets :: Initialization With Different Scope / Context

Jan 13, 2015

I want to initialize my servlet based on the scope of my application.

For example, I have multiple admins with their respective email address.

I want to perform action within my servlet based on the given environment.

Would this be the right approach, if I set the admin email addresses in my web.xml as init-param:

<servlet>
<servlet-name>ServletName</servlet-name>
<servlet-class>com.mkyong.ServletDemo</servlet-class>
<init-param>
<param-name>admin1</param-name>

[Code] .....

Now if I am in the admin 1 environment, I would initialize my servlet with request parameter admin=1 and the servlet should load email address of admin 1 and similarly when in the environment 2, should load the servlet with admin 2.

call environment 1:
/servlet/Demo?admin=1
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException{

[Code] .....

I could do the same by putting the email address of the respective admin as request param value, but i don't want to the email address to appear in the url.

View Replies View Related

JSF :: How To Access A Method With Session Scope Via Hyperlink

Jun 3, 2014

I have a hyperlink say,

[URL]

now, i want to access a managed bean's method to execute a service call related to the code embedded in the hyperlink.

My Managed bean

@ManagedBean(name="details")
@SessionScoped
public class XXXX extends Bean implements Serializable{
public XXXX(){...... }
public myMethod(..){
service.getDataRelatedToHyperlinkCode(....passing code here to fetch details from DB)
}
}

if i use postConstruct annotation it is getting executed only once since it is a session scope. and point to be noted is i cannot use viewscope and requestscope.

View Replies View Related

JSP :: Variables / Attributes Scope Inside Tag File

Jul 3, 2014

I have an issue with variables/attributes scope inside a jsp tag file.

In short, I have a tag with an attribute named "id". If the page using my tag has a variable called "id" (maybe coming from the spring model) and I call my tag WITHOUT specifying the id attribute, inside my tag I still can acces to the "id" attribute that was defined in the page but I don't want this behavior; if the tag is called without the "id" attribute then it should defaults to empty/null.

Example:

print.tag
<%@ attribute name="id" required="false" type="java.lang.String" %>
id=${id}
site.jsp

(...)
The id is: ${id} // <- Prints 'X'
<my:print /> <- Prints 'X' ! I want it to not print anything in that case
<my:print id="Y"/> <- Prints 'Y'
(...)

What I want is to have the tag attributes live only in the tag, without having any knowledge of any variable outside of the tag itself. Is it possible?

My current workaround is to remove the "id" attribute, enable dynamic attributes and with a scriptlet search in the dynamic attributes map for the "id" and save it in a variable with a different name (e.g. "__id").

View Replies View Related

JSF :: Count Number Of Views Created In A Session While Using Managed Bean With View Scope

Jan 30, 2014

I am trying to restrict the number of views in JSF 2.0.2 using

<context-param>
<param-name>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</param-name>
<param-value>5</param-value>
</context-param>

In my case my managed bean is View Scoped and it supports a UI page which has multiple forms and each form is submitted as AJAX POST request.

As per the statndard, setting restriction to 5 should create 5 views and after that based on LRU algorithm the oldest views should get deleted if 6th views is created.

Therefore any action on the oldest view will throw the ViewExpiredException and i simply redirect the user to view expired page.

1) When i set the restriction to 5 views, i open 4 tabs with 3 forms each.
2) I submit the 3 forms on first tab everything works fine.
3) As soon as I go to 2nd tab and submit the first form thr, i get view expired exception
4) It seems I am exceeding the number of views I mentioned in web.xml

I want to know :

1) Does every AJAX POST submit itself creates a view ?
2) How I can count the number of views created in a session ?
3)Can i force expiry of a view in JSF 2.0.2 while the session is still alive ?
4) Normally JSF 2.0.2 session cachces the views. Lets assume session is alive the entire day but a view was created in morning at 9:00 AM and is not used again the entire day. Assuming that session doesn't reaches the max number of views it can save in entire day, will the view created in morning expire on its own after certain interval of time ? If not , can we still force its expiry while keeping the session alive ?

View Replies View Related

One Public Class Per File

Feb 8, 2014

The compiler won't let me declare more than one class as "public". Am i correct in understanding that this is a java restriction ? This means i need to create a new file, for each public class that i want in a package ? The rest of the classes without access modifier will all be package-private. (Q has been asked before probably, but my search could not be narrowed).

View Replies View Related

How To Use Public Double GetXCoordinate

Dec 9, 2014

I am trying to understand a question:

R2 (x,y) -- Make the Point class code that implements a corresponding abstraction to a given point in R2. You should explicitly provide the manufacturer's code P (double x, double y) for the Point class. And code for the methods, whose definitions are:

- public double getXCoordinate ();
- public double getYCoordinate ();
- public setXYCoordinates (double x, double y);
- public moveTo (double x, double y);
- public printAtts ();

View Replies View Related

How To Compare Public String Value

Sep 7, 2014

I want to make a program in which i write the Months Strings via while into the checkbox.

I already did that but i have also to add an day if February is a loop day.

So my question is how to say java that if Months is equal to February & year is a leap year, add 1. (i didn't wrote the year code because it's not relevant for my problem.)

Java Code:

public String[] Months ={"January","February","March","April","May", "June", "July", "August", "September", "Oktober", "November", "December"};
public Asg1KeapYear() {
initComponents();
int MonthNo = 0;

[Code] ....

Netbeans shows me .equals() on incompatible types on Months.equals, do i have to declare it somehow?

View Replies View Related

Calling Public Function In JInternalFrame

Aug 31, 2014

Is it possible to create a JInternalFrame class with additional public functions that can be called from the desktop? Here is some snippets of the code. This is the Internal Frame with the public functions added after the constructor.

public class Search_Ifr extends javax.swing.JInternalFrame {
/**
* Creates new form Search_Ifr
*/
public Search_Ifr() {
initComponents();
 
[code].....

The line " ifrSearch.setTabPaneIndex("tabCust");" is throwing a compile error that the method is not found.

View Replies View Related

Public Type (name) Must Be Defined In Its Own File

Apr 1, 2014

I have a small issue understanding the following error message that Eclipse returns when i try to run the following code:

class Film {
String tytul;
String rodzaj;
int ocena;
void odtworz() {
System.out.println("Odtwarzamy film.");

[Code] .....

The message itself reads: "Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at FilmTester.main(Film.java:13)"

and the following on the line where the problem arises:

What gives? I'm positive i'm missing something obvious but i can figure it out why

View Replies View Related

Why Cannot Access A Public Method From Another Class

Feb 12, 2015

Why can't I access a method from another class? For example, I want to get the value of get method from another class. It's giving me an error on if(getExamType() == 'M') That's what I've done, for example:

Java Code:

public static Exam[] collateExams(Exam[] exams){
Exam [] r = new Exam[50];
r = exams;
Exam [] finalExam = new Exam[50];
for(int i = 0; i < r.length; i++) {
if(getExamType() == 'M') {
}
}
return r; mh_sh_highlight_all('java');

View Replies View Related

Unable To Access A Method Which Is Public From Servlet

May 13, 2014

I am trying to assess a method which is public from servlet. but it gives weird error. image has been attached .....

View Replies View Related

Make Http Server Creation Public

Mar 3, 2015

Now, I would like to properly stop the server. For that, I can do server.stop(); . However, this does not work since the object server is not public, it is contained within the public pc_proxy class.How do I do that?

Java Code: import java.net.*;
import java.io.*;
import com.sun.net.httpserver.*;
import java.util.concurrent.Executors;
import java.lang.reflect.Array;

[code]....

View Replies View Related

Java Eclipse - Public Static Int Error

Oct 28, 2014

I've got a problem in Eclipse. The below code is a part of my program, used for (re)starting a new game. The 'public static int' statement gives the error 'This method must return a result of type int'..

public static int playAgain(){
boolean validInput = false;
do {
System.out.println("Would you like to play a game? Please answer 'yes' or 'no'.");
String playAgain = input.next();

[Code] ....

View Replies View Related

Overriding - Use Public Access Modifiers With String

Apr 2, 2015

Why do we use public access modifiers with String toString() method in java while overriding???

View Replies View Related

Error / The Public Type Welcomer Must Be Defined In Its Own File

Mar 30, 2014

Why I cannot use 2 public classes like below?

public class Hello {
public static void main(String[] args){
Welcomer welcomer=new Welcomer();
welcomer.sayHello();

[Code] ....

Exception in thread "main" java.lang.Error: Unresolved compilation problem:

The public type Welcomer must be defined in its own file

at Welcomer.<init>(Hello.java:9)
at Hello.main(Hello.java:5)

View Replies View Related

Private Var Won't Save Value Of Public Getter Function From Base C

Sep 15, 2014

I'm working on this program for a class to create objects of a commissioned employee and union employee. Everything seems to work ok, but when I run my final pay calculation, one of my getter functions will not pass the variable for the pay into a class specific variable called check. here is the code in this function.

public void finalPayCal_U() {
setweekPay();//calculates weeks pay under 40 hours, stored in getweekpay
check = getweekPay();
if(getHours() > 40){
check = check + (1.5 * (getHours() - 40) * getRateOfPay());
}
check =- Dues;
}
}

The issue lies in check = getweekPay();

I thought this was a legal move, but I can't get it to work. It doesn't come back with anything more than 0 any time I run it.

All of these functions are out of the base class, employee (this function itself lives in the derived union class)

public void setweekPay() {
if (hours <= 40) {
weekPay = hours * rateOfPay;
} else {
weekPay = 40 * rateOfPay;
}
}

When I run, this function works as it returns the value when i print it to test.

however, when I do the part that says check = getWeekPay() above, it doesn't change the check variable. The only thing I have on the check variable is the dues taken out of it at the end, so it ends up being a negative number.

I have a similar problem with the other derived class's check variable. Both classes have the same variable as private but one is check the other checkC.

View Replies View Related

Non-Public Class In A Source File Doesn't Matching Its Name

Oct 20, 2014

I have a question about the following snippet concerning the steps the javac compiler follows to compile a program:

[...]at first, searching a class within a package is discussed if the latter doesn't contain a full package name[...]

It is a compile-time error if more than one class is found. (Classes must be unique, so the order of the import statements doesn't matter.)

The compiler goes one step further. It looks at the source files to see if the source is newer than the class file. If so, the source file is recompiled automatically. Recall that you can import only public classes from other packages. A source file can only contain one public class, and the names of the file and the public class must match. Therefore, the compiler can easily locate source files for public classes.

However, you can import nonpublic classes from the current package. These classes may be defined in source files with different names. If you import a class from the current package, the compiler searches all source files of the current package to see which one defines the class. I don't quite understand the red fragment. I wondered if the word "import" nonpublic classes from the current package weren't a synonym for the word "use", since why would we want to import a class from the same package when compiler searches the current package automatically anyway?

However I wanted to test nonpublic classes that are contained in source file which name doesn't match the class name:

NonpublicClass.java:

Java Code:

package com.work.company;
class NonpublicClass
{
public void description() {
System.out.println("Working!");
}
} mh_sh_highlight_all('java');

[Code] ....

Everything's fine when the source file names are the same as above. However, when I change NonpublicClass.java to a different name, there's an error "cannot find symbol" in:

Java Code: NonpublicClass v = new NonpublicClass(); mh_sh_highlight_all('java');

I noticed that the class file for NonpublicClass isn't even generated so that's probably the cause. If I change to the directory of the package the NonpublicClass is contained in and compile it directly, i.e. issue for example:

Java Code: javac NonpublicClass_different_name.java mh_sh_highlight_all('java');

Then a proper class file is generated with the class name, that is NonpublicClass.class, and afterwards I can compile the main program in Start.java.

So the question is what am I missing regarding the cited quote that reads:

If you import a class from the current package, the compiler searches all source files of the current package to see which one defines the class.

? Because adding such an import to CompanyClass.java:

import com.work.company.NonpublicClass;

didn't work either...

View Replies View Related

Singleton Pattern - Static Field And Public Constructor

Apr 4, 2014

In singleton pattern just having a static field is not enough? Do we really need to have a private constructor?

I can have a static field and have a public constructor and still say it is singleton.

View Replies View Related

Java IP Address Program - Check If It Is Public Or Private

Feb 2, 2015

I am doing an assignment for a college class. We are asked to get user input and decide if it is a valid IP address and then check what class the address is and if it is a public or private address.

So far, I can get the input, and check to see if the numbers are in a valid range. I can also display the IP address to the user. I am having an issue figuring out how to get the program to check the classes and whether they are public or private.

import javax.swing.JOptionPane;
/**
This program will take user input and calculate whether it is a valid IP address and the class that it belongs to.
*/

public class shortONE_1
{
public static void main(String[] args)
{
//Variables
final int MIN_OC = 1; //Minimum number accepted
final int MAX_OC = 255; //Maximum number accepted
final int MIN_A = 1; //Min number for class A
final int MAX_A = 127; //Max number for class A

[Code] ....

View Replies View Related

Difference In Variable Assignment Between Constructor And Variable Section

May 21, 2014

Given the case I have an object which is assigned only once. What is the difference in doing:

public class MyClass {
private MyObj obj = new MyObj("Hello world");

private MyClass(){}
//...
}

and

public class MyClass {
private MyObj obj;
private MyClass(){
obj = new MyObj("Hello world");
}
//...
}

Is there a difference in performance or usability? (Given also the case there are no static calls expected) ....

View Replies View Related

Are Terms Local Variable And Member Variable Comparable

Oct 27, 2014

The term "Local variable" is related to scope. That is a local variable is one which is defined in a certain block of code, and its scope is confined inside that block of code.And a "Member variable" is simple an instance variable.

I read in a discussion forum that when local variables are declared (example code below), their name reservation takes place in memory but they are not automatically initialized to anything. On the other hand, when member variables are declared, they are automatically initialized to null by default.

Java Code: public void myFunction () {
int [] myInt; // A local, member variable (because "static" keyword is not there) declared
} mh_sh_highlight_all('java');

So it seems that they are comparing local variables and member variables. While I think a member variable can also be be local in a block of code, isn't it?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved